diff --git a/runtime/JavaScript/src/antlr4/tree/Trees.js b/runtime/JavaScript/src/antlr4/tree/Trees.js index 63678d6a4..64ae02230 100644 --- a/runtime/JavaScript/src/antlr4/tree/Trees.js +++ b/runtime/JavaScript/src/antlr4/tree/Trees.js @@ -11,132 +11,129 @@ const {RuleContext} = require('./../RuleContext'); const {ATN: {INVALID_ALT_NUMBER}} = require('./../atn/ATN'); /** A set of utility routines useful for all kinds of ANTLR trees. */ -function Trees() { +const Trees = { + /** + * Print out a whole tree in LISP form. {@link //getNodeText} is used on the + * node payloads to get the text for the nodes. Detect + * parse trees and extract data appropriately. + */ + toStringTree: function(tree, ruleNames, recog) { + ruleNames = ruleNames || null; + recog = recog || null; + if(recog!==null) { + ruleNames = recog.ruleNames; + } + let s = Trees.getNodeText(tree, ruleNames); + s = Utils.escapeWhitespace(s, false); + const c = tree.getChildCount(); + if(c===0) { + return s; + } + let res = "(" + s + ' '; + if(c>0) { + s = Trees.toStringTree(tree.getChild(0), ruleNames); + res = res.concat(s); + } + for(let i=1;i0) { - s = Trees.toStringTree(tree.getChild(0), ruleNames); - res = res.concat(s); - } - for(let i=1;i