当前位置: 首页>>代码示例>>Java>>正文


Java RuleNode.getRuleContext方法代码示例

本文整理汇总了Java中org.antlr.v4.runtime.tree.RuleNode.getRuleContext方法的典型用法代码示例。如果您正苦于以下问题:Java RuleNode.getRuleContext方法的具体用法?Java RuleNode.getRuleContext怎么用?Java RuleNode.getRuleContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.antlr.v4.runtime.tree.RuleNode的用法示例。


在下文中一共展示了RuleNode.getRuleContext方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getSourceInterval

import org.antlr.v4.runtime.tree.RuleNode; //导入方法依赖的package包/类
public static Interval getSourceInterval(@NonNull ParseTree context) {
    Parameters.notNull("context", context);

    if (context instanceof TerminalNode) {
        TerminalNode terminalNode = (TerminalNode)context;
        Token token = terminalNode.getSymbol();
        return new Interval(token.getStartIndex(), token.getStopIndex());
    } else if (context instanceof RuleNode) {
        RuleNode ruleNode = (RuleNode)context;
        RuleContext ruleContext = ruleNode.getRuleContext();
        if (ruleContext instanceof ParserRuleContext) {
            return getSourceInterval((ParserRuleContext)ruleContext);
        } else {
            Token startSymbol = getStartSymbol(context);
            Token stopSymbol = getStopSymbol(context);
            if (startSymbol == null || stopSymbol == null) {
                return Interval.INVALID;
            }

            return new Interval(startSymbol.getStartIndex(), stopSymbol.getStopIndex());
        }
    } else {
        return Interval.INVALID;
    }
}
 
开发者ID:tunnelvisionlabs,项目名称:goworks,代码行数:26,代码来源:ParseTrees.java

示例2: findAncestor

import org.antlr.v4.runtime.tree.RuleNode; //导入方法依赖的package包/类
@CheckForNull
public static <ContextClass> ContextClass findAncestor(@NonNull ParseTree tree, @NonNull Class<ContextClass> nodeType) {
    for (ParseTree current = tree; current != null; current = current.getParent()) {
        if (!(current instanceof RuleNode)) {
            continue;
        }

        RuleNode ruleNode = (RuleNode)current;
        RuleContext ruleContext = ruleNode.getRuleContext();
        if (nodeType.isInstance(ruleContext)) {
            return nodeType.cast(ruleContext);
        }
    }

    return null;
}
 
开发者ID:tunnelvisionlabs,项目名称:goworks,代码行数:17,代码来源:ParseTrees.java

示例3: visitChildren

import org.antlr.v4.runtime.tree.RuleNode; //导入方法依赖的package包/类
@RuleDependency(recognizer=GoParser.class, rule=RULE_expression, version=1)
@Override
public Boolean visitChildren(RuleNode node) {
    RuleContext ruleContext = node.getRuleContext();
    if (ruleContext instanceof ExpressionContext) {
        return visitAnyExpression((ExpressionContext)ruleContext);
    }

    return super.visitChildren(node);
}
 
开发者ID:tunnelvisionlabs,项目名称:goworks,代码行数:11,代码来源:GoParser.java

示例4: walk

import org.antlr.v4.runtime.tree.RuleNode; //导入方法依赖的package包/类
@Override
@RuleDependency(recognizer=GoParser.class, rule=GoParser.RULE_body, version=0)
public void walk(ParseTreeListener listener, ParseTree t) {
    if (t instanceof RuleNode) {
        RuleNode ruleNode = (RuleNode)t;
        if (ruleNode.getRuleContext() instanceof BodyContext) {
            return;
        }
    }

    super.walk(listener, t);
}
 
开发者ID:tunnelvisionlabs,项目名称:goworks,代码行数:13,代码来源:CodeModelBuilderListener.java

示例5: ParseTreeNode

import org.antlr.v4.runtime.tree.RuleNode; //导入方法依赖的package包/类
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");
        }
    }
}
 
开发者ID:tunnelvisionlabs,项目名称:goworks,代码行数:49,代码来源:ParseTreeNode.java


注:本文中的org.antlr.v4.runtime.tree.RuleNode.getRuleContext方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。