List of usage examples for org.antlr.v4.runtime Token getText
String getText();
From source file:nl.lxtreme.libtdl.grammar.adv.TriggerStageAction.java
License:Apache License
/** * Returns the numeric index of the timer, so "timer1" -> 1 and "timer2" * -> 2.//from www .ja va2 s . c o m * * @param timerName * the timer name, cannot be <code>null</code>. * @return a numeric index, >= 0. */ private int getTimerNumber(Token timerName) { String name = timerName.getText(); char index = name.charAt(name.length() - 1); if (!Character.isDigit(index)) { return 0; } return index - '0'; }
From source file:nl.lxtreme.libtdl.grammar.adv.TriggerSum.java
License:Apache License
/** * Defines an input for this sum./*from w w w.j ava2s .c o m*/ * * @param inputTree * the input, e.g., a, b, timer1, and so on. * @return the index of the given input, >= 0 && < 16. */ public SumPart defineInput(Token inputTree) { int idx = findInputIndex(inputTree.getText()); if (idx < 0) { throw new RuntimeException("Invalid input: " + inputTree.getText()); } Input input = m_inputs[idx]; // Initialize this operator for use in this sum... input.init(); return input; }
From source file:nl.lxtreme.libtdl.grammar.adv.TriggerSum.java
License:Apache License
/** * Defines an operation on a lefthand and righthand side. * //from w ww . j ava 2s . c o m * @param operator * the operator to apply; * @param lhs * the LHS-sum pair; * @param rhs * the RHS-sum pair. * @return the new index, >= 0. */ public SumPart defineOperator(Token operator, SumPart lhs, SumPart rhs) { AbstractSumPair part = getPart(lhs, rhs); part.setOperator(mapOperator(operator.getText())); return part; }
From source file:nl.lxtreme.libtdl.grammar.basic.BasicTdlSemanticAnalyzer.java
License:Apache License
@Override public BasicTdlSemanticAnalyzer visitExpr(ExprContext ctx) { if (ctx.term != null) { Token term = ctx.term; String name = normalizeName(term.getText()); if (!m_declarations.containsKey(name)) { String msg = name + " is not declared"; Marker marker = new MarkerBuilder().setCategory(Category.SEMANTIC).setType(Type.ERROR) // .setLocation(ctx).setDescription(msg).build(); m_problemReporter.report(marker); }//from ww w . j av a 2 s . co m } return super.visitExpr(ctx); }
From source file:nl.lxtreme.libtdl.grammar.basic.TermExpression.java
License:Apache License
/** * Defines the actual term used./*from w w w . jav a 2 s. c o m*/ * * @param token * the token representing the term, cannot be <code>null</code>. */ public void defineTerm(Token token) { m_name = Util.normalizeName(token.getText()); }
From source file:no.ssb.vtl.script.error.VTLScriptException.java
License:Apache License
private void extractPositionFromContext(ParserRuleContext ctx) { checkNotNull(ctx);// w w w.ja v a 2s .co m startLine = ctx.getStart().getLine(); startColumn = ctx.getStart().getCharPositionInLine(); if (ctx.getStop() != null) { stopLine = ctx.getStop().getLine(); if (ctx.getStart() == ctx.getStop()) { Token token = ctx.getStart(); stopColumn = startColumn + token.getText().length(); } else { stopColumn = ctx.getStop().getCharPositionInLine(); } } }
From source file:no.ssb.vtl.script.visitors.AggregationVisitor.java
License:Apache License
private static Set<Component> computeAggregationComponents(Set<Component> aggregationComponents, Set<Component> availableIdentifiers, Token clause) { switch (clause.getType()) { case GROUP_BY: return aggregationComponents; case ALONG:// w w w .j av a 2 s.c o m return availableIdentifiers.stream().filter(component -> !aggregationComponents.contains(component)) .collect(Collectors.toSet()); default: throw new IllegalArgumentException("unrecognized token: " + clause.getText()); } }
From source file:org.apache.hive.hplsql.Exec.java
License:Apache License
/** * Append the text preserving the formatting (space symbols) between tokens *//*from w ww . j av a 2 s.c o m*/ void append(StringBuilder str, String appendStr, Token start, Token stop) { String spaces = start.getInputStream() .getText(new org.antlr.v4.runtime.misc.Interval(start.getStartIndex(), stop.getStopIndex())); spaces = spaces.substring(start.getText().length(), spaces.length() - stop.getText().length()); str.append(spaces); str.append(appendStr); }
From source file:org.apache.olingo.server.core.uri.parser.Parser.java
License:Apache License
public void showTokens(final String input, final List<? extends Token> list) { boolean first = true; System.out.println("input: " + input); String nL = "\n"; StringBuilder out = new StringBuilder("[").append(nL); for (Token token : list) { if (!first) { out.append(","); first = false;/*from w w w . ja va 2 s . c o m*/ } int index = token.getType(); out.append("\"").append(token.getText()).append("\"").append(" "); if (index != -1) { out.append(UriLexer.VOCABULARY.getDisplayName(index)); } else { out.append(index); } out.append(nL); } out.append(']'); System.out.println("tokens: " + out.toString()); }
From source file:org.apache.olingo.server.core.uri.testutil.ParseTreeToText.java
License:Apache License
private static String getNodeText(@NotNull final Tree t, @Nullable final List<String> ruleNames) { if (ruleNames != null) { if (t instanceof RuleNode) { int ruleIndex = ((RuleNode) t).getRuleContext().getRuleIndex(); return ruleNames.get(ruleIndex); } else if (t instanceof ErrorNode) { return t.toString(); } else if (t instanceof TerminalNode) { Token symbol = ((TerminalNode) t).getSymbol(); if (symbol != null) { return symbol.getText(); }/* w ww . ja v a2s . c o m*/ } } // no recog for rule names Object payload = t.getPayload(); if (payload instanceof Token) { return ((Token) payload).getText(); } return t.getPayload().toString(); }