本文整理汇总了Java中org.antlr.v4.runtime.tree.ParseTree.getText方法的典型用法代码示例。如果您正苦于以下问题:Java ParseTree.getText方法的具体用法?Java ParseTree.getText怎么用?Java ParseTree.getText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.antlr.v4.runtime.tree.ParseTree
的用法示例。
在下文中一共展示了ParseTree.getText方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSetItemOp
import org.antlr.v4.runtime.tree.ParseTree; //导入方法依赖的package包/类
private CypherSetItem.Op getSetItemOp(CypherParser.SetItemContext ctx) {
for (ParseTree child : ctx.children) {
if (child instanceof TerminalNode) {
String text = child.getText();
if (text.equals("+=")) {
return CypherSetItem.Op.PLUS_EQUAL;
} else if (text.equals("=")) {
return CypherSetItem.Op.EQUAL;
}
}
}
throw new MemgraphException("Could not find set item op: " + ctx.getText());
}
示例2: visitRangeLiteral
import org.antlr.v4.runtime.tree.ParseTree; //导入方法依赖的package包/类
@Override
public CypherRangeLiteral visitRangeLiteral(CypherParser.RangeLiteralContext ctx) {
Integer from = null;
Integer to = null;
boolean seenDotDot = false;
for (ParseTree child : ctx.children) {
if (child instanceof CypherParser.IntegerLiteralContext) {
int i = visitIntegerLiteral((CypherParser.IntegerLiteralContext) child).getIntValue();
if (seenDotDot) {
to = i;
} else {
from = i;
}
continue;
}
String text = child.getText();
if (text.equals("*")) {
continue;
}
if (text.equals("..")) {
seenDotDot = true;
continue;
}
}
if (!seenDotDot) {
to = from;
}
return new CypherRangeLiteral(from, to);
}
示例3: parseTreeToText
import org.antlr.v4.runtime.tree.ParseTree; //导入方法依赖的package包/类
protected String parseTreeToText(ParseTree ctx){
if(ctx instanceof TerminalNode) return ctx.getText();
StringBuilder sb = new StringBuilder();
int childCount = ctx.getChildCount();
for(int i=0;i<childCount;i++){
if(i>0) sb.append(" ");
sb.append(parseTreeToText(ctx.getChild(i)));
}
return sb.toString();
}
示例4: assignAlias
import org.antlr.v4.runtime.tree.ParseTree; //导入方法依赖的package包/类
private String assignAlias(String alias, ParserRuleContext node, Scope scope) {
if (alias == null) {
alias = "source";
}
if (node != null && node instanceof yqlplusParser.Alias_defContext) {
//alias_def : (AS? ID);
ParseTree idChild = node;
if (node.getChildCount() > 1) {
idChild = node.getChild(1);
}
alias = idChild.getText();
if (scope.isCursor(alias)) {
throw new ProgramCompileException(toLocation(scope, idChild), "Source alias '%s' is already used", alias);
}
scope.defineDataSource(toLocation(scope, idChild), alias, true);
return alias;
} else {
String candidate = alias;
int c = 0;
while (scope.isCursor(candidate)) {
candidate = alias + (++c);
}
scope.defineDataSource(null, candidate);
return alias;
}
}
示例5: decodeType
import org.antlr.v4.runtime.tree.ParseTree; //导入方法依赖的package包/类
private OperatorNode<TypeOperator> decodeType(Scope scope, TypenameContext type) {
TypeOperator op;
ParseTree typeNode = type.getChild(0);
switch (getParseTreeIndex(typeNode)) {
case yqlplusParser.TYPE_BOOLEAN:
op = TypeOperator.BOOLEAN;
break;
case yqlplusParser.TYPE_BYTE:
op = TypeOperator.BYTE;
break;
case yqlplusParser.TYPE_DOUBLE:
op = TypeOperator.DOUBLE;
break;
case yqlplusParser.TYPE_INT16:
op = TypeOperator.INT16;
break;
case yqlplusParser.TYPE_INT32:
op = TypeOperator.INT32;
break;
case yqlplusParser.TYPE_INT64:
op = TypeOperator.INT64;
break;
case yqlplusParser.TYPE_STRING:
op = TypeOperator.STRING;
break;
case yqlplusParser.TYPE_TIMESTAMP:
op = TypeOperator.TIMESTAMP;
break;
case yqlplusParser.RULE_arrayType:
return OperatorNode.create(toLocation(scope, typeNode), TypeOperator.ARRAY, decodeType(scope, ((ArrayTypeContext) typeNode).getChild(TypenameContext.class, 0)));
case yqlplusParser.RULE_mapType:
return OperatorNode.create(toLocation(scope, typeNode), TypeOperator.MAP, decodeType(scope, ((MapTypeContext) typeNode).getChild(TypenameContext.class, 0)));
default:
throw new ProgramCompileException("Unknown type " + typeNode.getText());
}
return OperatorNode.create(toLocation(scope, typeNode), op);
}
示例6: checkNode
import org.antlr.v4.runtime.tree.ParseTree; //导入方法依赖的package包/类
private static <T> T checkNode(ParseTree node, Class<T> clazz) {
if (node instanceof ErrorNode) {
throw new IndexRQLParseError(node.getText());
} else if (node instanceof TerminalNode) {
return null;
} else if (clazz.isInstance(node)) {
return (T) node;
}
return null;
}
示例7: assignAlias
import org.antlr.v4.runtime.tree.ParseTree; //导入方法依赖的package包/类
private String assignAlias(String alias, ParserRuleContext node, Scope scope) {
if (alias == null) {
alias = "source";
}
if (node != null && node instanceof yqlplusParser.Alias_defContext) {
//alias_def : (AS? ID);
ParseTree idChild = node;
if (node.getChildCount() > 1) {
idChild = node.getChild(1);
}
alias = idChild.getText();
if (scope.isCursor(alias)) {
throw new ProgramCompileException(toLocation(scope, idChild), "Source alias '%s' is already used", alias);
}
scope.defineDataSource(toLocation(scope, idChild), alias);
return alias;
} else {
String candidate = alias;
int c = 0;
while (scope.isCursor(candidate)) {
candidate = alias + (++c);
}
scope.defineDataSource(null, candidate);
return alias;
}
}
示例8: decodeType
import org.antlr.v4.runtime.tree.ParseTree; //导入方法依赖的package包/类
private OperatorNode<TypeOperator> decodeType(Scope scope, TypenameContext type) {
TypeOperator op;
ParseTree typeNode = type.getChild(0);
switch (getParseTreeIndex(typeNode)) {
case yqlplusParser.TYPE_BOOLEAN:
op = TypeOperator.BOOLEAN;
break;
case yqlplusParser.TYPE_BYTE:
op = TypeOperator.BYTE;
break;
case yqlplusParser.TYPE_DOUBLE:
op = TypeOperator.DOUBLE;
break;
case yqlplusParser.TYPE_INT16:
op = TypeOperator.INT16;
break;
case yqlplusParser.TYPE_INT32:
op = TypeOperator.INT32;
break;
case yqlplusParser.TYPE_INT64:
op = TypeOperator.INT64;
break;
case yqlplusParser.TYPE_STRING:
op = TypeOperator.STRING;
break;
case yqlplusParser.TYPE_TIMESTAMP:
op = TypeOperator.TIMESTAMP;
break;
case yqlplusParser.RULE_arrayType:
return OperatorNode.create(toLocation(scope, typeNode), TypeOperator.ARRAY, decodeType(scope, ((ArrayTypeContext)typeNode).getChild(TypenameContext.class, 0)));
case yqlplusParser.RULE_mapType:
return OperatorNode.create(toLocation(scope, typeNode), TypeOperator.MAP, decodeType(scope, ((MapTypeContext)typeNode).getChild(TypenameContext.class, 0)));
default:
throw new ProgramCompileException("Unknown type " + typeNode.getText());
}
return OperatorNode.create(toLocation(scope, typeNode), op);
}
示例9: isArrayParameter
import org.antlr.v4.runtime.tree.ParseTree; //导入方法依赖的package包/类
public boolean isArrayParameter(ParseTree nameNode) {
String name = nameNode.getText();
if (name.startsWith("@")) {
name = name.substring(1);
}
return name != null && arrayParameters.contains(name);
}
示例10: visit
import org.antlr.v4.runtime.tree.ParseTree; //导入方法依赖的package包/类
@Override
public Object visit(final ParseTree tree) {
final int n = tree.getChildCount();
for (int i = 0; i < n; i++) {
final ParseTree c = tree.getChild(i);
visit(c);
}
final ParsedNode parsedNode = new org.sonar.plugins.tsql.sensors.custom.nodes.ParsedNode(tree);
for (final CandidateRule rule : this.rules) {
final RuleImplementation ruleImplemention = rule.getRuleImplementation();
if (matcher.match(ruleImplemention, parsedNode)) {
final CandidateNode node = new CandidateNode(rule.getKey(), rule.getRule(), parsedNode);
if (ruleImplemention.getRuleMode() == RuleMode.GROUP) {
final String name = tree.getText();
groupedNodes.putIfAbsent(name, node);
} else {
singleNodes.add(node);
}
}
}
return null; // tree.accept(this);
}
示例11: getFirstTypeIdentifier
import org.antlr.v4.runtime.tree.ParseTree; //导入方法依赖的package包/类
private String getFirstTypeIdentifier(ParseTree tree) {
if (tree instanceof SwiftParser.STypeContext) {
return tree.getText();
}
int childCount = tree.getChildCount();
String result = "";
for (int i = 0; result.equals("") && i< childCount; i++){
result = getFirstTypeIdentifier(tree.getChild(i));
}
return result;
}
示例12: visitInterpolationExpr
import org.antlr.v4.runtime.tree.ParseTree; //导入方法依赖的package包/类
@Override
public Object visitInterpolationExpr(KalangParser.InterpolationExprContext ctx) {
List<ParseTree> children = ctx.children;
ExprNode[] exprs = new ExprNode[children.size()];
Token[] exprTokens = new Token[children.size()];
for(int i=0;i<exprs.length;i++){
ParseTree c = children.get(i);
if(c instanceof TerminalNode){
Token token = ((TerminalNode) c).getSymbol();
int t = token.getType();
String rawText = c.getText();
String text;
switch(t){
case KalangLexer.InterpolationPreffixString:
text = rawText.substring(1,rawText.length()-2);
break;
case KalangLexer.INTERPOLATION_STRING:
text = rawText;
break;
case KalangLexer.RBRACE:
case KalangLexer.INTERPOLATION_END:
case KalangLexer.INTERPOLATION_INTERUPT:
//TODO optimize empty string
text = "";
break;
default :
throw Exceptions.unexceptedValue(t);
}
exprs[i]=new ConstExpr(StringLiteralUtil.parse(text));
exprTokens[i] = token;
}else if(c instanceof ExpressionContext){
ExprNode expr = this.visitExpression((ExpressionContext) c);
if(expr==null) return null;
exprs[i]=expr;
exprTokens[i] = ((ExpressionContext) c).getStart();
}else{
throw Exceptions.unexceptedValue(c);
}
}
return this.concatExpressionsToStringExpr(exprs,exprTokens);
}