本文整理汇总了Java中org.antlr.v4.runtime.RuleContext.getChild方法的典型用法代码示例。如果您正苦于以下问题:Java RuleContext.getChild方法的具体用法?Java RuleContext.getChild怎么用?Java RuleContext.getChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.antlr.v4.runtime.RuleContext
的用法示例。
在下文中一共展示了RuleContext.getChild方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getChildContextText
import org.antlr.v4.runtime.RuleContext; //导入方法依赖的package包/类
/**
* Searches the children of the given context for a context of the given clazz
* type and returns its Text Value. If there are multiple relevant child nodes,
* we will return the text value for one of them at random.
*/
public String getChildContextText(RuleContext ctx) {
if (ctx == null) {
return "";
}
if (ctx instanceof TypeNameContext) {
return ctx.getText();
}
String s = "";
for (int i = 0; i < ctx.getChildCount(); i++) {
if (!(ctx.getChild(i) instanceof TerminalNodeImpl)) {
try {
String t = getChildContextText((RuleContext) ctx.getChild(i));
if (!t.isEmpty()) {
s += t + ",";
}
} catch (Exception e) {
// do nothing
}
}
}
return s.replaceAll(",$", "");
}
示例2: findLeftSibling
import org.antlr.v4.runtime.RuleContext; //导入方法依赖的package包/类
private ParseTree findLeftSibling(RuleContext ctx) {
RuleContext p = ctx.getParent();
if(p!=null) {
for(int i=0; i<p.getChildCount(); i++) {
if(p.getChild(i).equals(ctx)) {
if(i>0)
return p.getChild(i-1);
break;
}
}
}
return null;
}
示例3: searchTokenFromHead
import org.antlr.v4.runtime.RuleContext; //导入方法依赖的package包/类
private Token searchTokenFromHead(RuleContext ctx, SilverstripeTokenId token) {
for(int i=0; i<ctx.getChildCount(); i++) {
ParseTree child = ctx.getChild(i);
if(child instanceof TerminalNode && ((TerminalNode)child).getSymbol().getType() == token.getId()) {
return ((TerminalNode)child).getSymbol();
}
}
throw new IllegalArgumentException("Illegal arguments");
}
示例4: searchTokenFromTail
import org.antlr.v4.runtime.RuleContext; //导入方法依赖的package包/类
private Token searchTokenFromTail(RuleContext ctx, SilverstripeTokenId token) {
for(int i=ctx.getChildCount()-1; i>=0; i--) {
ParseTree child = ctx.getChild(i);
if(child instanceof TerminalNode && ((TerminalNode)child).getSymbol().getType() == token.getId()) {
return ((TerminalNode)child).getSymbol();
}
}
throw new IllegalArgumentException("Illegal arguments");
}