File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1010# ----------------------------------------------------------------------
1111
1212from typing import Callable , Any
13+
1314import types
1415from .tree import Tree
1516
2021class Ast (Tree ):
2122 """ Adds some methods for easier coding...
2223 """
23- pass
24+ @property
25+ def token (self ):
26+ return self .__class__
2427
2528
2629class NodeVisitor :
@@ -45,14 +48,13 @@ def visit(self, node):
4548
4649 def _visit (self , node ):
4750 methname = 'visit_' + node .token
48- meth = getattr (self , methname , None )
49- if meth is None :
50- meth = self .generic_visit
51+ meth = getattr (self , methname , self .generic_visit )
52+
5153 return meth (node )
5254
5355 @staticmethod
5456 def generic_visit (node : Ast ):
55- raise RuntimeError ("No { }() method defined" . format ( 'visit_' + node . token ) )
57+ raise RuntimeError (f "No visit_ { node . token } () method defined" )
5658
5759 def filter_inorder (self ,
5860 node ,
You can’t perform that action at this time.
0 commit comments