List of usage examples for org.antlr.v4.runtime Token getText
String getText();
From source file:bam.web.dtc.compiler.CodeModelGenerator.java
@Override public void enterEnum_(TypeScriptParser.Enum_Context ctx) { Exceptions.uncheck(() -> {/*from ww w.j a v a2 s.c om*/ JDefinedClass enum_ = withDoc(pkg()._enum(ctx.name.getText())); for (Token v : ctx.values) { enum_.enumConstant(v.getText()); } }); }
From source file:br.edu.ifrn.potigol.editor.PrettyListener.java
License:Open Source License
@Override public void exitInst(InstContext ctx) { String s = getValue(ctx.getChild(0)); setValue(ctx, s);// w w w. j av a2 s .c o m int a = ctx.getStart().getTokenIndex(); List<Token> tt = tokens.getHiddenTokensToLeft(a, 1); List<Token> ttnl = tokens.getHiddenTokensToLeft(a, 2); String ttt = ""; if (ttnl != null && ttnl.size() > 1) ttt = "\n\n"; if (tt != null) { for (Token t : tt) { ttt = ttt + t.getText(); // System.out.println(t.getType() + " - " + t.getChannel()); } // System.out.println(ttt); } setValue(ctx, ttt + getValue(ctx)); }
From source file:br.edu.ifrn.potigol.editor.PrinterListener.java
License:Open Source License
@Override public void exitInst(InstContext ctx) { String s = getValue(ctx.getChild(0)); setValue(ctx, s);//w w w . ja va 2 s.co m int a = ctx.getStart().getTokenIndex(); List<Token> tt = tokens.getHiddenTokensToLeft(a, 1); List<Token> ttnl = tokens.getHiddenTokensToLeft(a, 2); String ttt = "<span class=\"comentario\">"; if (ttnl != null && ttnl.size() > 1) ttt = "\n\n"; if (tt != null) { for (Token t : tt) { ttt = ttt + t.getText(); // System.out.println(t.getType() + " - " + t.getChannel()); } // System.out.println(ttt); } ttt = ttt + "</span>"; setValue(ctx, ttt + getValue(ctx)); }
From source file:cfml.parsing.cfscript.CFBinaryExpression.java
License:Open Source License
public CFBinaryExpression(Token t, CFExpression left, CFExpression right) { super(t);/* w w w. j a v a 2 s . c o m*/ _kind = t.getType(); operatorImage = t.getText(); if (_kind == CFSCRIPTLexer.ANDOPERATOR) { _kind = CFSCRIPTLexer.AND; } else if (_kind == CFSCRIPTLexer.OROPERATOR) { _kind = CFSCRIPTLexer.OR; } else if (_kind == CFSCRIPTLexer.MODOPERATOR) { _kind = CFSCRIPTLexer.MOD; } _left = left; _right = right; }
From source file:cfml.parsing.cfscript.CFIdentifier.java
License:Open Source License
public CFIdentifier(Token _t) { super(_t); name = _t.getText(); token = _t; }
From source file:cfml.parsing.cfscript.CFLiteral.java
License:Open Source License
public CFLiteral(Token _t) { super(_t);/*from w ww . j a va 2 s . c om*/ kind = _t.getType(); image = _t.getText(); switch (kind) { case CFSCRIPTLexer.FLOATING_POINT_LITERAL: case CFSCRIPTLexer.INTEGER_LITERAL: val = _t.getText(); break; case CFSCRIPTLexer.STRING_LITERAL: // create a String, stripping off the surrounding quotes and // replacing any escaped quotes with a single quote String quote = _t.getText().substring(0, 1); String str = _t.getText().substring(1, _t.getText().length() - 1); str = str.replaceAll(quote + quote, quote); image = str; val = str; break; case CFSCRIPTLexer.BOOLEAN_LITERAL: val = _t.getText(); break; // CFML doesn't do nulls, to my knowledge // case CFSCRIPTLexer.NULL: // val = ""; // break; default: break; } }
From source file:ch.raffael.contracts.processor.cel.parser.Literals.java
License:Apache License
@NeedsWork(description = "This can't handle Integer.MIN_VALUE/Long.MIN_VALUE, because the AST is NEG->IntLiteral (positive)") @NotNull//from w w w . java2 s. c om static AstNode integer(Token tok) { String strValue = tok.getText(); Literal.Kind kind = null; if (Character.toUpperCase(strValue.charAt(strValue.length() - 1)) == 'L') { strValue = strValue.substring(0, strValue.length() - 1); try { return Nodes.literal(tok, Literal.Kind.LONG, Long.decode(strValue)); } catch (NumberFormatException e) { // We know that it was a syntactically correct int literal, the lexer made // that sure. Therefore, we also know, what this exception means: The value // is out of range return error(tok, "Long literal out of range: " + tok.getText()); } } else { try { return Nodes.literal(tok, Literal.Kind.INT, Integer.decode(strValue)); } catch (NumberFormatException e) { // We know that it was a syntactically correct int literal, the lexer made // that sure. Therefore, we also know, what this exception means: The value // is out of range return error(tok, "Integer literal out of range: " + tok.getText()); } } }
From source file:ch.raffael.contracts.processor.cel.parser.Literals.java
License:Apache License
static AstNode floatingPoint(Token tok) { String strValue = tok.getText(); Literal.Kind kind = Literal.Kind.DOUBLE; if (Character.toUpperCase(strValue.charAt(strValue.length() - 1)) == 'F') { kind = Literal.Kind.FLOAT;//from w w w. j a v a2 s. c o m strValue = strValue.substring(0, strValue.length() - 1); } else if (Character.toUpperCase(strValue.charAt(strValue.length() - 1)) == 'D') { strValue = strValue.substring(0, strValue.length() - 1); } if (kind == Literal.Kind.DOUBLE) { return Nodes.literal(tok, Literal.Kind.DOUBLE, Double.valueOf(strValue)); } else { return Nodes.literal(tok, Literal.Kind.FLOAT, Float.valueOf(strValue)); } }
From source file:ch.raffael.contracts.processor.cel.parser.Literals.java
License:Apache License
static AstNode string(Token tok, Literal.Kind kind) { String strValue = tok.getText(); strValue = strValue.substring(1, strValue.length() - (kind == Literal.Kind.CHAR ? 2 : 1)); StringBuilder buf = new StringBuilder(strValue.length()); for (int i = 0; i < strValue.length(); i++) { if (strValue.charAt(i) == '\\') { i++;/* w ww .java 2 s .c o m*/ int unescaped; switch (strValue.charAt(i)) { case '\\': unescaped = '\\'; break; case 'n': unescaped = '\n'; break; case 'r': unescaped = '\r'; break; case 't': unescaped = '\t'; break; case 'b': unescaped = '\b'; break; case 'f': unescaped = '\f'; break; case '\'': unescaped = '\''; break; case '"': unescaped = '"'; break; case 'u': unescaped = 0; for (int j = 0; j < 4; j++) { unescaped = (unescaped << 4) | hex(strValue.charAt(i + j + 1)); } i += 4; break; default: // octal unescaped = 0; for (int j = 0; j < 3 && i < strValue.length(); j++, i++) { int digit = strValue.charAt(i) - '0'; if (digit < 0 || digit > 7) { i--; break; } unescaped = (unescaped << 3) | digit; if (j == 1 && unescaped >= 32) { // must have been \4xx => only two digits break; } } } buf.append((char) unescaped); } else { buf.append(strValue.charAt(i)); } } if (kind == Literal.Kind.CHAR) { assert buf.length() == 1; return Nodes.literal(tok, Literal.Kind.CHAR, buf.charAt(0)); } else { return Nodes.literal(tok, Literal.Kind.STRING, buf.toString()); } }
From source file:codesniffer.java8.adapter.AdapterUtil.java
License:Open Source License
/** * If there are no statements within a block, we need a special method to grab any comments that * might exist between braces./* w ww . ja v a2 s . c om*/ * * @param node * @param parserRuleContext * @param adapterParameters */ public static void setInternalComments(Node node, ParserRuleContext parserRuleContext, AdapterParameters adapterParameters) { BufferedTokenStream tokens = adapterParameters.getTokens(); if (node == null || parserRuleContext == null || tokens == null) { throw new IllegalArgumentException("Parameters must not be null"); } Token startToken = parserRuleContext.getStart(); Token stopToken = parserRuleContext.getStop(); List<Token> commentTokens; ArrayList<Comment> internalCommentList = new ArrayList<>(); // Checking to the right of the start token will check inside the statement commentTokens = tokens.getHiddenTokensToRight(startToken.getTokenIndex(), Java8Lexer.COMMENTS); if (commentTokens != null) { internalCommentList.ensureCapacity(commentTokens.size()); for (Token commentToken : commentTokens) { // Skip already claimed comments (prevents comment repeats) if (adapterParameters.isCommentTokenClaimed(commentToken.getTokenIndex())) { continue; } else { // Claim it adapterParameters.claimCommentToken(commentToken.getTokenIndex()); } if (commentToken.getText().startsWith("/**")) { DocumentComment javadocComment = new DocumentComment(commentToken.getText()); internalCommentList.add(javadocComment); } else if (commentToken.getText().startsWith("/*")) { BlockComment blockComment = new BlockComment(commentToken.getText()); internalCommentList.add(blockComment); } else if (commentToken.getText().startsWith("//")) { LineComment lineComment = new LineComment(commentToken.getText()); internalCommentList.add(lineComment); } } } if (internalCommentList.size() > 0) { if (node.getOrphanComments() != null) { node.getOrphanComments().addAll(internalCommentList); } else { node.setOrphanComments(internalCommentList); } } // if (internalCommentList.size() > 0) { // if (node.getInternalComments() != null) { // node.getInternalComments().addAll(internalCommentList); // } else { // node.setInternalComments(internalCommentList); // } // } }