List of usage examples for org.antlr.v4.runtime Token getText
String getText();
From source file:com.oracle.truffle.llvm.parser.LlvmNodeFactory.java
License:Open Source License
/** * Returns an {@link LlvmWritePropertyNode} for the given parameters. * * @param receiverNode The receiver object of the property assignment * @param nameToken The name of the property being assigned * @param valueNode The value to be assigned * @return An LlvmExpressionNode for the given parameters. *///w ww .jav a 2 s . co m public LlvmExpressionNode createWriteProperty(LlvmExpressionNode receiverNode, Token nameToken, LlvmExpressionNode valueNode) { final int start = receiverNode.getSourceSection().getCharIndex(); final int length = valueNode.getSourceSection().getCharEndIndex() - start; SourceSection src = source.createSection("=", start, length); return LlvmWritePropertyNode.create(src, receiverNode, nameToken.getText(), valueNode); }
From source file:com.oracle.truffle.llvm.parser.LlvmNodeFactory.java
License:Open Source License
/** * Creates source description of a single token. *///w w w . j a va2 s .c om private SourceSection srcFromToken(Token token) { return source.createSection(token.getText(), token.getStartIndex(), token.getText().length()); }
From source file:com.oracle.truffle.sl.parser.SLNodeFactory.java
License:Open Source License
public void startFunction(Token nameToken, Token bodyStartToken) { assert functionStartPos == 0; assert functionName == null; assert functionBodyStartPos == 0; assert parameterCount == 0; assert frameDescriptor == null; assert lexicalScope == null; functionStartPos = nameToken.getStartIndex(); functionName = nameToken.getText(); functionBodyStartPos = bodyStartToken.getStartIndex(); frameDescriptor = new FrameDescriptor(); methodNodes = new ArrayList<>(); startBlock();/* w ww . j a v a 2s . c om*/ }
From source file:com.oracle.truffle.sl.parser.SLNodeFactory.java
License:Open Source License
/** * Returns an {@link SLReturnNode} for the given parameters. * * @param t The token containing the return node's info * @param valueNode The value of the return (null if not returning a value) * @return An SLReturnNode for the given parameters. *//* www.j ava 2 s. com*/ public SLStatementNode createReturn(Token t, SLExpressionNode valueNode) { final int start = t.getStartIndex(); final int length = valueNode == null ? t.getText().length() : valueNode.getSourceEndIndex() - start; final SLReturnNode returnNode = new SLReturnNode(valueNode); returnNode.setSourceSection(start, length); return returnNode; }
From source file:com.oracle.truffle.sl.parser.SLNodeFactory.java
License:Open Source License
/** * Returns the corresponding subclass of {@link SLExpressionNode} for binary expressions. </br> * These nodes are currently not instrumented. * * @param opToken The operator of the binary expression * @param leftNode The left node of the expression * @param rightNode The right node of the expression * @return A subclass of SLExpressionNode using the given parameters based on the given opToken. * null if either leftNode or rightNode is null. *///from ww w . j av a 2s . c o m public SLExpressionNode createBinary(Token opToken, SLExpressionNode leftNode, SLExpressionNode rightNode) { if (leftNode == null || rightNode == null) { return null; } final SLExpressionNode leftUnboxed = SLUnboxNodeGen.create(leftNode); final SLExpressionNode rightUnboxed = SLUnboxNodeGen.create(rightNode); final SLExpressionNode result; switch (opToken.getText()) { case "+": result = SLAddNodeGen.create(leftUnboxed, rightUnboxed); break; case "*": result = SLMulNodeGen.create(leftUnboxed, rightUnboxed); break; case "/": result = SLDivNodeGen.create(leftUnboxed, rightUnboxed); break; case "-": result = SLSubNodeGen.create(leftUnboxed, rightUnboxed); break; case "<": result = SLLessThanNodeGen.create(leftUnboxed, rightUnboxed); break; case "<=": result = SLLessOrEqualNodeGen.create(leftUnboxed, rightUnboxed); break; case ">": result = SLLogicalNotNodeGen.create(SLLessOrEqualNodeGen.create(leftUnboxed, rightUnboxed)); break; case ">=": result = SLLogicalNotNodeGen.create(SLLessThanNodeGen.create(leftUnboxed, rightUnboxed)); break; case "==": result = SLEqualNodeGen.create(leftUnboxed, rightUnboxed); break; case "!=": result = SLLogicalNotNodeGen.create(SLEqualNodeGen.create(leftUnboxed, rightUnboxed)); break; case "&&": result = new SLLogicalAndNode(leftUnboxed, rightUnboxed); break; case "||": result = new SLLogicalOrNode(leftUnboxed, rightUnboxed); break; default: throw new RuntimeException("unexpected operation: " + opToken.getText()); } int start = leftNode.getSourceCharIndex(); int length = rightNode.getSourceEndIndex() - start; result.setSourceSection(start, length); result.addExpressionTag(); return result; }
From source file:com.oracle.truffle.sl.parser.SLNodeFactory.java
License:Open Source License
/** * Returns an {@link SLInvokeNode} for the given parameters. * * @param functionNode The function being called * @param parameterNodes The parameters of the function call * @param finalToken A token used to determine the end of the sourceSelection for this call * @return An SLInvokeNode for the given parameters. null if functionNode or any of the * parameterNodes are null./*ww w.j a v a 2 s .c o m*/ */ public SLExpressionNode createCall(SLExpressionNode functionNode, List<SLExpressionNode> parameterNodes, Token finalToken) { if (functionNode == null || containsNull(parameterNodes)) { return null; } final SLExpressionNode result = new SLInvokeNode(functionNode, parameterNodes.toArray(new SLExpressionNode[parameterNodes.size()])); final int startPos = functionNode.getSourceCharIndex(); final int endPos = finalToken.getStartIndex() + finalToken.getText().length(); result.setSourceSection(startPos, endPos - startPos); result.addExpressionTag(); return result; }
From source file:com.oracle.truffle.sl.parser.SLNodeFactory.java
License:Open Source License
public SLExpressionNode createStringLiteral(Token literalToken, boolean removeQuotes) { /* Remove the trailing and ending " */ String literal = literalToken.getText(); if (removeQuotes) { assert literal.length() >= 2 && literal.startsWith("\"") && literal.endsWith("\""); literal = literal.substring(1, literal.length() - 1); }// w ww .j a v a 2 s .c o m final SLStringLiteralNode result = new SLStringLiteralNode(literal.intern()); srcFromToken(result, literalToken); result.addExpressionTag(); return result; }
From source file:com.oracle.truffle.sl.parser.SLNodeFactory.java
License:Open Source License
public SLExpressionNode createNumericLiteral(Token literalToken) { SLExpressionNode result;/*from w w w . jav a 2s .c om*/ try { /* Try if the literal is small enough to fit into a long value. */ result = new SLLongLiteralNode(Long.parseLong(literalToken.getText())); } catch (NumberFormatException ex) { /* Overflow of long value, so fall back to BigInteger. */ result = new SLBigIntegerLiteralNode(new BigInteger(literalToken.getText())); } srcFromToken(result, literalToken); result.addExpressionTag(); return result; }
From source file:com.oracle.truffle.sl.parser.SLNodeFactory.java
License:Open Source License
/** * Creates source description of a single token. */// w w w . j ava2 s . co m private static void srcFromToken(SLStatementNode node, Token token) { node.setSourceSection(token.getStartIndex(), token.getText().length()); }
From source file:com.sample.JavaErrorStrategy.java
License:BSD License
protected String getSymbolText(@NotNull Token symbol) { return symbol.getText(); }