Java 类org.antlr.v4.runtime.InterpreterRuleContext 实例源码

项目:codebuff    文件:GrammarParserInterpreter.java   
@Override
protected InterpreterRuleContext createInterpreterRuleContext(ParserRuleContext parent,
                                                              int invokingStateNumber,
                                                              int ruleIndex)
{
    return new GrammarInterpreterRuleContext(parent, invokingStateNumber, ruleIndex);
}
项目:goworks    文件:ParseTreeNode.java   
public ParseTreeNode(@NonNull ParseTree tree, @NullAllowed List<String> ruleNames) {
    super(Children.LEAF);
    _tree = tree;
    _ruleNames = ruleNames;

    if (tree.getChildCount() > 0) {
        setChildren(Children.createLazy(new ChildrenOfParseTreeNodeCreator()));
    }

    if (tree instanceof RuleNode) {
        RuleNode ruleNode = (RuleNode)tree;
        RuleContext ruleContext = ruleNode.getRuleContext();
        if (ruleContext instanceof ParserRuleContext && ruleContext.getClass() != ParserRuleContext.class && ruleContext.getClass() != InterpreterRuleContext.class) {
            String contextName = ruleContext.getClass().getSimpleName();
            if (!"Context".equals(contextName) && contextName.endsWith("Context")) {
                contextName = contextName.substring(0, contextName.length() - "Context".length());
            }

            contextName = Character.toLowerCase(contextName.charAt(0)) + contextName.substring(1);
            setDisplayName(contextName);
        } else {
            String displayName = null;
            if (ruleNames != null && ruleContext.getRuleIndex() >= 0 && ruleContext.getRuleIndex() < ruleNames.size()) {
                displayName = ruleNames.get(ruleContext.getRuleIndex());
            }

            if (displayName == null || displayName.isEmpty()) {
                displayName = "Rule Node";
            }
            setDisplayName(displayName);
        }
    } else if (tree instanceof ErrorNode) {
        setDisplayName("Error Node");
    } else if (tree instanceof TerminalNode) {
        String nodeText = tree.getText();
        if (nodeText != null && !nodeText.isEmpty()) {
            nodeText = nodeText.substring(0, Math.min(nodeText.length(), 100));
            nodeText = nodeText.replace("\\", "\\\\");
            nodeText = nodeText.replace("\r", "\\r");
            nodeText = nodeText.replace("\n", "\\n");
            nodeText = nodeText.replace("\t", "\\t");
            nodeText = nodeText.replace("'", "\\'");
            setDisplayName("'" + nodeText + "'");
        } else {
            setDisplayName("Terminal Node");
        }
    }
}
项目:intellij-plugin-v4    文件:PreviewParser.java   
@Override
protected InterpreterRuleContext createInterpreterRuleContext(ParserRuleContext parent, int invokingStateNumber, int ruleIndex) {
    return new PreviewInterpreterRuleContext(parent, invokingStateNumber, ruleIndex);
}
项目:antlrworks2    文件:ParseTreeNode.java   
public ParseTreeNode(@NonNull ParseTree tree, @NullAllowed List<String> ruleNames) {
    super(Children.LEAF);
    _tree = tree;
    _ruleNames = ruleNames;

    if (tree.getChildCount() > 0) {
        setChildren(Children.createLazy(new ChildrenOfParseTreeNodeCreator()));
    }

    if (tree instanceof RuleNode) {
        RuleNode ruleNode = (RuleNode)tree;
        RuleContext ruleContext = ruleNode.getRuleContext();
        if (ruleContext instanceof ParserRuleContext && ruleContext.getClass() != ParserRuleContext.class && ruleContext.getClass() != InterpreterRuleContext.class) {
            String contextName = ruleContext.getClass().getSimpleName();
            if (!"Context".equals(contextName) && contextName.endsWith("Context")) {
                contextName = contextName.substring(0, contextName.length() - "Context".length());
            }

            contextName = Character.toLowerCase(contextName.charAt(0)) + contextName.substring(1);
            setDisplayName(contextName);
        } else {
            String displayName = null;
            if (ruleNames != null && ruleContext.getRuleIndex() >= 0 && ruleContext.getRuleIndex() < ruleNames.size()) {
                displayName = ruleNames.get(ruleContext.getRuleIndex());
            }

            if (displayName == null || displayName.isEmpty()) {
                displayName = "Rule Node";
            }
            setDisplayName(displayName);
        }
    } else if (tree instanceof ErrorNode) {
        setDisplayName("Error Node");
    } else if (tree instanceof TerminalNode) {
        String nodeText = tree.getText();
        if (nodeText != null && !nodeText.isEmpty()) {
            nodeText = nodeText.substring(0, Math.min(nodeText.length(), 100));
            nodeText = nodeText.replace("\\", "\\\\");
            nodeText = nodeText.replace("\r", "\\r");
            nodeText = nodeText.replace("\n", "\\n");
            nodeText = nodeText.replace("\t", "\\t");
            nodeText = nodeText.replace("'", "\\'");
            setDisplayName("'" + nodeText + "'");
        } else {
            setDisplayName("Terminal Node");
        }
    }
}