From c37573ebe124b99f0b628540c491164220b4ed99 Mon Sep 17 00:00:00 2001 From: Robert Collins Date: Tue, 17 Nov 2015 22:35:14 +1300 Subject: [PATCH] Test that mutual recursion works for Ometa V1 syntax Working on issue 57 --- ometa/test/test_pymeta.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/ometa/test/test_pymeta.py b/ometa/test/test_pymeta.py index ed7e57f..2021587 100644 --- a/ometa/test/test_pymeta.py +++ b/ometa/test/test_pymeta.py @@ -359,6 +359,23 @@ def test_leftrecursion(self): self.assertEqual(g.num("32767"), 32767) + def test_mutual_leftrecursion(self): + g = self.compile(""" + num ::= (:n :d => n * 10 + d + | ) + digit ::= :x ?(x.isdigit()) => int(x) + x ::= + expr ::= :e '-' :n => e - n + | + """) + self.assertEqual(g.expr("3"), 3) + self.assertEqual(g.expr("3-2"), 1) + self.assertEqual(g.expr("3-2-1"), 0) + self.assertEqual(g.x("3"), 3) + self.assertEqual(g.x("3-2"), 1) + self.assertEqual(g.x("3-2-1"), 0) + + def test_characterVsSequence(self): """ Characters (in single-quotes) are not regarded as sequences.