示例#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"])
示例#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"])
示例#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
示例#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