Java Code Examples for org.antlr.v4.runtime.tree.TerminalNode#getText()

The following examples show how to use org.antlr.v4.runtime.tree.TerminalNode#getText() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ArgumentContextUtils.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
final @NonNull String stringFromStringContext(final ArgumentContext context, final StatementSourceReference ref) {
    // Get first child, which we fully expect to exist and be a lexer token
    final ParseTree firstChild = context.getChild(0);
    verify(firstChild instanceof TerminalNode, "Unexpected shape of %s", context);
    final TerminalNode firstNode = (TerminalNode) firstChild;
    final int firstType = firstNode.getSymbol().getType();
    switch (firstType) {
        case YangStatementParser.IDENTIFIER:
            // Simple case, there is a simple string, which cannot contain anything that we would need to process.
            return firstNode.getText();
        case YangStatementParser.STRING:
            // Complex case, defer to a separate method
            return concatStrings(context, ref);
        default:
            throw new VerifyException("Unexpected first symbol in " + context);
    }
}
 
Example 2
Source File: DefaultDataQLVisitor.java    From hasor with Apache License 2.0 6 votes vote down vote up
private SpecialType specialType(TerminalNode rou, SpecialType defaultType) {
    if (rou == null) {
        return defaultType;
    }
    String rouType = rou.getText();
    if ("#".equals(rouType)) {
        return SpecialType.Special_A;
    }
    if ("$".equals(rouType)) {
        return SpecialType.Special_B;
    }
    if ("@".equals(rouType)) {
        return SpecialType.Special_C;
    }
    throw newParseException(rou.getSymbol(), "rouType '" + rouType + "' is not supported");
}
 
Example 3
Source File: ExpressionVisitor.java    From ureport with Apache License 2.0 6 votes vote down vote up
@Override
public BaseExpression visitSimpleJoin(SimpleJoinContext ctx) {
	List<BaseExpression> expressions=new ArrayList<BaseExpression>();
	List<Operator> operators=new ArrayList<Operator>();
	List<UnitContext> unitContexts=ctx.unit();
	List<TerminalNode> operatorNodes=ctx.Operator();
	for(int i=0;i<unitContexts.size();i++){
		UnitContext unitContext=unitContexts.get(i);
		BaseExpression expr=buildExpression(unitContext);
		expressions.add(expr);
		if(i>0){
			TerminalNode operatorNode=operatorNodes.get(i-1);
			String op=operatorNode.getText();
			operators.add(Operator.parse(op));
		}
	}
	if(operators.size()==0 && expressions.size()==1){
		return expressions.get(0);
	}
	JoinExpression expression=new JoinExpression(operators,expressions);
	expression.setExpr(ctx.getText());
	return expression;
}
 
Example 4
Source File: Parse.java    From rockscript with Apache License 2.0 5 votes vote down vote up
private SingleExpression parseLiteral(LiteralContext literalContext) {
  if (literalContext.StringLiteral()!=null) {
    return parseStringLiteral(literalContext);
  }

  TerminalNode nullLiteral = literalContext.NullLiteral();
  if (nullLiteral!=null) {
    return new Literal(createNextScriptElementId(), createLocation(literalContext));
  }

  NumericLiteralContext numericLiteralContext = literalContext.numericLiteral();
  if (numericLiteralContext!=null) {
    if (numericLiteralContext.DecimalLiteral()!=null) {
      return parseDecimalNumberLiteral(numericLiteralContext);
    }
    addErrorUnsupportedElement(numericLiteralContext, "number");
    return null;
  }

  TerminalNode regularExpressionLiteral = literalContext.RegularExpressionLiteral();
  if (regularExpressionLiteral!=null) {
    String regexText = regularExpressionLiteral.getText();
    addErrorUnsupportedElement(regularExpressionLiteral, "regex");
    return null;
  }

  TerminalNode booleanLiteral = literalContext.BooleanLiteral();
  if (booleanLiteral != null) {
    if ("true".equals(booleanLiteral.getText())) {
      return parseBooleanLiteral(literalContext, true);
    } else if ("false".equals(booleanLiteral.getText())) {
      return parseBooleanLiteral(literalContext, false);
    }
  }
  return null;
}
 
Example 5
Source File: QuickstartCqlVisitor.java    From clinical_quality_language with Apache License 2.0 5 votes vote down vote up
private String unquote(TerminalNode node) {
    if (node == null) return null;

    String text = node.getText();
    int tokenType = node.getSymbol().getType();
    if (cqlLexer.STRING == tokenType || cqlLexer.VALUESET == tokenType) {
        // chop off leading and trailing ' or "
        text = text.substring(1, text.length() - 1);
    }

    return text;
}
 
Example 6
Source File: ApplyGroupsApplicator.java    From batfish with Apache License 2.0 5 votes vote down vote up
@Override
public void visitTerminal(TerminalNode node) {
  if (_enablePathRecording) {
    String text = node.getText();
    int line = node.getSymbol().getLine();
    if (node.getSymbol().getType() == FlatJuniperLexer.WILDCARD) {
      _currentPath.addWildcardNode(text, line);
    } else {
      _currentPath.addNode(text, line);
    }
  }
}
 
Example 7
Source File: JavaFilePage.java    From jd-gui with GNU General Public License v3.0 5 votes vote down vote up
public void enterClassBodyDeclaration(JavaParser.ClassBodyDeclarationContext ctx) {
    if (ctx.getChildCount() == 2) {
        ParseTree first = ctx.getChild(0);

        if (first instanceof TerminalNode) {
            TerminalNode f = (TerminalNode)first;

            if (f.getSymbol().getType() == JavaParser.STATIC) {
                String name = f.getText();
                int position = f.getSymbol().getStartIndex();
                declarations.put(currentInternalTypeName + "-<clinit>-()V", new TypePage.DeclarationData(position, 6, currentInternalTypeName, name, "()V"));
            }
        }
    }
}
 
Example 8
Source File: JsonPathCompiler.java    From JsonSurfer with MIT License 5 votes vote down vote up
@Override
public Void visitChildrenNode(JsonPathParser.ChildrenNodeContext ctx) {
    int i = 0;
    String[] strings = new String[ctx.QUOTED_STRING().size()];
    for (TerminalNode node : ctx.QUOTED_STRING()) {
        String quotedString = node.getText();
        strings[i++] = removeQuote(quotedString);
    }
    currentPathBuilder().children(strings);
    return super.visitChildren(ctx);
}
 
Example 9
Source File: JavaFileIndexerProvider.java    From jd-gui with GNU General Public License v3.0 5 votes vote down vote up
public void enterMethodDeclaration(JavaParser.MethodDeclarationContext ctx) {
    TerminalNode identifier = ctx.Identifier();

    if (identifier != null) {
        String name = identifier.getText();
        methodDeclarationSet.add(name);
    }
}
 
Example 10
Source File: Parser.java    From graql with GNU Affero General Public License v3.0 5 votes vote down vote up
private boolean getBoolean(TerminalNode bool) {
    Graql.Token.Literal literal = Graql.Token.Literal.of(bool.getText());

    if (literal != null && literal.equals(Graql.Token.Literal.TRUE)) {
        return true;

    } else if (literal != null && literal.equals(Graql.Token.Literal.FALSE)) {
        return false;

    } else {
        throw new IllegalArgumentException("Unrecognised Boolean token: " + bool.getText());
    }
}
 
Example 11
Source File: Parse.java    From rockscript with Apache License 2.0 5 votes vote down vote up
private String parsePropertyName(PropertyNameContext propertyNameContext) {
  IdentifierNameContext identifierNameContext = propertyNameContext.identifierName();
  if (identifierNameContext!=null) {
    return identifierNameContext.getText();
  }
  TerminalNode stringLiteralNode = propertyNameContext.StringLiteral();
  if (stringLiteralNode!=null) {
    String propertyNameWithQuotes = stringLiteralNode.getText();
    String propertyNameWithoutQuotes = removeQuotesFromString(stringLiteralNode, propertyNameWithQuotes);
    return propertyNameWithoutQuotes;
  }
  addErrorUnsupportedElement(propertyNameContext, "propertyName");
  return null;
}
 
Example 12
Source File: WildcardPruner.java    From batfish with Apache License 2.0 5 votes vote down vote up
@Override
public void visitTerminal(TerminalNode node) {
  if (_enablePathRecording) {
    String text = node.getText();
    int line = node.getSymbol().getLine();
    if (node.getSymbol().getType() == FlatJuniperLexer.WILDCARD_ARTIFACT) {
      _currentPath.addWildcardNode(text, line);
    } else {
      _currentPath.addNode(text, line);
    }
  }
}
 
Example 13
Source File: JavaFileIndexerProvider.java    From jd-gui with GNU General Public License v3.0 5 votes vote down vote up
public void enterInterfaceMethodDeclaration(JavaParser.InterfaceMethodDeclarationContext ctx) {
    TerminalNode identifier = ctx.Identifier();

    if (identifier != null) {
        String name = identifier.getText();
        methodDeclarationSet.add(name);
    }
}
 
Example 14
Source File: AntlrXPathParser.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
private YangExpr parseTerminal(final TerminalNode term) {
    final String text = term.getText();
    switch (term.getSymbol().getType()) {
        case xpathParser.Literal:
            // We have to strip quotes
            haveLiteral = true;
            return YangLiteralExpr.of(text.substring(1, text.length() - 1));
        case xpathParser.Number:
            return mathSupport.createNumber(text);
        default:
            throw illegalShape(term);
    }
}
 
Example 15
Source File: TerminalTransformer.java    From smartcheck with GNU General Public License v3.0 5 votes vote down vote up
/**
 *
 * @param terminalNode terminal node
 * @return stirng
 */
@Override
public final String apply(final TerminalNode terminalNode) {

    String text = terminalNode.getText();

    boolean trim = Stream.of("\"", "'")
            .anyMatch(c -> text.startsWith(c) && text.endsWith(c));
    if (trim) {
        return text.substring(1, text.length() - 1);
    }

    return text;
}
 
Example 16
Source File: CqlPreprocessorVisitor.java    From clinical_quality_language with Apache License 2.0 5 votes vote down vote up
@Override
public Object visitTerminal(@NotNull TerminalNode node) {
    String text = node.getText();
    int tokenType = node.getSymbol().getType();
    if (cqlLexer.STRING == tokenType || cqlLexer.QUOTEDIDENTIFIER == tokenType) {
        // chop off leading and trailing ' or "
        text = text.substring(1, text.length() - 1);
    }

    return text;
}
 
Example 17
Source File: ValueNode.java    From gyro with Apache License 2.0 4 votes vote down vote up
public ValueNode(TerminalNode context) {
    super(context.getSymbol(), context.getSymbol());

    this.value = context.getText();
}
 
Example 18
Source File: RuleFilterVisitorImpl.java    From SkaETL with Apache License 2.0 4 votes vote down vote up
@Override
public String visitTerminal(TerminalNode node) {
    return node.getText();
}
 
Example 19
Source File: BuildVisitor.java    From Arend with Apache License 2.0 4 votes vote down vote up
private String getInfixText(TerminalNode node) {
  String name = node.getText();
  return name.substring(1, name.length() - 1);
}
 
Example 20
Source File: CypherCstToAstVisitor.java    From vertexium with Apache License 2.0 4 votes vote down vote up
private CypherString visitOC_EscapedSymbolicName(TerminalNode escapedSymbolicName) {
    String text = escapedSymbolicName.getText();
    text = text.substring(1, text.length() - 1);
    return new CypherString(text);
}