From 7e100d137caec139daacc2967836f957bb0818fe Mon Sep 17 00:00:00 2001 From: Yclept Nemo Date: Sat, 29 Jul 2023 11:15:39 -0400 Subject: [PATCH] expose the "apply" rule Allow higher-order rules --- ometa/runtime.py | 1 + ometa/test/test_runtime.py | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/ometa/runtime.py b/ometa/runtime.py index d6bdc24..49e41ff 100644 --- a/ometa/runtime.py +++ b/ometa/runtime.py @@ -800,6 +800,7 @@ def digit(self): rule_end = end rule_ws = eatWhitespace rule_exactly = exactly + rule_apply = apply #Deprecated. rule_spaces = eatWhitespace diff --git a/ometa/test/test_runtime.py b/ometa/test/test_runtime.py index 957f3bc..474acb5 100644 --- a/ometa/test/test_runtime.py +++ b/ometa/test/test_runtime.py @@ -58,6 +58,17 @@ def test_exactlyFail(self): self.assertEquals(exc.args[0], 0) + def test_apply(self): + """ + L{OMetaBase.rule_apply} applies the given rule with arguments. + """ + data = "foo" + o = OMetaBase(data) + v, e = o.rule_apply("exactly", "f") + self.assertEqual(v, "f") + self.assertEqual(e.args[0], 0) + self.assertRaises(NameError, o.rule_apply, "foo") + def test_token(self): """