Пример #1
0
def load_python_file(moduleobject):
    """ Try to create an indexable instance from a module"""
    if isinstance(moduleobject, str):
        moduleobject = load_module(moduleobject)
    if not hasattr(moduleobject, "iclass"):
        raise KeyError("Element" + str(moduleobject))
    iclass = getattr(moduleobject, "iclass")
    mylist = getattr(moduleobject, "__all__", None) or list(
        filter(lambda x: x[:1] != "_", (dir(moduleobject))))
    mylist.remove('iclass')
    resultdic = {}
    for x in mylist:
        resultdic[x] = getattr(moduleobject, x)
    if iclass == "SymbolGrammar":
        from pydsl.grammar.BNF import BNFGrammar
        return BNFGrammar(**resultdic)
    elif iclass == "PLY":
        from pydsl.grammar.definition import PLYGrammar
        return PLYGrammar(moduleobject)
    elif iclass in ["PythonGrammar"]:
        from pydsl.grammar.definition import PythonGrammar
        return PythonGrammar(resultdic)
    elif iclass == "PythonTranslator":
        return resultdic
    elif iclass == "parsley":
        from pydsl.grammar.parsley import ParsleyGrammar
        return ParsleyGrammar(**resultdic)
    elif iclass == "pyparsing":
        return resultdic['root_symbol']
    else:
        raise ValueError(str(moduleobject))
Пример #2
0
 def testCheck(self):
     """Test checker instantiation and call"""
     from pydsl.check import PLYChecker
     from pydsl.contrib.grammar import example_ply
     from pydsl.grammar.definition import PLYGrammar
     grammardef = PLYGrammar(example_ply)
     checker = PLYChecker(grammardef)
     self.assertTrue(checker.check("O"))
     self.assertTrue(checker.check(["O"]))
     self.assertFalse(checker.check("FALSE"))
Пример #3
0
class TestGrammarDefinitionPLY(unittest.TestCase):
    def setUp(self):
        import plye
        from pydsl.grammar.definition import PLYGrammar
        self.grammardef = PLYGrammar(plye)

    @unittest.skip
    def testEnumerate(self):
        self.grammardef.enum()

    @unittest.skip
    def testFirst(self):
        self.grammardef.first

    @unittest.skip
    def testMin(self):
        self.grammardef.minsize

    @unittest.skip
    def testMax(self):
        self.grammardef.maxsize

    def testAlphabet(self):
        self.assertListEqual(self.grammardef.alphabet, frozenset)
Пример #4
0
class TestGrammarDefinitionPLY(unittest.TestCase):
    def setUp(self):
        import plye
        from pydsl.grammar.definition import PLYGrammar
        self.grammardef = PLYGrammar(plye)

    @unittest.skip
    def testEnumerate(self):
        self.grammardef.enum()

    @unittest.skip
    def testFirst(self):
        self.grammardef.first

    @unittest.skip
    def testMin(self):
        self.grammardef.minsize

    @unittest.skip
    def testMax(self):
        self.grammardef.maxsize

    def testAlphabet(self):
        self.assertListEqual(self.grammardef.alphabet, frozenset)
Пример #5
0
 def setUp(self):
     import plye
     from pydsl.grammar.definition import PLYGrammar
     self.grammardef = PLYGrammar(plye)
Пример #6
0
 def setUp(self):
     import plye
     from pydsl.grammar.definition import PLYGrammar
     self.grammardef = PLYGrammar(plye)