Browse Source
Merge pull request #133 from Gentle/interpreter_defaults
Interpreter class: fixed default behavior to return results
tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.6.0
Erez Shinan
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
9 additions and
1 deletions
-
lark/tree.py
-
tests/test_trees.py
|
|
@@ -195,7 +195,7 @@ class Interpreter(object): |
|
|
|
return self.__default__ |
|
|
|
|
|
|
|
def __default__(self, tree): |
|
|
|
self.visit_children(tree) |
|
|
|
return self.visit_children(tree) |
|
|
|
|
|
|
|
|
|
|
|
class Transformer_NoRecurse(Transformer): |
|
|
|
|
|
@@ -49,6 +49,14 @@ class TestTrees(TestCase): |
|
|
|
|
|
|
|
self.assertEqual(Interp2().visit(t), list('BCde')) |
|
|
|
|
|
|
|
class Interp3(Interpreter): |
|
|
|
def b(self, tree): |
|
|
|
return 'B' |
|
|
|
|
|
|
|
def c(self, tree): |
|
|
|
return 'C' |
|
|
|
|
|
|
|
self.assertEqual(Interp3().visit(t), list('BCd')) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|