def compile(self, grammar, globals=None): """ Produce an object capable of parsing via this grammar. @param grammar: A string containing an OMeta grammar. """ g = OMeta(grammar) tree = g.parseGrammar('TestGrammar') g = GrammarInterpreter(tree, OMetaBase, globals) return HandyInterpWrapper(g)
def compile(self, grammar, globals=None): """ Produce an object capable of parsing via this grammar. @param grammar: A string containing an OMeta grammar. """ g = OMeta(grammar) tree = g.parseGrammar('TestGrammar') g = GrammarInterpreter(tree, OMetaBase, globals) return HandyInterpWrapper(g)
def test_failure(self): g = OMeta(""" foo = 'a':one baz:two 'd'+ 'e' -> (one, two) baz = 'b' | 'c' """, {}) tree = g.parseGrammar('TestGrammar') i = TrampolinedGrammarInterpreter( tree, 'foo', callback=lambda x: setattr(self, 'result', x)) e = self.assertRaises(ParseError, i.receive, 'foobar') self.assertEqual(str(e), "\nfoobar\n^\nParse error at line 1, column 0:" " expected the character 'a'. trail: []\n")
def test_failure(self): g = OMeta(""" foo = 'a':one baz:two 'd'+ 'e' -> (one, two) baz = 'b' | 'c' """, {}) tree = g.parseGrammar('TestGrammar') i = TrampolinedGrammarInterpreter( tree, 'foo', callback=lambda x: setattr(self, 'result', x)) e = self.assertRaises(ParseError, i.receive, 'foobar') self.assertEqual(str(e), "\nfoobar\n^\nParse error at line 2, column 0:" " expected the character 'a'. trail: []\n")
import sys from ometa.grammar import OMeta from ometa.builder import writePython if len(sys.argv) != 3: print "Usage: %s grammar-filename python-filename" % (sys.argv[0],) sys.exit(1) with open(sys.argv[1]) as infile: grammar = infile.read() g = OMeta(grammar) tree = g.parseGrammar("Parser") source = writePython(tree, grammar) + '\n' with open(sys.argv[2], 'w') as outfile: outfile.write(source)
import sys from ometa.grammar import OMeta from ometa.builder import writePython if len(sys.argv) != 3: print "Usage: %s grammar-filename python-filename" % (sys.argv[0], ) sys.exit(1) with open(sys.argv[1]) as infile: grammar = infile.read() g = OMeta(grammar) tree = g.parseGrammar("Parser") source = writePython(tree, grammar) + '\n' with open(sys.argv[2], 'w') as outfile: outfile.write(source)
def compile(self, grammar, globals=None): g = OMeta(grammar) tree = g.parseGrammar('TestGrammar') return TrampolinedInterpWrapper(tree, globals)
def compile(self, grammar, globals=None): g = OMeta(grammar) tree = g.parseGrammar('TestGrammar') return TrampolinedInterpWrapper(tree, globals)