Beispiel #1
0
 def test_stringConsumedBy(self):
     called = []
     grammarSource = "rule = <'x'+>:y -> y"
     grammar = OMeta(grammarSource).parseGrammar("Parser")
     def interp(result, error):
         called.append(result)
     trampoline = TrampolinedGrammarInterpreter(grammar, "rule", interp)
     trampoline.receive("xxxxx")
     trampoline.end()
     self.assertEqual(called, ["xxxxx"])
Beispiel #2
0
 def test_stringConsumedBy(self):
     called = []
     grammarSource = "rule = <'x'+>:y -> y"
     grammar = OMeta(grammarSource).parseGrammar("Parser")
     def interp(result, error):
         called.append(result)
     trampoline = TrampolinedGrammarInterpreter(grammar, "rule", interp)
     trampoline.receive("xxxxx")
     trampoline.end()
     self.assertEqual(called, ["xxxxx"])
Beispiel #3
0
 def doIt(s):
     """
     @param s: The string to be parsed by the wrapped grammar.
     """
     tree = not isinstance(s, basestring)
     if tree:
         raise unittest.SkipTest("Not applicable for push parsing")
     results = []
     def whenDone(val, err):
         results.append(val)
     parser = TrampolinedGrammarInterpreter(self._tree, name, whenDone,
                                            self._globals)
     for i, c in enumerate(s):
         assert len(results) == 0
         parser.receive(c)
     parser.end()
     if results and parser.input.position == len(parser.input.data):
         try:
             return ''.join(results[0])
         except TypeError:
             return results[0]
     else:
         raise parser.currentError
Beispiel #4
0
 def doIt(s):
     """
     @param s: The string to be parsed by the wrapped grammar.
     """
     tree = not isinstance(s, basestring)
     if tree:
         raise unittest.SkipTest("Not applicable for push parsing")
     results = []
     def whenDone(val, err):
         results.append(val)
     parser = TrampolinedGrammarInterpreter(self._tree, name, whenDone,
                                            self._globals)
     for i, c in enumerate(s):
         assert len(results) == 0
         parser.receive(c)
     parser.end()
     if results and parser.input.position == len(parser.input.data):
         try:
             return ''.join(results[0])
         except TypeError:
             return results[0]
     else:
         raise parser.currentError