Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
 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")
Ejemplo n.º 4
0
 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")
Ejemplo n.º 5
0
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)
Ejemplo n.º 6
0
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)
Ejemplo n.º 7
0
 def compile(self, grammar, globals=None):
     g = OMeta(grammar)
     tree = g.parseGrammar('TestGrammar')
     return TrampolinedInterpWrapper(tree, globals)
Ejemplo n.º 8
0
 def compile(self, grammar, globals=None):
     g = OMeta(grammar)
     tree = g.parseGrammar('TestGrammar')
     return TrampolinedInterpWrapper(tree, globals)