Esempio n. 1
0
def pgen_compose (pgen_st1, pgen_st2, start_symbol, additional_tokens = None):
    nfa_grammar1 = pgen.handleStart(pgen_st1)
    nfa_grammar2 = pgen.handleStart(pgen_st2)
    nfa_composed = nfa.compose_nfas(nfa_grammar1, nfa_grammar2)
    grammar3 = pgen.generateDfaGrammar(nfa_composed, start_symbol)
    pgen.translateLabels(grammar3, additional_tokens)
    pgen.generateFirstSets(grammar3)
    grammar3[0] = map(tuple, grammar3[0])
    return DFAParser.addAccelerators(tuple(grammar3))
Esempio n. 2
0
 def test_simple_compose (self):
     testpath = os.path.split(__file__)[0]
     gobj1 = PyPgen.PyPgen().handleStart(
         PgenParser.parseFile(os.path.join(testpath, 'test.pgen')))
     gobj2 = PyPgen.PyPgen().handleStart(
         PgenParser.parseFile(os.path.join(testpath, 'ext.pgen')))
     gobj3 = nfa.compose_nfas(gobj1, gobj2)
     self.assertTrue(gobj3)
     self.assertEqual(len(gobj3[0]), len(gobj1[0]))
     self.assertNotEqual(gobj3[0], gobj1[0])
Esempio n. 3
0
# Module data

MY_GRAMMAR_EXT = """
compound_stmt: quotedef
quotedef: 'quote' ['[' expr ']'] [NAME] qsuite
qsuite: ':' (QUOTED NEWLINE | NEWLINE QUOTED)
"""

MY_START_SYMBOL = 'file_input'

pgen = PyPgen.PyPgen()
py_grammar_path = os.path.split(basil.lang.python.__file__)[0]
py_nfa_grammar = pgen.handleStart(PgenParser.parseFile(
    os.path.join(py_grammar_path, 'python26/Grammar')))
ext_nfa_grammar = pgen.handleStart(PgenParser.parseString(MY_GRAMMAR_EXT))
my_nfa_grammar = nfa.compose_nfas(py_nfa_grammar, ext_nfa_grammar)
my_grammar0 = pgen.generateDfaGrammar(my_nfa_grammar, MY_START_SYMBOL)
pgen.translateLabels(my_grammar0, {'QUOTED' : mylexer.QUOTED})
pgen.generateFirstSets(my_grammar0)
my_grammar0[0] = map(tuple, my_grammar0[0])
my_grammar0 = tuple(my_grammar0)
my_grammar = DFAParser.addAccelerators(my_grammar0)
del my_grammar0

__DEBUG__ = False

if __DEBUG__:
    import pprint

# ______________________________________________________________________
# Class and function definitions