List of usage examples for org.antlr.v4.runtime.tree TerminalNodeImpl getText
@Override
public String getText()
From source file:com.puppycrawl.tools.checkstyle.checks.javadoc.ExpectedParseTreeGenerator.java
License:Open Source License
public String walk(ParseTree t, String parentObjectName) { final String className = t.getClass().getSimpleName(); String id = null;//from ww w . j ava 2 s . c om if (t instanceof TerminalNode) { final TerminalNodeImpl terminal = (TerminalNodeImpl) t; final int type = terminal.symbol.getType(); String tokenType = ""; if (type == -1) { tokenType = "EOF"; } else { tokenType = JavadocUtils.getTokenName(type); } String text = terminal.getText(); if ("\n".equals(text)) { text = "\\n"; } else if ("\t".equals(text)) { text = "\\t"; } else { text = text.replace("\"", "\\\""); } final int number = getVariableCounter(tokenType); id = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, tokenType.toLowerCase()) + number; System.out.println(" CommonToken " + id + " = new CommonToken(JavadocTokenTypes." + tokenType + ", \"" + text + "\");"); } else { int number = getVariableCounter(className); id = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, className) + number++; System.out.println( " " + className + " " + id + " = new " + className + "(" + parentObjectName + ", 0);"); final int n = t.getChildCount(); for (int i = 0; i < n; i++) { final String childId = walk(t.getChild(i), id); System.out.println(" " + id + ".addChild(" + childId + ");"); } } return id; }
From source file:parsetool.dataview.MyDataViewVisitor.java
@Override public Void visitValue(@NotNull DataViewParser.ValueContext ctx) { Value value = this.stack.peekCtx(Value.class); value.parse(ctx, this.stack.peekPrev()); ParseTree tree = TreeUtil.getChild(ctx, "parameter"); if (tree != null) { Parameter parameter = new Parameter(); value.setIs_parameter(true);//w w w . ja v a 2 s. c o m value.setParameter(parameter); this.stack.push(parameter); this.visit(tree); this.stack.pop(); return null; } tree = TreeUtil.getChild(ctx, "select_list"); if (tree != null) { Select_List select_list = new Select_List(); value.setIs_select_list(true); value.setSelect_list(select_list); this.stack.push(select_list); this.visit(tree); this.stack.pop(); return null; } TerminalNodeImpl type = (TerminalNodeImpl) ctx.INT(); if (type != null) { value.setIs_int(true); value.setValue(type.getText()); return null; } type = (TerminalNodeImpl) ctx.BOOL(); if (type != null) { value.setIs_bool(true); value.setValue(type.getText()); return null; } type = (TerminalNodeImpl) ctx.CHAR(); if (type != null) { value.setIs_char(true); value.setValue(type.getText()); return null; } type = (TerminalNodeImpl) ctx.FLOAT(); if (type != null) { value.setIs_float(true); value.setValue(type.getText()); return null; } type = (TerminalNodeImpl) ctx.STRING(); if (type != null) { value.setIs_string(true); value.setValue(type.getText()); return null; } type = (TerminalNodeImpl) ctx.OPTION_STRING(); if (type != null) { value.setIs_option_string(true); value.setValue(type.getText()); return null; } return null; }
From source file:parsetool.workflow.MyWorkflowVisitor.java
@Override public Void visitConstant(@NotNull WorkflowParser.ConstantContext ctx) { Constant constant = this.stack.peekCtx(Constant.class); constant.parse(ctx, this.stack.peekPrev()); TerminalNodeImpl type = (TerminalNodeImpl) ctx.CHARACTER_LITERAL(); if (type != null) { constant.setIs_char(true); constant.setValue(type.getText()); return null; }/* www.ja v a2 s .c o m*/ type = (TerminalNodeImpl) ctx.DECIMAL_LITERAL(); if (type != null) { constant.setIs_int(true); constant.setValue(type.getText()); return null; } type = (TerminalNodeImpl) ctx.FLOATING_POINT_LITERAL(); if (type != null) { constant.setIs_float(true); constant.setValue(type.getText()); return null; } type = (TerminalNodeImpl) ctx.HEX_LITERAL(); if (type != null) { constant.setIs_hex(true); constant.setValue(type.getText()); return null; } type = (TerminalNodeImpl) ctx.OCTAL_LITERAL(); if (type != null) { constant.setIs_octal(true); constant.setValue(type.getText()); return null; } type = (TerminalNodeImpl) ctx.STRING_LITERAL(); if (type != null) { constant.setIs_string(true); constant.setValue(type.getText()); return null; } type = (TerminalNodeImpl) ctx.BOOL_LITERAL(); if (type != null) { constant.setIs_bool(true); constant.setValue(type.getText()); return null; } return null; }