List of usage examples for org.antlr.v4.runtime Token getText
String getText();
From source file:de.huberlin.cuneiform.language.StringExpression.java
License:Apache License
public void setValue(Token valueToken) { if (valueToken == null) throw new NullPointerException("Value token must not be null."); value = valueToken.getText(); if (value == null) throw new NullPointerException("Value string must not be null."); if (value.length() < 2) throw new RuntimeException("Value string length must not be smaller than 2."); if (!(value.startsWith("'") && value.endsWith("'"))) if (!(value.startsWith("\"") && value.endsWith("\""))) throw new RuntimeException("Value string must start and end either on ''' or '\"'"); value = value.substring(1, value.length() - 1); }
From source file:de.huberlin.wbi.cuneiform.core.preprocess.PreListener.java
License:Apache License
@Override public void enterCallExpr(@NotNull CuneiformParser.CallExprContext ctx) { Token id; Token lparen;/*from w ww . ja v a 2 s. c om*/ id = ctx.ID().getSymbol(); lparen = ctx.LPAREN().getSymbol(); rewriter.replace(id, "apply"); rewriter.insertAfter(lparen, " task: " + id.getText() + " "); }
From source file:de.huberlin.wbi.cuneiform.core.preprocess.PreListener.java
License:Apache License
@Override public void enterForeignDefTask(@NotNull CuneiformParser.ForeignDefTaskContext ctx) { Token deftask;// w w w . j a va2 s . c o m Token id; Token bodyStop; deftask = ctx.DEFTASK().getSymbol(); bodyStop = ctx.foreignBody().getStop(); id = ctx.ID().getSymbol(); rewriter.insertAfter(bodyStop, ";"); rewriter.insertAfter(id, " = \\"); rewriter.replace(deftask, id, id.getText()); }
From source file:de.huberlin.wbi.cuneiform.core.preprocess.PreListener.java
License:Apache License
@Override public void enterNativeDefTask(@NotNull CuneiformParser.NativeDefTaskContext ctx) { Token deftask;//www. j a va 2s . c o m Token id; Token bodyStop; deftask = ctx.DEFTASK().getSymbol(); bodyStop = ctx.RBRACE().getSymbol(); id = ctx.ID().getSymbol(); rewriter.insertAfter(bodyStop, ";"); rewriter.insertAfter(id, " = \\"); rewriter.replace(deftask, id, id.getText()); }
From source file:de.huberlin.wbi.cuneiform.core.preprocess.PreListener.java
License:Apache License
@Override public void exitFromStackExpr(@NotNull CuneiformParser.FromStackExprContext ctx) { Token symbol; symbol = ctx.FROMSTACK().getSymbol(); if (exprStack.isEmpty()) throw new ParseException(symbol.getLine(), symbol.getCharPositionInLine(), symbol.getText(), "Pipe destination encountered where there is no source."); rewriter.replace(symbol, exprStack.pop()); }
From source file:de.interactive_instruments.ShapeChange.SBVR.Sbvr2FolVisitor.java
License:Open Source License
/** * @param quantifier/*from w w w.j a v a 2s . c o m*/ * @param noun * @param context * provides the context for evaluation of the noun; can be * <code>null</code>; if not <code>null</code> the context can be * a list of SchemaCalls and a copy of it will be prepended as-is * (so without checks for validity in context) to the SchemaCall * represented by the noun - the result is the value of the * variable * @param predicateExprCtx * @return */ private Quantification parseQuantification(Quantifier quantifier, Token noun, PropertyCall verbContext, RelativeClauseExprContext relativeClauseExprCtx) { Quantification q = new Quantification(); q.setQuantifier(quantifier); // parse noun concept (handle concatenation) String n = noun.getText(); try { Variable v; if (verbContext != null) { v = parseVariable(n, verbContext); } else { v = parseVariable(n); } q.setVar(v); scopes.push(v); } catch (SbvrParsingException e) { SbvrErrorInfo error = e.getError(); error.setMetadataFromToken(noun); throw e; } // parse optional relative clause if (relativeClauseExprCtx != null) { Predicate p = this.visitRelativeClauseExpr(relativeClauseExprCtx); q.setCondition(p); } return q; }
From source file:de.interactive_instruments.ShapeChange.SBVR.Sbvr2FolVisitor.java
License:Open Source License
@Override public Expression visitNameExpr(NameExprContext ctx) { List<String> names = new ArrayList<String>(); for (Token t : ctx.values) { String s = t.getText(); // strip leading and trailing "'" names.add(s.substring(1, s.length() - 1)); }/* ww w .j ava 2 s . c o m*/ if (names.size() == 1) { StringLiteral sl = new StringLiteral(); sl.setValue(names.get(0)); return sl; } else { StringLiteralList sll = new StringLiteralList(); sll.setValues(names); return sll; } }
From source file:de.interactive_instruments.ShapeChange.SBVR.SbvrValidationErrorListener.java
License:Open Source License
public boolean validateNounConcept(Token t) { if (t == null) { String msg = "Unknown noun concept encountered."; addErrorMessage(Category.NOT_A_NOUN_CONCEPT, msg); return false; }//from www. j av a 2 s .com String concept = t.getText(); if (!isNoun(concept)) { String msg = concept + " is not a known noun concept."; addErrorMessage(Category.NOT_A_NOUN_CONCEPT, msg, t); return false; } return true; }
From source file:de.interactive_instruments.ShapeChange.SBVR.SbvrValidationErrorListener.java
License:Open Source License
@Override public void enterVerbExpr(de.interactive_instruments.antlr.sbvr.SBVRParser.VerbExprContext ctx) { Token verbToken = ctx.verb; if (verbToken != null) { String concept = verbToken.getText(); /*//w ww . j a v a 2 s .com * TODO this simple noun check is usually done automatically using the * SbvrParserHelper; a more thorough test could be performed here */ if (!isVerb(concept)) { String msg = concept + " is not a known verb concept."; addErrorMessage(Category.NOT_A_VERB_CONCEPT, msg, verbToken); } } }
From source file:dijkstra.utility.DijkstraTraceListener.java
License:Open Source License
private String tokenString(ParseTree pt) { StringBuilder sb = new StringBuilder(); Token t = ((TerminalNode) pt).getSymbol(); if (t.getType() == INTEGER | t.getType() == ID) { sb.append(parser.getVocabulary().getDisplayName(t.getType()) + " '" + t.getText() + "'"); } else {/*www. jav a2 s .c om*/ sb.append(parser.getVocabulary().getDisplayName(t.getType())); } return sb.toString(); }