Exemple #1
0
 def walk(self, tree:ParseTree, ast):
     if tree.getChildCount() > 1:
         for child in tree.getChildren():
             # Don't add useless token to tree
             if isinstance(child.getPayload(), antlr4.Token) and child.symbol.type in useless_tokens:
                 continue
             temp = CstFlattened(ast, child)
             if not isinstance(temp.payload, antlr4.Token):
                 # Only traverse down if the payload is not a Token.
                 self.walk(child, temp)
     else:
         super().walk(tree, ast)
Exemple #2
0
 def walk(self, tree: ParseTree, ast):
     if tree.getChildCount() > 1:
         for child in tree.getChildren():
             # Don't add useless token to tree
             if isinstance(
                     child.getPayload(),
                     antlr4.Token) and child.symbol.type in useless_tokens:
                 continue
             temp = CstFlattened(ast, child)
             if not isinstance(temp.payload, antlr4.Token):
                 # Only traverse down if the payload is not a Token.
                 self.walk(child, temp)
     else:
         super().walk(tree, ast)
Exemple #3
0
 def walk(self, tree: ParseTree, ast):
     if tree.getChildCount() == 0:
         # We've reached a leaf. We must create a new instance of an AST because
         # the constructor will make sure this new instance is added to its parent's
         # child nodes.
         CstFlattened(ast, tree)
     elif tree.getChildCount() == 1:
         # We've reached an inner node with a single child: we don't include this in
         # our AST.
         self.walk(tree.getChild(0), ast)
     elif tree.getChildCount() > 1:
         for child in tree.getChildren():
             temp = CstFlattened(ast, child)
             if not isinstance(temp.payload, antlr4.Token):
                 # Only traverse down if the payload is not a Token.
                 self.walk(child, temp)
Exemple #4
0
 def walk(self, tree:ParseTree, ast):
     if tree.getChildCount() == 0:
         # We've reached a leaf. We must create a new instance of an AST because
         # the constructor will make sure this new instance is added to its parent's
         # child nodes.
         CstFlattened(ast, tree)
     elif tree.getChildCount() == 1:
         # We've reached an inner node with a single child: we don't include this in
         # our AST.
         self.walk(tree.getChild(0), ast)
     elif tree.getChildCount() > 1:
         for child in tree.getChildren():
             temp = CstFlattened(ast, child)
             if not isinstance(temp.payload, antlr4.Token):
                 # Only traverse down if the payload is not a Token.
                 self.walk(child, temp)