def generate(inputfilename, outputfilename='', dump=0, **flags): """Generate a grammar, given an input filename (X.g) and an output filename (defaulting to X.py).""" if not outputfilename: if inputfilename.endswith('.g'): outputfilename = inputfilename[:-2] + '.py' else: raise Exception( 'Must specify output filename if input filename is not *.g') DIVIDER = '\n%%\n' # This pattern separates the pre/post parsers preparser, postparser = None, None # Code before and after the parser desc # Read the entire file s = open(inputfilename, 'r').read() # See if there's a separation between the pre-parser and parser f = s.find(DIVIDER) if f >= 0: preparser, s = s[:f] + '\n\n', s[f + len(DIVIDER):] # See if there's a separation between the parser and post-parser f = s.find(DIVIDER) if f >= 0: s, postparser = s[:f], '\n\n' + s[f + len(DIVIDER):] # Create the parser and scanner and parse the text scanner = grammar.ParserDescriptionScanner(s, filename=inputfilename) if preparser: scanner.del_line += preparser.count('\n') parser = grammar.ParserDescription(scanner) t = runtime.wrap_error_reporter(parser, 'Parser') if t is None: return 1 # Failure if preparser is not None: t.preparser = preparser if postparser is not None: t.postparser = postparser # Check the options for f in t.options.keys(): for opt, _, _ in yapps_options: if f == opt: break else: print >> sys.stderr, 'Warning: unrecognized option', f # Add command line options to the set for f in flags.keys(): t.options[f] = flags[f] # Generate the output if dump: t.dump_information() else: t.output = open(outputfilename, 'w') t.generate_output() return 0
def generate(inputfile, outputfile=None, dump=0, **flags): """Generate a grammar, given an input filename (X.g) and an output filename (defaulting to X.py).""" inputfilename = inputfile if isinstance(inputfile, string_types) else inputfile.name if not outputfile: if inputfilename.endswith('.g'): outputfile = inputfilename[:-2] + '.py' else: raise Exception( 'Must specify output filename if input filename is not *.g') DIVIDER = '\n%%\n' # This pattern separates the pre/post parsers preparser, postparser = None, None # Code before and after the parser desc # Read the entire file if isinstance(inputfile, string_types): inputfile = open(inputfilename) s = inputfile.read() # See if there's a separation between the pre-parser and parser f = s.find(DIVIDER) if f >= 0: preparser, s = s[:f] + '\n\n', s[f + len(DIVIDER):] # See if there's a separation between the parser and post-parser f = s.find(DIVIDER) if f >= 0: s, postparser = s[:f], '\n\n' + s[f + len(DIVIDER):] # Create the parser and scanner and parse the text scanner = grammar.ParserDescriptionScanner(s, filename=inputfilename) if preparser: scanner.del_line += preparser.count('\n') parser = grammar.ParserDescription(scanner) t = runtime.wrap_error_reporter(parser, 'Parser') if t is None: return 1 # Failure if preparser is not None: t.preparser = preparser if postparser is not None: t.postparser = postparser # Add command line options to the set t.options.update(flags) # Generate the output if dump: t.dump_information() else: if isinstance(outputfile, string_types): outputfile = open(outputfile, 'w') t.output = outputfile t.generate_output() return 0
def generate(inputfile, outputfile=None, dump=0, **flags): """Generate a grammar, given an input filename (X.g) and an output filename (defaulting to X.py).""" inputfilename = inputfile if isinstance( inputfile, string_types ) else inputfile.name if not outputfile: if inputfilename.endswith('.g'): outputfile = inputfilename[:-2] + '.py' else: raise Exception('Must specify output filename if input filename is not *.g') DIVIDER = '\n%%\n' # This pattern separates the pre/post parsers preparser, postparser = None, None # Code before and after the parser desc # Read the entire file if isinstance(inputfile, string_types): inputfile = open(inputfilename) s = inputfile.read() # See if there's a separation between the pre-parser and parser f = s.find(DIVIDER) if f >= 0: preparser, s = s[:f]+'\n\n', s[f+len(DIVIDER):] # See if there's a separation between the parser and post-parser f = s.find(DIVIDER) if f >= 0: s, postparser = s[:f], '\n\n'+s[f+len(DIVIDER):] # Create the parser and scanner and parse the text scanner = grammar.ParserDescriptionScanner(s, filename=inputfilename) if preparser: scanner.del_line += preparser.count('\n') parser = grammar.ParserDescription(scanner) t = runtime.wrap_error_reporter(parser, 'Parser') if t is None: return 1 # Failure if preparser is not None: t.preparser = preparser if postparser is not None: t.postparser = postparser # Add command line options to the set t.options.update(flags) # Generate the output if dump: t.dump_information() else: if isinstance(outputfile, string_types): outputfile = open(outputfile, 'w') t.output = outputfile t.generate_output() return 0
def generate(inputfilename, outputfilename='', dump=0, **flags): """Generate a grammar, given an input filename (X.g) and an output filename (defaulting to X.py).""" if not outputfilename: if inputfilename.endswith('.g'): outputfilename = inputfilename[:-2] + '.py' else: raise Exception('Must specify output filename if input filename is not *.g') DIVIDER = '\n%%\n' # This pattern separates the pre/post parsers preparser, postparser = None, None # Code before and after the parser desc # Read the entire file s = open(inputfilename,'r').read() # See if there's a separation between the pre-parser and parser f = s.find(DIVIDER) if f >= 0: preparser, s = s[:f]+'\n\n', s[f+len(DIVIDER):] # See if there's a separation between the parser and post-parser f = s.find(DIVIDER) if f >= 0: s, postparser = s[:f], '\n\n'+s[f+len(DIVIDER):] # Create the parser and scanner and parse the text scanner = grammar.ParserDescriptionScanner(s, filename=inputfilename) if preparser: scanner.del_line += preparser.count('\n') parser = grammar.ParserDescription(scanner) t = runtime.wrap_error_reporter(parser, 'Parser') if t is None: return 1 # Failure if preparser is not None: t.preparser = preparser if postparser is not None: t.postparser = postparser # Check the options for f in t.options.keys(): for opt,_,_ in yapps_options: if f == opt: break else: print >>sys.stderr, 'Warning: unrecognized option', f # Add command line options to the set for f in flags.keys(): t.options[f] = flags[f] # Generate the output if dump: t.dump_information() else: t.output = open(outputfilename, 'w') t.generate_output() return 0
def parse(rule, text): P = CiscoShowIpOspfNeighbor(CiscoShowIpOspfNeighborScanner(text)) return runtime.wrap_error_reporter(P, rule)
def parse(rule, text): P = CodeParser(CodeParserScanner(text)) return runtime.wrap_error_reporter(P, rule)
def parse(rule, text): P = FireWolfParser(FireWolfParserScanner(text)) return runtime.wrap_error_reporter(P, rule)
def parse(rule, text): P = SearchParser(SearchParserScanner(text)) return runtime.wrap_error_reporter(P, rule)
def parse(rule, text): P = CiscoShowArp(CiscoShowArpScanner(text)) return runtime.wrap_error_reporter(P, rule)
def parse(rule, text): P = NoBrainFuck(NoBrainFuckScanner(text)) return runtime.wrap_error_reporter(P, rule)
def parse(rule, text): P = Nscr(NscrScanner(text)) return runtime.wrap_error_reporter(P, rule)
def parse(rule, text): P = DiceCalculator(DiceCalculatorScanner(text)) return runtime.wrap_error_reporter(P, rule)
def parse(rule, text): P = NetscreenGetSystem(NetscreenGetSystemScanner(text)) return runtime.wrap_error_reporter(P, rule)
def parse(rule, text): P = CiscoShowProcessCpu(CiscoShowProcessCpuScanner(text)) return runtime.wrap_error_reporter(P, rule)
def parse(rule, text): P = psfasc(psfascScanner(text)) return runtime.wrap_error_reporter(P, rule)
def parse(rule, text): P = sql(sqlScanner(text)) return runtime.wrap_error_reporter(P, rule)
def parse(rule, text): P = TimosShowRouterArp(TimosShowRouterArpScanner(text)) return runtime.wrap_error_reporter(P, rule)
def parse(rule, text): P = skillparser(skillparserScanner(text)) return runtime.wrap_error_reporter(P, rule)
def parse(rule, text): P = Lyrics(LyricsScanner(text)) return runtime.wrap_error_reporter(P, rule)
def parse(rule, text): P = TimosShowRouterBgpSummary(TimosShowRouterBgpSummaryScanner(text)) return runtime.wrap_error_reporter(P, rule)
def parse(rule, text): P = IMP3(IMP3Scanner(text)) return runtime.wrap_error_reporter(P, rule)
def parse(rule, text): P = ParserDescription(ParserDescriptionScanner(text)) return runtime.wrap_error_reporter(P, rule)
def parse(rule, text): P = Test(TestScanner(text)) return runtime.wrap_error_reporter(P, rule)
def parse(rule, text): P = TimosShowPortDescription(TimosShowPortDescriptionScanner(text)) return runtime.wrap_error_reporter(P, rule)
def parse(rule, text): P = Prodo(ProdoScanner(text)) return runtime.wrap_error_reporter(P, rule)
def parse(rule, text): P = IndexerQuery(IndexerQueryScanner(text)) return runtime.wrap_error_reporter(P, rule)
def parse(rule, text): P = Cnn(CnnScanner(text)) # TODO: fix error thrown by wrap_error_reporter when wrn added return runtime.wrap_error_reporter(P, rule)
def parse(rule, text): P = Proboj(ProbojScanner(text)) return runtime.wrap_error_reporter(P, rule)
def parse(rule, text): P = CiscoShowInterfaceDescription( CiscoShowInterfaceDescriptionScanner(text)) return runtime.wrap_error_reporter(P, rule)
def parse(rule, text): P = Hercule(HerculeScanner(text)) return runtime.wrap_error_reporter(P, rule)
def parse(rule, text): """ parses the state string corresponding to a certain net """ P = Cnn(CnnScanner(text)) return runtime.wrap_error_reporter(P, rule)