List of usage examples for org.antlr.v4.runtime Token getText
String getText();
From source file:plugins.quorum.Libraries.Language.Compile.JavaToQuorumListener.java
@Override public void enterGeneric_declaration(QuorumParser.Generic_declarationContext ctx) { quorum.Libraries.Language.Compile.Context.GenericDeclarationContext context = new quorum.Libraries.Language.Compile.Context.GenericDeclarationContext(); List<Token> ids = ctx.ids; Iterator<Token> tokens = ids.iterator(); while (tokens.hasNext()) { Token next = tokens.next(); String value = next.getText(); Text text = new Text(); text.value = value;/* w ww .j a v a 2s .com*/ context.tokens.Add(text); } setLocation(ctx, context); listener.EnterGenericDeclaration(context); }
From source file:plugins.quorum.Libraries.Language.Compile.JavaToQuorumListener.java
@Override public void exitGeneric_declaration(QuorumParser.Generic_declarationContext ctx) { quorum.Libraries.Language.Compile.Context.GenericDeclarationContext context = new quorum.Libraries.Language.Compile.Context.GenericDeclarationContext(); List<Token> ids = ctx.ids; Iterator<Token> tokens = ids.iterator(); while (tokens.hasNext()) { Token next = tokens.next(); String value = next.getText(); Text text = new Text(); text.value = value;// w w w . j a v a 2s . c o m context.tokens.Add(text); } setLocation(ctx, context); listener.ExitGenericDeclaration(context); }
From source file:sdd.vtlParser.components.AST.java
License:Open Source License
@Override public String toString() { StringBuilder builder = new StringBuilder(); AST ast = this; List<AST> firstStack = new ArrayList<>(); firstStack.add(ast);/*from w w w .ja v a 2s .c om*/ List<List<AST>> childListStack = new ArrayList<>(); childListStack.add(firstStack); while (!childListStack.isEmpty()) { List<AST> childStack = childListStack.get(childListStack.size() - 1); if (childStack.isEmpty()) { childListStack.remove(childListStack.size() - 1); } else { ast = childStack.remove(0); String caption; if (ast.payload instanceof Token) { Token token = (Token) ast.payload; caption = String.format("TOKEN[type: %s, text: '%s']", token.getType(), token.getText().replace("\n", "\\n")); } else { caption = String.valueOf(ast.payload); } String indent = ""; for (int i = 0; i < childListStack.size() - 1; i++) { indent += (childListStack.get(i).size() > 0) ? "| " : " "; } builder.append(indent).append(childStack.isEmpty() ? "'- " : "|- ").append(caption).append("\n"); if (ast.children.size() > 0) { List<AST> children = new ArrayList<>(); for (int i = 0; i < ast.children.size(); i++) { children.add(ast.children.get(i)); } childListStack.add(children); } } } return builder.toString(); }
From source file:sdd.vtlParser.components.AST.java
License:Open Source License
public String toSimpleString() { StringBuilder builder = new StringBuilder(); AST ast = this; List<AST> firstStack = new ArrayList<>(); firstStack.add(ast);//w w w . j ava 2 s. c o m List<List<AST>> childListStack = new ArrayList<>(); childListStack.add(firstStack); while (!childListStack.isEmpty()) { List<AST> childStack = childListStack.get(childListStack.size() - 1); if (childStack.isEmpty()) { childListStack.remove(childListStack.size() - 1); } else { ast = childStack.remove(0); String caption; if (ast.payload instanceof Token) { Token token = (Token) ast.payload; // caption = String.format("TOKEN[type: %s, text: '%s']", // token.getType(), token.getText().replace("\n", "\\n")); caption = "'" + token.getText().replace("\n", "\\n") + "'"; } else { caption = "[" + String.valueOf(ast.payload) + "]"; } String indent = ""; for (int i = 0; i < childListStack.size() - 1; i++) { indent += (childListStack.get(i).size() > 0) ? "| " : " "; } builder.append(indent).append(childStack.isEmpty() ? "'- " : "|- ").append(caption).append("\n"); if (ast.children.size() > 0) { List<AST> children = new ArrayList<>(); for (int i = 0; i < ast.children.size(); i++) { children.add(ast.children.get(i)); } childListStack.add(children); } } } return builder.toString(); }
From source file:tool.GeneratorVisitor.java
License:Open Source License
@Override public Void visitUnaryExpr(UnaryExprContext ctx) { if (ctx.single != null) { super.visitAtomExpr(ctx.single); } else {/*from www . ja v a2 s . c o m*/ UnaryExpression unaryExpr = null; // reverse visiting order just for the initialization super.visitAtomExpr(ctx.arg); Expression expr = expressionHolder; expressionHolder = null; unaryExpr = new UnaryExpression(expr); for (Token op : ctx.ops) { String opString = op.getText(); UnaryOperator operator = new UnaryOperator(UnaryOperatorType.findBySsaForm(opString)); unaryExpr.addOperator(operator); } expressionHolder = unaryExpr; } return null; }
From source file:us.ihmc.idl.generator.IDLGenerator.java
License:Apache License
private static void printToken(CommonTokenStream tokens, int index, Token token) { if (token.getType() != IDLParser.WS) { String out = ""; out += " Index: " + token.getTokenIndex(); out += " Start: " + token.getStartIndex(); out += " Stop: " + token.getStopIndex(); out += " Channel: " + token.getChannel(); out += " Type: " + token.getType(); // out += " Hidden: "; // List<Token> hiddenTokensToLeft = tokens.getHiddenTokensToLeft(index); // for (int i = 0; hiddenTokensToLeft != null && i < hiddenTokensToLeft.size(); i++) // { // if (hiddenTokensToLeft.get(i).getType() != IDLParser.WS) // { // out += "\n\t" + i + ":"; // out += "\n\tChannel: " + hiddenTokensToLeft.get(i).getChannel() + " Type: " + hiddenTokensToLeft.get(i).getType(); // out += hiddenTokensToLeft.get(i).getText().replaceAll("\\s", ""); // } // } out += " " + token.getText().replaceAll("\\s", ""); System.out.println(out);//w w w .j a va 2 s . c o m } }
From source file:x10dt.ui.contentProposer.X10ContentProposer.java
License:Open Source License
private String computePrefixOfToken(Token tokenToComplete, int offset, ParseController pc) { String prefix = ""; if (tokenToComplete.getType() == X10Parser.IDENTIFIER || /*tokenToComplete.getType() == X10Parser.ErrorId ||*/ pc.isKeyword(tokenToComplete.getType())) { if (offset >= tokenToComplete.getStartIndex() && offset <= tokenToComplete.getStopIndex() + 1) { prefix = tokenToComplete.getText().toString().substring(0, offset - tokenToComplete.getStartIndex()); }//from w ww .j a v a2 s . com } return prefix; }
From source file:x10dt.ui.parser.ParseController.java
License:Open Source License
private IToken getIToken(final Token token) { IToken ret = new IToken() { public int getAdjunctIndex() { // TODO Auto-generated method stub return 0; }/*from w w w .j av a 2 s. com*/ public int getColumn() { return token.getCharPositionInLine(); } public int getEndColumn() { return token.getCharPositionInLine() + token.getStopIndex() - token.getStartIndex(); } public int getEndLine() { return token.getLine(); } public int getEndOffset() { return token.getStopIndex(); } public IToken[] getFollowingAdjuncts() { // TODO Auto-generated method stub return null; } public ILexStream getILexStream() { // TODO Auto-generated method stub return null; } public IPrsStream getIPrsStream() { // TODO Auto-generated method stub return null; } public int getKind() { return token.getType(); } public ILexStream getLexStream() { // TODO Auto-generated method stub return null; } public int getLine() { return token.getLine(); } public IToken[] getPrecedingAdjuncts() { // TODO Auto-generated method stub return null; } public IPrsStream getPrsStream() { // TODO Auto-generated method stub return null; } public int getStartOffset() { return token.getStartIndex(); } public int getTokenIndex() { return token.getTokenIndex(); } public String getValue(char[] arg0) { return token.getText(); } public void setAdjunctIndex(int arg0) { // TODO Auto-generated method stub } public void setEndOffset(int arg0) { } public void setKind(int arg0) { // TODO Auto-generated method stub } public void setStartOffset(int arg0) { // TODO Auto-generated method stub } public void setTokenIndex(int arg0) { // TODO Auto-generated method stub } }; return ret; }