def test_markAsTree(self): """ Grammars containing list patterns are marked as taking tree-shaped input rather than character streams. """ x = t.Rule("foo", t.List(t.Exactly("x"))) g = t.Grammar("TestGrammar", True, [x]) self.assert_("\n tree = True\n" in writePython(g, ""))
def test_listpattern(self): """ Test code generation for list patterns. """ x = t.List(t.Exactly("x")) self.assertEqual( writePython(x, ""), dd(""" def _G_listpattern_1(): _G_exactly_2, lastError = self.exactly('x') self.considerError(lastError, None) return (_G_exactly_2, self.currentError) _G_listpattern_3, lastError = self.listpattern(_G_listpattern_1) self.considerError(lastError, None) _G_listpattern_3 """))
def test_listpattern(self): x = t.List(t.Exactly("x")) self.assertEqual( writeBytecode(x), [t.Descend(), t.Match('x'), t.Ascend()])