From 4c841846640d51f058ccc0f05551259cca0c88a0 Mon Sep 17 00:00:00 2001 From: Robert Collins Date: Tue, 17 Nov 2015 22:44:41 +1300 Subject: [PATCH 1/2] Test on 3.4 and drop 3.2. Coverage no longer supports 3.2, and since we only just release 3.x support its highly likely noone cares that we test on 3.2 or not. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index ab462ab..6d0996a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,8 +2,8 @@ language: python python: - "2.6" - "2.7" - - "3.2" - "3.3" + - "3.4" install: - "bash .travis.install" From 8fc17f6d3707624370dc948b9cb2f89fa7364630 Mon Sep 17 00:00:00 2001 From: Robert Collins Date: Tue, 17 Nov 2015 22:35:14 +1300 Subject: [PATCH 2/2] Test that mutual recursion works Working on issue 57 --- ometa/test/test_pymeta.py | 53 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/ometa/test/test_pymeta.py b/ometa/test/test_pymeta.py index ed7e57f..9a83ba7 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. @@ -806,6 +823,23 @@ def test_leftrecursion(self): self.assertEqual(g.num("32767"), 32767) + def test_mutual_leftrecursion(self): + g = self.compile(""" + num = (num:n digit:d -> n * 10 + d + | digit) + digit = :x ?(x.isdigit()) -> int(x) + x = expr + expr = x:e '-' num:n -> e - n + | num + """) + 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. @@ -1011,6 +1045,25 @@ def test_leftrecursion(self): self.assertEqual(g.num("3"), 3) self.assertEqual(g.num("32767"), 32767) + def test_mutual_leftrecursion(self): + g = self.compile(""" + num = (num:n digit:d -> makeInt(n, d) + | digit) + digit = :x ?(isdigit(x)) -> int(x) + x = expr + expr = x:e '-' num:n -> subtract(e, n) + | num + """, {"makeInt": lambda x, y: x * 10 + y, + "isdigit": lambda x: x.isdigit(), + "subtract": lambda x, y: x-y}) + 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.