Example usage for org.antlr.v4.runtime.tree Tree getChildCount

List of usage examples for org.antlr.v4.runtime.tree Tree getChildCount

Introduction

In this page you can find the example usage for org.antlr.v4.runtime.tree Tree getChildCount.

Prototype

int getChildCount();

Source Link

Document

How many children are there?

Usage

From source file:br.beholder.memelang.control.MainWindowController.java

private static void fillTree(TreeNodeWrapper node, Tree tree) {

    if (tree == null) {
        return;/*from  w  ww.j av  a 2s .c o  m*/
    }

    for (int i = 0; i < tree.getChildCount(); i++) {

        Tree childTree = tree.getChild(i);
        TreeNodeWrapper childNode = new TreeNodeWrapper(childTree);

        node.add(childNode);

        fillTree(childNode, childTree);
    }
}

From source file:com.espertech.esper.epl.parse.ASTConstantHelper.java

License:Open Source License

private static RuleNode findChildRuleByType(Tree node, int ruleNum) {
    for (int i = 0; i < node.getChildCount(); i++) {
        Tree child = node.getChild(i);//  w ww .j  a  v a  2 s  .  co  m
        if (isRuleOfType(child, ruleNum)) {
            return (RuleNode) child;
        }
    }
    return null;
}

From source file:com.espertech.esper.epl.parse.ASTExprHelper.java

License:Open Source License

public static void patternCollectAddSubnodesAddParentNode(EvalFactoryNode evalNode, Tree node,
        Map<Tree, EvalFactoryNode> astPatternNodeMap) {
    if (evalNode == null) {
        throw ASTWalkException.from("Invalid null expression node for '" + ASTUtil.printNode(node) + "'");
    }//from  w w w.ja v a 2  s  .  c om
    for (int i = 0; i < node.getChildCount(); i++) {
        Tree childNode = node.getChild(i);
        EvalFactoryNode childEvalNode = patternGetRemoveTopNode(childNode, astPatternNodeMap);
        if (childEvalNode != null) {
            evalNode.addChildNode(childEvalNode);
        }
    }
    astPatternNodeMap.put(node, evalNode);
}

From source file:com.espertech.esper.epl.parse.ASTExprHelper.java

License:Open Source License

public static EvalFactoryNode patternGetRemoveTopNode(Tree node, Map<Tree, EvalFactoryNode> astPatternNodeMap) {
    EvalFactoryNode pattern = astPatternNodeMap.get(node);
    if (pattern != null) {
        astPatternNodeMap.remove(node);//from   w  w w  .  j a v a2  s.  co m
        return pattern;
    }
    for (int i = 0; i < node.getChildCount(); i++) {
        pattern = patternGetRemoveTopNode(node.getChild(i), astPatternNodeMap);
        if (pattern != null) {
            return pattern;
        }
    }
    return null;
}

From source file:com.espertech.esper.epl.parse.ASTExprHelper.java

License:Open Source License

public static void regExCollectAddSubNodes(final RowRegexExprNode regexNode, Tree node,
        Map<Tree, RowRegexExprNode> astRegExNodeMap) {
    if (regexNode == null) {
        throw ASTWalkException.from("Invalid null expression node for '" + ASTUtil.printNode(node) + "'");
    }/* w w  w .jav  a2 s  . c  o m*/
    RegExAction action = new RegExAction() {
        public void found(RowRegexExprNode exprNode, Map<Tree, RowRegexExprNode> astRegExNodeMap, Tree node) {
            astRegExNodeMap.remove(node);
            regexNode.addChildNode(exprNode);
        }
    };
    for (int i = 0; i < node.getChildCount(); i++) {
        Tree childNode = node.getChild(i);
        regExApplyActionRecursive(childNode, astRegExNodeMap, action);
    }
}

From source file:com.espertech.esper.epl.parse.ASTExprHelper.java

License:Open Source License

public static void regExApplyActionRecursive(Tree node, Map<Tree, RowRegexExprNode> astRegExNodeMap,
        RegExAction action) {/* w  w  w  .  ja v a 2 s.  co m*/
    RowRegexExprNode expr = astRegExNodeMap.get(node);
    if (expr != null) {
        action.found(expr, astRegExNodeMap, node);
        return;
    }
    for (int i = 0; i < node.getChildCount(); i++) {
        regExApplyActionRecursive(node.getChild(i), astRegExNodeMap, action);
    }
}

From source file:com.espertech.esper.epl.parse.ASTExprHelper.java

License:Open Source License

public static void exprCollectAddSubNodes(final ExprNode parentNode, Tree node,
        Map<Tree, ExprNode> astExprNodeMap) {
    if (parentNode == null) {
        throw ASTWalkException.from("Invalid null expression node for '" + ASTUtil.printNode(node) + "'");
    }/* w  w w.ja v  a2s  .c o m*/
    if (node == null) {
        return;
    }
    ExprAction action = new ExprAction() {
        public void found(ExprNode exprNode, Map<Tree, ExprNode> astExprNodeMap, Tree node) {
            astExprNodeMap.remove(node);
            parentNode.addChildNode(exprNode);
        }
    };
    for (int i = 0; i < node.getChildCount(); i++) {
        Tree childNode = node.getChild(i);
        recursiveFindRemoveChildExprNode(childNode, astExprNodeMap, action);
    }
}

From source file:com.espertech.esper.epl.parse.ASTExprHelper.java

License:Open Source License

public static List<ExprNode> exprCollectSubNodes(Tree parentNode, int startIndex,
        Map<Tree, ExprNode> astExprNodeMap) {
    ExprNode selfNode = astExprNodeMap.remove(parentNode);
    if (selfNode != null) {
        return Collections.singletonList(selfNode);
    }//from   ww  w  .ja va2 s  .  c  o  m
    final List<ExprNode> exprNodes = new ArrayList<ExprNode>();
    ExprAction action = new ExprAction() {
        public void found(ExprNode exprNode, Map<Tree, ExprNode> astExprNodeMap, Tree node) {
            astExprNodeMap.remove(node);
            exprNodes.add(exprNode);
        }
    };
    for (int i = startIndex; i < parentNode.getChildCount(); i++) {
        Tree currentNode = parentNode.getChild(i);
        recursiveFindRemoveChildExprNode(currentNode, astExprNodeMap, action);
    }
    return exprNodes;
}

From source file:com.espertech.esper.epl.parse.ASTExprHelper.java

License:Open Source License

private static void recursiveFindRemoveChildExprNode(Tree node, Map<Tree, ExprNode> astExprNodeMap,
        ExprAction action) {/*ww  w.  j a v a  2s .  com*/
    ExprNode expr = astExprNodeMap.get(node);
    if (expr != null) {
        action.found(expr, astExprNodeMap, node);
        return;
    }
    for (int i = 0; i < node.getChildCount(); i++) {
        recursiveFindRemoveChildExprNode(node.getChild(i), astExprNodeMap, action);
    }
}

From source file:com.espertech.esper.epl.parse.ASTExprHelper.java

License:Open Source License

public static RowRegexExprNode regExGetRemoveTopNode(Tree node,
        Map<Tree, RowRegexExprNode> astRowRegexNodeMap) {
    RowRegexExprNode regex = astRowRegexNodeMap.get(node);
    if (regex != null) {
        astRowRegexNodeMap.remove(node);
        return regex;
    }/*from  ww  w .  j ava 2s.  c om*/
    for (int i = 0; i < node.getChildCount(); i++) {
        regex = regExGetRemoveTopNode(node.getChild(i), astRowRegexNodeMap);
        if (regex != null) {
            return regex;
        }
    }
    return null;
}