public void walk(ParseTreeListener listener, ParseTree t) { if ( t instanceof ErrorNode) { listener.visitErrorNode((ErrorNode)t); return; } else if ( t instanceof TerminalNode) { listener.visitTerminal((TerminalNode)t); return; } RuleNode r = (RuleNode)t; enterRule(listener, r); int n = r.getChildCount(); for (int i = 0; i<n; i++) { walk(listener, r.getChild(i)); } exitRule(listener, r); }
@Override public TqlElement visitFieldContains(TqlParser.FieldContainsContext ctx) { LOG.debug("Visit field contains: " + ctx.getText()); TerminalNode field = ctx.getChild(TerminalNode.class, 0); TqlElement fieldName = field.accept(this); TerminalNode valueNode = ctx.getChild(TerminalNode.class, 2); if (valueNode instanceof ErrorNode) throw new TqlException(valueNode.getText()); String quotedValue = valueNode.getSymbol().getText(); String value = quotedValue.substring(1, quotedValue.length() - 1); FieldContainsExpression fieldContainsExpression = new FieldContainsExpression(fieldName, value); LOG.debug("End visit field contains: " + ctx.getText()); return fieldContainsExpression; }
@Override public TqlElement visitFieldMatchesRegexp(TqlParser.FieldMatchesRegexpContext ctx) { LOG.debug("Visit field matches: " + ctx.getText()); TerminalNode field = ctx.getChild(TerminalNode.class, 0); TqlElement fieldName = field.accept(this); TerminalNode regexNode = ctx.getChild(TerminalNode.class, 2); if (regexNode instanceof ErrorNode) throw new TqlException(regexNode.getText()); String quotedRegex = regexNode.getSymbol().getText(); String regex = quotedRegex.substring(1, quotedRegex.length() - 1); FieldMatchesRegex fieldMatchesRegex = new FieldMatchesRegex(fieldName, regex); LOG.debug("End visit field matches: " + ctx.getText()); return fieldMatchesRegex; }
@Override public CypherAstBase visitErrorNode(ErrorNode node) { throw new MemgraphException(String.format( "Could not parse: invalid value \"%s\" (line: %d, pos: %d)", node.getText(), node.getSymbol().getLine(), node.getSymbol().getCharPositionInLine() )); }
/** * {@inheritDoc} * * <p>The default implementation returns the result of calling * {@link #visitChildren} on {@code ctx}.</p> */ // @Override public Result visitNumbers(@NotNull QueryParser.NumbersContext ctx) { // return new Result( Result.Type.NUMBER, ctx.getText()); // } @Override public Result visitErrorNode(@NotNull ErrorNode errorNode) { return null; }
@Override public void visitErrorNode(ErrorNode node) { super.visitErrorNode(node); if (!isGenericError(node.getText())) recognize(node.getSymbol(), getStop(node)); addErrorToken(node); debugErrorNode(node); }
@Override public void visitErrorNode(ErrorNode node) { if(node.getSymbol().getCharPositionInLine() != -1) { int line = node.getSymbol().getLine(); int rangeStart = node.getSymbol().getStartIndex(); int rangeEnd = node.getSymbol().getStopIndex(); log.logProblem("Error node: \"" + node.getText() + "\"", line, rangeStart, rangeEnd, Problem.Severity.CRITICAL); } else { log.logProblem("Error node with no position information: \"" + node.getText() + "\"", Problem.NO_LINE_NUM, Problem.Severity.CRITICAL); } }
private static <T> T checkNode(ParseTree node, Class<T> clazz) { if (node instanceof ErrorNode) { throw new IndexRQLParseError(node.getText()); } else if (node instanceof TerminalNode) { return null; } else if (clazz.isInstance(node)) { return (T) node; } return null; }
@Override public void visitErrorNode(ErrorNode node) { // if (builder.length() > 0) { // builder.append(' '); // } // // builder.append(Utils.escapeWhitespace(Trees.getNodeText(node, ruleNames), false)); // builder.append(System.lineSeparator()); }
@Override public void visitErrorNode(ErrorNode node) { if (builder.length() > 0) { builder.append(' '); } builder.append(Utils.escapeWhitespace(Trees.getNodeText(node, ruleNames), false)); }
@Override public CypherAstBase visitErrorNode(ErrorNode node) { throw new VertexiumException(String.format( "Could not parse: invalid value \"%s\" (line: %d, pos: %d)", node.getText(), node.getSymbol().getLine(), node.getSymbol().getCharPositionInLine() )); }
@Override public void visitErrorNode(ErrorNode node) { if (logger.isDebugEnabled()) { logger.debug("visitErrorNode(ErrorNode) - start"); //$NON-NLS-1$ } super.visitErrorNode(node); if (logger.isDebugEnabled()) { logger.debug("visitErrorNode(ErrorNode) - end"); //$NON-NLS-1$ } }
protected String getNodeText(Tree tree, List<String> ruleNames) { if (ruleNames != null) { if(tree instanceof RuleNode) { int ruleIndex = ((RuleNode)tree).getRuleContext().getRuleIndex(); String ruleName = (String)ruleNames.get(ruleIndex); return ruleName; } if(tree instanceof ErrorNode) return tree.toString(); if(tree instanceof TerminalNode) { Token symbol = ((TerminalNode)tree).getSymbol(); if(symbol != null) { String s = symbol.getText(); return s; } } } Object payload = tree.getPayload(); if(payload instanceof Token) return ((Token)payload).getText(); else return tree.getPayload().toString(); }
@Override public TqlElement visitFieldCompliesPattern(TqlParser.FieldCompliesPatternContext ctx) { LOG.debug("Visit field complies: " + ctx.getText()); TqlElement fieldName = ctx.getChild(0).accept(this); ParseTree patternNode = ctx.getChild(2); if (patternNode instanceof ErrorNode) throw new TqlException(patternNode.getText()); String quotedPattern = patternNode.getText(); String pattern = quotedPattern.substring(1, quotedPattern.length() - 1); FieldCompliesPattern fieldCompliesPattern = new FieldCompliesPattern(fieldName, pattern); LOG.debug("End visit field complies: " + ctx.getText()); return fieldCompliesPattern; }
@Override public TqlElement visitFieldIn(TqlParser.FieldInContext ctx) { LOG.debug("Visit field in: " + ctx.getText()); TerminalNode field = ctx.getChild(TerminalNode.class, 0); TqlElement fieldName = field.accept(this); // All children which are not terminal values are the needed literal values (see syntax) LiteralValue[] literalValues = ctx.children.stream().filter(c -> c instanceof TqlParser.LiteralValueContext || c instanceof TqlParser.BooleanValueContext || c instanceof ErrorNode).map(c -> (LiteralValue) c.accept(this)) .toArray(LiteralValue[]::new); FieldInExpression fieldIn = new FieldInExpression(fieldName, literalValues); LOG.debug("End visit field in: " + ctx.getText()); return fieldIn; }
@Override public void visitErrorNode(ErrorNode node) { super.visitErrorNode(node); logger.debug("visitErrorNode: " + node.getText()); }
@Override public void visitErrorNode(ErrorNode arg0) { Logger.log(Logger.DEBUG, "visitErrorNode" + arg0.getText()); }
@Override public void visitErrorNode(ErrorNode node) { //no imp }
@Override public void visitErrorNode(ErrorNode errorNode) { // do nothing. }
public void visitErrorNode(@NotNull ErrorNode node) { System.out.println(node.getText()); }
@Override public ParserResult visitErrorNode(ErrorNode node) { throw new UnsupportedOperationException("Error would be thrown by ThrowingExceptionErrorStrategy"); }
@Override public Result visitErrorNode(@NotNull ErrorNode errorNode) { return null; }
@Override public void visitErrorNode(ErrorNode errorNode) { }
@Override public void visitErrorNode(ErrorNode arg0) { // TODO Auto-generated method stub }
@Override public void visitErrorNode(ErrorNode errorNode) { super.visitErrorNode(errorNode); errorNodes.add(errorNode); }
public List<ErrorNode> getErrorNodes() { return errorNodes; }
@Override public void visitErrorNode(ErrorNode node) { if (!isGenericError(node.getText())) addElement(node.getSymbol(), SyntaxElementType.error); }
private void addErrorToken(ErrorNode node) { errorTokensRead.add(node.getSymbol()); allErrorTokensRead.add(node.getSymbol()); }
private int getStop(ErrorNode node) { return node.getSymbol().getStopIndex(); }
private void debugErrorNode(ErrorNode node) { debugToken("Error: " + node.getText(), getBoundaries(node)); }
@Override public void visitErrorNode(ErrorNode node) { valid = false; }
@Override public void visitTerminal(TerminalNode node) { valid &= !(node instanceof ErrorNode); }
@Override public void visitErrorNode(ErrorNode node) { }
@Override public void visitErrorNode(@NotNull ErrorNode node) { super.visitErrorNode(node); }
@Override public String visitErrorNode(ErrorNode node) { mErrorFlag = true; return ""; }
@Override public void visitErrorNode(ErrorNode node) { errorReporter.error(locationOf(node), node.getText()); }