List of usage examples for org.antlr.v4.runtime.tree TerminalNode getText
String getText();
From source file:HSMgen.java
License:Open Source License
public void exitFsmSectionStm(@NotNull HSMgenParser.FsmSectionStmContext ctx) { ArraySym states = new ArraySym(); for (HSMgenParser.FsmStateStmContext sctx : ctx.fsmStateStm()) { states.addElem(getAnnotation(sctx)); delAnnotation(sctx);/*from ww w. j av a2s .c o m*/ } ArraySym inherited = new ArraySym(); if (ctx.fsmSubState() != null) { for (TerminalNode i : ctx.fsmSubState().IDENTIFIER()) { inherited.addElem(new Symbol(SymType.IDENTIFIER, i.getText(), null)); } } HSMgen.dumpFsm(new Symbol(SymType.ARRAY, ctx.IDENTIFIER().getText(), states), new Symbol(SymType.ARRAY, null, inherited)); }
From source file:PostParser.java
License:Open Source License
/** * {@inheritDoc}/*from www. j a v a2s . c om*/ * * <p>This takes a ParserRuleContext of a binary operator and "flattens" * the operator if one of its operands is the same binary operator context.</p> */ public void flatten(ParserRuleContext ctx) { /* This function only flattens if the operator is the same and also * keeps the operators intact. * * Since ANTLR4 parses this operator as left associative, we only * need to check the left hand side expr. */ //If the child isn't the same construct, nothing to do. if (!(ctx.getChild(0).getClass() == ctx.getClass())) return; ParserRuleContext lhs = (ParserRuleContext) ctx.getChild(0); ParseTree rhs = ctx.getChild(2); TerminalNode op = (TerminalNode) ctx.getChild(1); /*If the operator of the nested Context isn't the same, nothing to do. *The operator is always in position 1 for infix operators. We do this *check because some Contexts that use the same context for multiple *operators. */ if (!op.getText().equals(lhs.getChild(1).getText())) return; //Clear all children. ctx.children.clear(); //Add all children of lhs. (Also adds the operator of the lhs.) ctx.children.addAll(lhs.children); //Finally, add the rhs back in. ctx.children.add(rhs); }
From source file:PostParser.java
License:Open Source License
/** * {@inheritDoc}//from w w w .ja v a 2s . co m * * <p>PlusOp[expr1,expr2]</p> */ @Override public void exitPlusOp(FoxySheepParser.PlusOpContext ctx) { /* We have to treat PlusOp special, because we only flatten if the operator * is the same, and we also have to keep the operators intact. Also, only * plus and minus (not PlusMinus or MinusPlus) are flat. */ /* Since ANTLR4 parses this operator as left associative, we only * need to check the left hand side expr. */ //If the child isn't a PlusOp, nothing to do. if (!(ctx.getChild(0) instanceof FoxySheepParser.PlusOpContext)) return; //If the op isn't Plus or Minus, nothing to do. if (ctx.BINARYMINUS() == null && ctx.BINARYPLUS() == null) return; FoxySheepParser.PlusOpContext lhs = (FoxySheepParser.PlusOpContext) ctx.getChild(0); ParseTree rhs = ctx.getChild(2); TerminalNode op = (TerminalNode) ctx.getChild(1); //If the operator of the nested PlusOp isn't the same, nothing to do. if (!op.getText().equals(lhs.getChild(1).getText())) return; //Clear all children. ctx.children.clear(); //Add all children of lhs. (Also adds the operator of the lhs.) ctx.children.addAll(lhs.children); //Finally, add the rhs back in. ctx.children.add(rhs); }
From source file:PostParser.java
License:Open Source License
/** * {@inheritDoc}/*from w w w. ja v a2 s . c o m*/ * * <p>And[expr1,expr2]</p> */ @Override public void exitAnd(FoxySheepParser.AndContext ctx) { //The usual flatten function won't work, because there are two And operators, //and we need to flatten over both. //If the child isn't the same construct, nothing to do. if (!(ctx.getChild(0).getClass() == ctx.getClass())) return; ParserRuleContext lhs = (ParserRuleContext) ctx.getChild(0); ParseTree rhs = ctx.getChild(2); TerminalNode op = (TerminalNode) ctx.getChild(1); /*If the operator of the nested Context isn't the same, nothing to do. *The operator is always in position 1 for infix operators. We do this *check because some Contexts that use the same context for multiple *operators. */ //Here's the part that's different from flatten(). //If childOp is an Nand or parentOp is a Nand, then we need child==parent. String childOp = lhs.getChild(1).getText(); if (childOp.equals("\u22bc") || op.getText().equals("\u22bc")) { if (!op.getText().equals(childOp)) return; } //Clear all children. ctx.children.clear(); //Add all children of lhs. (Also adds the operator of the lhs.) ctx.children.addAll(lhs.children); //Finally, add the rhs back in. ctx.children.add(rhs); }
From source file:PostParser.java
License:Open Source License
/** * {@inheritDoc}//from w ww . j a va2s . c o m * * <p>Or[expr1,expr2]</p> */ @Override public void exitOr(FoxySheepParser.OrContext ctx) { //The usual flatten function won't work, because there are two Or operators, //and we need to flatten over both. //If the child isn't the same construct, nothing to do. if (!(ctx.getChild(0).getClass() == ctx.getClass())) return; ParserRuleContext lhs = (ParserRuleContext) ctx.getChild(0); ParseTree rhs = ctx.getChild(2); TerminalNode op = (TerminalNode) ctx.getChild(1); /*If the operator of the nested Context isn't the same, nothing to do. *The operator is always in position 1 for infix operators. We do this *check because some Contexts that use the same context for multiple *operators. */ //Here's the part that's different from flatten(). //If childOp is an Nor or parentOp is a Nor, then we need child==parent. String childOp = lhs.getChild(1).getText(); if (childOp.equals("\u22bd") || op.getText().equals("\u22bd")) { if (!op.getText().equals(childOp)) return; } //Clear all children. ctx.children.clear(); //Add all children of lhs. (Also adds the operator of the lhs.) ctx.children.addAll(lhs.children); //Finally, add the rhs back in. ctx.children.add(rhs); }
From source file:FunctionListener.java
@Override public void enterFunctionExpression(ECMAScriptParser.FunctionExpressionContext ctx) { TerminalNode id = ctx.Identifier(); // tester si null car fonction anonyme currentFunctionName = id.getText(); graph.nodes.add(currentFunctionName); }
From source file:ai.grakn.graql.internal.parser.GremlinVisitor.java
License:Open Source License
@Override public Consumer<PrettyStringBuilder> visitTerminal(TerminalNode node) { return str -> { str.append(node.getText()); }; }
From source file:ai.grakn.graql.internal.parser.QueryVisitor.java
License:Open Source License
private String unquoteString(TerminalNode string) { return string.getText().substring(1, string.getText().length() - 1); }
From source file:ai.grakn.graql.internal.parser.QueryVisitor.java
License:Open Source License
private long getInteger(TerminalNode integer) { return Long.parseLong(integer.getText()); }
From source file:ai.grakn.graql.internal.template.TemplateVisitor.java
License:Open Source License
@Override public String visitTerminal(TerminalNode node) { int index = node.getSymbol().getTokenIndex(); String lws = tokens.getHiddenTokensToLeft(index) != null ? tokens.getHiddenTokensToLeft(index).stream().map(Token::getText).collect(joining()) : ""; String rws = tokens.getHiddenTokensToRight(index) != null ? tokens.getHiddenTokensToRight(index).stream().map(Token::getText).collect(joining()) : ""; return lws + node.getText() + rws; }