List of usage examples for org.antlr.v4.runtime.tree RuleNode getText
String getText();
From source file:com.espertech.esper.epl.parse.ASTConstantHelper.java
License:Open Source License
private static Object parseNumber(RuleNode number, int factor) { int tokenType = getSingleChildTokenType(number); if (tokenType == EsperEPL2GrammarLexer.IntegerLiteral) { return parseIntLongByte(number.getText(), factor); }// w w w . j av a 2 s . c o m else if (tokenType == EsperEPL2GrammarLexer.FloatingPointLiteral) { String numberText = number.getText(); if (numberText.endsWith("f") || numberText.endsWith("F")) { return FloatValue.parseString(number.getText()) * factor; } else { return DoubleValue.parseString(number.getText()) * factor; } } throw ASTWalkException.from("Encountered unrecognized constant", number.getText()); }
From source file:nl.basjes.parse.useragent.utils.AntlrUtils.java
License:Apache License
public static String getSourceText(RuleNode ruleNode) { if (ruleNode instanceof ParserRuleContext) { return getSourceText((ParserRuleContext) ruleNode); }//from w w w. j a va 2 s .c o m return ruleNode.getText(); }
From source file:org.aksw.simba.cetus.parser.StringCreatingVisitor.java
License:Open Source License
public String visitChildren(RuleNode node) { int n = node.getChildCount(); if (n > 1) { StringBuilder result = new StringBuilder(); ParseTree child;// w w w . j a v a2 s . co m String childResult; for (int i = 0; i < n; i++) { child = node.getChild(i); childResult = child.accept(this); if (childResult != null) { if (i > 0) { result.append(' '); } result.append(childResult); } } return result.toString(); } else { if (n == 1) { return node.getChild(0).accept(this); } else { return node.getText(); } } }
From source file:org.icesquirrel.interpreter.SquirrelInterpretedFunction.java
License:Open Source License
public SquirrelInterpretedFunction(StatContext functionBody, FuncargsContext functionSignature) { super();/*from ww w. ja v a 2 s . co m*/ this.functionBody = Arrays.asList(functionBody); AbstractParseTreeVisitor<YieldContext> visitor = new AbstractParseTreeVisitor<YieldContext>() { @Override public YieldContext visitChildren(RuleNode node) { System.err.println("VISIT CHILDREN: " + node.getText()); // TODO Auto-generated method stub return super.visitChildren(node); } @Override protected boolean shouldVisitNextChild(RuleNode node, YieldContext currentResult) { // TODO Auto-generated method stub boolean shouldVisitNextChild = super.shouldVisitNextChild(node, currentResult); System.err.println("VISIT SHOULD VISIT: " + node.getText() + " = " + shouldVisitNextChild + " / YIELD : " + currentResult); return shouldVisitNextChild; } @Override public YieldContext visit(ParseTree tree) { System.err.println("VISIT: " + tree.getText()); return super.visit(tree); } }; YieldContext yield = visitor.visit(functionBody); // YieldContext yield = functionBody.accept(visitor); if (yield != null) { System.err.println("REMOVEME! GOT YIELD"); } // setGenerator(functionBody.getText().contains("yi)); // TODO // vararg support // TODO // friend variables // Arguments ArglistContext parlist = functionSignature.arglist(); if (parlist != null) { varargs = parlist.VARARGS() != null; if (!varargs) { for (NameContext name : parlist.namelist().name()) { String nameText = name.NAME().getText(); ExpContext exp = name.exp(); Object value = null; if (exp != null) { value = SquirrelExecutionContext.get().getProcessor().evaluate(exp); } arguments.insertLocal(nameText, value); } } } }