List of usage examples for org.antlr.v4.runtime.tree ErrorNode getText
String getText();
From source file:com.blazebit.persistence.impl.expression.JPQLSelectExpressionVisitorImpl.java
License:Apache License
@Override public Expression visitErrorNode(ErrorNode node) { throw new SyntaxErrorException("Parsing failed: " + node.getText()); }
From source file:com.github.pascalgn.jiracli.parser.CommandReference.java
License:Apache License
public static List<CommandReference> parseCommandReferences(String str) { CommandLineLexer lexer = new CommandLineLexer(new ANTLRInputStream(str)); CommandLineParser parser = new CommandLineParser(new CommonTokenStream(lexer)); lexer.removeErrorListeners();//from ww w . j a v a 2 s . c o m parser.removeErrorListeners(); CommandLineContext commandLine = parser.commandLine(); final List<CommandReference> commands = new ArrayList<CommandReference>(); final StringBuilder name = new StringBuilder(); final List<String> arguments = new ArrayList<String>(); class Listener extends CommandLineParserBaseListener { @Override public void enterCommandName(CommandNameContext ctx) { if (name.length() == 0) { name.append(ctx.getText()); } else { List<String> args = new ArrayList<String>(arguments); CommandReference command = new CommandReference(name.toString(), args); commands.add(command); name.setLength(0); name.append(ctx.getText()); arguments.clear(); } } @Override public void enterArgument(ArgumentContext ctx) { String arg = ctx.getText(); if (arg.startsWith("'") && arg.endsWith("'")) { arguments.add(unescape(arg.substring(1, arg.length() - 1))); } else if (arg.startsWith("\"") && arg.endsWith("\"")) { arguments.add(unescape(arg.substring(1, arg.length() - 1))); } else { arguments.add(unescape(arg)); } } @Override public void visitErrorNode(ErrorNode node) { throw new IllegalStateException("Unexpected content: " + node.getText()); } } ParseTreeWalker.DEFAULT.walk(new Listener(), commandLine); if (name.length() > 0) { CommandReference command = new CommandReference(name.toString(), arguments); commands.add(command); } return commands; }
From source file:com.koltem.filetype.verilog.editor.VerilogContextTreeListener.java
@Override public void visitErrorNode(ErrorNode en) { //throw new java.lang.UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. println("In visitErrorNode"); println(en.getText()); }
From source file:com.microsoft.thrifty.schema.parser.ThriftListener.java
License:Open Source License
@Override public void visitErrorNode(ErrorNode node) { errorReporter.error(locationOf(node), node.getText()); }
From source file:com.twosigma.beaker.groovy.autocomplete.GroovyNodeCompletion.java
License:Apache License
@Override public void visitErrorNode(ErrorNode arg0) { if (arg0.getSymbol().getStartIndex() < cursor && arg0.getSymbol().getStopIndex() + 1 >= cursor) { //System.out.println("ERR: "+arg0.getSymbol().getStartIndex()+" "+arg0.getSymbol().getStopIndex()+" "+arg0.getSymbol().getText()); ParseTree cuc = arg0.getParent(); if (cuc.getChild(0).equals(arg0)) { AutocompleteCandidate c = new AutocompleteCandidate(GroovyCompletionTypes.INITIAL, arg0.getText()); addQuery(c);//from w ww . j a va 2 s .c o m } else { AutocompleteCandidate c = new AutocompleteCandidate(GroovyCompletionTypes.TOPLEVEL, arg0.getText()); addQuery(c); } if (cuc instanceof StatementContext && ((StatementContext) cuc).getStop().getStopIndex() + 1 == cursor) { if (cuc.getText().contains(".")) { addQuery(classUtils.expandExpression(cuc.getText(), registry, classUtils.DO_ALL)); // complete with standard groovy extension functions AutocompleteCandidate c = new AutocompleteCandidate(GroovyCompletionTypes.STDFUNCS, cuc.getText().substring(cuc.getText().lastIndexOf(".") + 1)); addQuery(c); } else { AutocompleteCandidate c = new AutocompleteCandidate(GroovyCompletionTypes.NAME, cuc.getText()); addQuery(c); c = new AutocompleteCandidate(GroovyCompletionTypes.CUSTOM_TYPE, cuc.getText()); addQuery(c); } } } }
From source file:com.twosigma.beaker.javash.autocomplete.JavaNodeCompletion.java
License:Apache License
@Override public void visitErrorNode(ErrorNode arg0) { if (arg0.getSymbol().getStartIndex() < cursor && arg0.getSymbol().getStopIndex() + 1 >= cursor) { //System.out.println("ERR: "+arg0.getSymbol().getStartIndex()+" "+arg0.getSymbol().getStopIndex()+" "+arg0.getSymbol().getText()); if (arg0.getParent() instanceof CompilationUnitContext) { CompilationUnitContext cuc = (CompilationUnitContext) arg0.getParent(); if (cuc.getChild(0).equals(arg0)) { AutocompleteCandidate c = new AutocompleteCandidate(JavaCompletionTypes.INITIAL, arg0.getText()); addQuery(c);// w ww . j a v a2s . c o m } else { AutocompleteCandidate c = new AutocompleteCandidate(JavaCompletionTypes.TOPLEVEL, arg0.getText()); addQuery(c); } return; } else if (arg0.getParent() instanceof BlockStatementContext) { if (!arg0.getSymbol().getText().equals(".")) { AutocompleteCandidate c = new AutocompleteCandidate(JavaCompletionTypes.BLOCKLEVEL, arg0.getText()); addQuery(c); c = new AutocompleteCandidate(JavaCompletionTypes.TYPE, arg0.getText()); addQuery(c); c = new AutocompleteCandidate(JavaCompletionTypes.CUSTOM_TYPE, arg0.getText()); addQuery(c); c = new AutocompleteCandidate(JavaCompletionTypes.NAME, arg0.getText()); addQuery(c); } else { BlockStatementContext bs = (BlockStatementContext) arg0.getParent(); if (bs.getChildCount() > 1) { addQuery(classUtils.expandExpression(bs.getText(), registry, classUtils.DO_ALL)); } } } else if (arg0.getParent() instanceof ExpressionContext) { // we are the rightmost child of the expression ParseTree chld = arg0.getParent().getChild(arg0.getParent().getChildCount() - 1); if (!chld.equals(arg0)) return; addQuery(classUtils.expandExpression(arg0.getParent().getText(), registry, classUtils.DO_NON_STATIC)); } else if (arg0.getParent() instanceof TypeDeclarationContext && arg0.getParent().getParent() != null && arg0.getParent().getParent() instanceof CompilationUnitContext) { AutocompleteCandidate c = new AutocompleteCandidate(JavaCompletionTypes.TOPLEVEL, arg0.getText()); addQuery(c); } else if (arg0.getParent() instanceof MemberDeclarationContext && arg0.getParent().getParent() != null && arg0.getParent().getParent() instanceof ClassBodyDeclarationContext && arg0.getParent().getParent().getParent() != null && arg0.getParent().getParent().getParent() instanceof ClassBodyContext && arg0.getParent().getParent().getParent().getText().trim().startsWith("<missing '{'>")) { AutocompleteCandidate c = new AutocompleteCandidate(JavaCompletionTypes.CLASSLEVEL, arg0.getText()); addQuery(c); } else if (arg0.getParent() instanceof MemberDeclarationContext && arg0.getParent().getParent() != null && arg0.getParent().getParent() instanceof ClassBodyDeclarationContext && arg0.getParent().getParent().getParent() != null && arg0.getParent().getParent().getParent() instanceof ClassBodyContext) { AutocompleteCandidate c = new AutocompleteCandidate(JavaCompletionTypes.TYPE, arg0.getText()); addQuery(c); c = new AutocompleteCandidate(JavaCompletionTypes.CUSTOM_TYPE, arg0.getText()); addQuery(c); } } }
From source file:com.twosigma.beakerx.javash.autocomplete.JavaNodeCompletion.java
License:Apache License
@Override public void visitErrorNode(ErrorNode arg0) { if (arg0.getText().equals("new")) { CompilationUnitContext cuc = (CompilationUnitContext) arg0.getParent(); List<ParseTree> children = cuc.children; int tokenIndex = arg0.getSymbol().getTokenIndex(); if (tokenIndex - 2 >= 0 && tokenIndex + 1 <= children.size()) { ParseTree variablePT = children.get(tokenIndex - 2); ParseTree typePT = children.get(tokenIndex + 1); String type = typePT.getText(); String variable = variablePT.getText(); AutocompleteCandidate c1 = new AutocompleteCandidate(JavaCompletionTypes.NAME, variable); registry.addCandidate(c1);/*from ww w . ja v a 2 s . c o m*/ if (type != null) classUtils.defineVariable(variable, type); return; } } if (arg0.getSymbol().getStartIndex() < cursor && arg0.getSymbol().getStopIndex() + 1 >= cursor) { //System.out.println("ERR: "+arg0.getSymbol().getStartIndex()+" "+arg0.getSymbol().getStopIndex()+" "+arg0.getSymbol().getText()); if (arg0.getParent() instanceof CompilationUnitContext) { CompilationUnitContext cuc = (CompilationUnitContext) arg0.getParent(); AutocompleteCandidate c = new AutocompleteCandidate(JavaCompletionTypes.INITIAL, arg0.getText()); addQuery(c, cursor); AutocompleteCandidate c2 = new AutocompleteCandidate(JavaCompletionTypes.TOPLEVEL, arg0.getText()); addQuery(c2, cursor); completeClassFromPath(cuc, arg0.getText()); return; } else if (arg0.getParent() instanceof BlockStatementContext) { if (!arg0.getSymbol().getText().equals(".")) { AutocompleteCandidate c = new AutocompleteCandidate(JavaCompletionTypes.BLOCKLEVEL, arg0.getText()); addQuery(c, cursor); c = new AutocompleteCandidate(JavaCompletionTypes.TYPE, arg0.getText()); addQuery(c, cursor); c = new AutocompleteCandidate(JavaCompletionTypes.CUSTOM_TYPE, arg0.getText()); addQuery(c, cursor); c = new AutocompleteCandidate(JavaCompletionTypes.NAME, arg0.getText()); addQuery(c, cursor); } else { BlockStatementContext bs = (BlockStatementContext) arg0.getParent(); if (bs.getChildCount() > 1) { addQuery(classUtils.expandExpression(bs.getText(), registry, classUtils.DO_ALL), cursor); } } } else if (arg0.getParent() instanceof ExpressionContext) { // we are the rightmost child of the expression ParseTree chld = arg0.getParent().getChild(arg0.getParent().getChildCount() - 1); if (!chld.equals(arg0)) return; addQuery( classUtils.expandExpression(arg0.getParent().getText(), registry, classUtils.DO_NON_STATIC), cursor); } else if (arg0.getParent() instanceof TypeDeclarationContext && arg0.getParent().getParent() != null && arg0.getParent().getParent() instanceof CompilationUnitContext) { AutocompleteCandidate c = new AutocompleteCandidate(JavaCompletionTypes.TOPLEVEL, arg0.getText()); addQuery(c, cursor); } else if (arg0.getParent() instanceof MemberDeclarationContext && arg0.getParent().getParent() != null && arg0.getParent().getParent() instanceof ClassBodyDeclarationContext && arg0.getParent().getParent().getParent() != null && arg0.getParent().getParent().getParent() instanceof ClassBodyContext && arg0.getParent().getParent().getParent().getText().trim().startsWith("<missing '{'>")) { AutocompleteCandidate c = new AutocompleteCandidate(JavaCompletionTypes.CLASSLEVEL, arg0.getText()); addQuery(c, cursor); } else if (arg0.getParent() instanceof MemberDeclarationContext && arg0.getParent().getParent() != null && arg0.getParent().getParent() instanceof ClassBodyDeclarationContext && arg0.getParent().getParent().getParent() != null && arg0.getParent().getParent().getParent() instanceof ClassBodyContext) { AutocompleteCandidate c = new AutocompleteCandidate(JavaCompletionTypes.TYPE, arg0.getText()); addQuery(c, cursor); c = new AutocompleteCandidate(JavaCompletionTypes.CUSTOM_TYPE, arg0.getText()); addQuery(c, cursor); } } }
From source file:edu.psu.swe.scim.spec.phonenumber.PhoneNumberParseTreeListener.java
License:Apache License
@Override public void visitErrorNode(ErrorNode node) { LOGGER.error(indent(node.getText())); }
From source file:edu.psu.swe.scim.spec.phonenumber.TreePrintingListener.java
License:Apache License
@Override public void visitErrorNode(ErrorNode node) { log.error(indent(node.getText())); }
From source file:edu.psu.swe.scim.spec.protocol.filter.TreePrintingListener.java
License:Apache License
@Override public void visitErrorNode(ErrorNode node) { LOG.error(indent(node.getText())); }