Esempio n. 1
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
Esempio n. 2
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
Esempio n. 3
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
Esempio n. 4
0
File: yapps2.py Progetto: eykd/Dyce
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
Esempio n. 5
0
def parse(rule, text):
    P = CiscoShowIpOspfNeighbor(CiscoShowIpOspfNeighborScanner(text))
    return runtime.wrap_error_reporter(P, rule)
Esempio n. 6
0
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)
Esempio n. 8
0
def parse(rule, text):
    P = SearchParser(SearchParserScanner(text))
    return runtime.wrap_error_reporter(P, rule)
Esempio n. 9
0
def parse(rule, text):
    P = CiscoShowArp(CiscoShowArpScanner(text))
    return runtime.wrap_error_reporter(P, rule)
Esempio n. 10
0
def parse(rule, text):
    P = NoBrainFuck(NoBrainFuckScanner(text))
    return runtime.wrap_error_reporter(P, rule)
Esempio n. 11
0
def parse(rule, text):
    P = Nscr(NscrScanner(text))
    return runtime.wrap_error_reporter(P, rule)
Esempio n. 12
0
File: dcalc.py Progetto: eykd/Dyce
def parse(rule, text):
    P = DiceCalculator(DiceCalculatorScanner(text))
    return runtime.wrap_error_reporter(P, rule)
Esempio n. 13
0
def parse(rule, text):
    P = NetscreenGetSystem(NetscreenGetSystemScanner(text))
    return runtime.wrap_error_reporter(P, rule)
Esempio n. 14
0
def parse(rule, text):
    P = CiscoShowProcessCpu(CiscoShowProcessCpuScanner(text))
    return runtime.wrap_error_reporter(P, rule)
Esempio n. 15
0
def parse(rule, text):
    P = psfasc(psfascScanner(text))
    return runtime.wrap_error_reporter(P, rule)
Esempio n. 16
0
def parse(rule, text):
    P = SearchParser(SearchParserScanner(text))
    return runtime.wrap_error_reporter(P, rule)
Esempio n. 17
0
def parse(rule, text):
    P = psfasc(psfascScanner(text))
    return runtime.wrap_error_reporter(P, rule)
Esempio n. 18
0
def parse(rule, text):
    P = sql(sqlScanner(text))
    return runtime.wrap_error_reporter(P, rule)
Esempio n. 19
0
def parse(rule, text):
    P = TimosShowRouterArp(TimosShowRouterArpScanner(text))
    return runtime.wrap_error_reporter(P, rule)
Esempio n. 20
0
def parse(rule, text):
    P = skillparser(skillparserScanner(text))
    return runtime.wrap_error_reporter(P, rule)
Esempio n. 21
0
def parse(rule, text):
    P = Nscr(NscrScanner(text))
    return runtime.wrap_error_reporter(P, rule)
Esempio n. 22
0
File: grammar.py Progetto: pazur/wpp
def parse(rule, text):
    P = Lyrics(LyricsScanner(text))
    return runtime.wrap_error_reporter(P, rule)
Esempio n. 23
0
def parse(rule, text):
    P = TimosShowRouterBgpSummary(TimosShowRouterBgpSummaryScanner(text))
    return runtime.wrap_error_reporter(P, rule)
Esempio n. 24
0
File: imp3.py Progetto: gernst/imp3
def parse(rule, text):
    P = IMP3(IMP3Scanner(text))
    return runtime.wrap_error_reporter(P, rule)
Esempio n. 25
0
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)
Esempio n. 28
0
def parse(rule, text):
    P = Prodo(ProdoScanner(text))
    return runtime.wrap_error_reporter(P, rule)
Esempio n. 29
0
def parse(rule, text):
    P = IndexerQuery(IndexerQueryScanner(text))
    return runtime.wrap_error_reporter(P, rule)
Esempio n. 30
0
File: grammar.py Progetto: pazur/wpp
def parse(rule, text):
    P = Lyrics(LyricsScanner(text))
    return runtime.wrap_error_reporter(P, rule)
Esempio n. 31
0
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)
Esempio n. 32
0
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)
Esempio n. 34
0
def parse(rule, text):
    P = ParserDescription(ParserDescriptionScanner(text))
    return runtime.wrap_error_reporter(P, rule)
Esempio n. 35
0
def parse(rule, text):
    P = Hercule(HerculeScanner(text))
    return runtime.wrap_error_reporter(P, rule)
Esempio n. 36
0
def parse(rule, text):
    P = sql(sqlScanner(text))
    return runtime.wrap_error_reporter(P, rule)
Esempio n. 37
0
def parse(rule, text):
    P = CodeParser(CodeParserScanner(text))
    return runtime.wrap_error_reporter(P, rule)
Esempio n. 38
0
def parse(rule, text):
    P = skillparser(skillparserScanner(text))
    return runtime.wrap_error_reporter(P, rule)
Esempio n. 39
0
def parse(rule, text):
    """
    parses the state string corresponding to a certain net
    """
    P = Cnn(CnnScanner(text))
    return runtime.wrap_error_reporter(P, rule)