@Override public void enterAlter_view(Alter_viewContext ctx) { throw new ParseCancellationException("Not finishing parse of ALTER VIEW"); }
public ParseCancellationException(String message, Throwable cause) { super(message); initCause(cause); }
throw (RecognitionException)e.getCause();
if (pce.getCause() instanceof WrappedException) { WrappedException cause = (WrappedException) pce.getCause(); } else { throw new ScriptException( pce.getMessage(), null, cause.getLineNumber(), if (pce.getCause() != null) { throw new ScriptException(pce.getCause().getMessage()); } else { throw new ScriptException(pce.getMessage());
private void read(Graph<V, E> graph, Reader input, CSVBaseListener listener) throws ImportException { try { ThrowingErrorListener errorListener = new ThrowingErrorListener(); // create lexer CSVLexer lexer = new CSVLexer(CharStreams.fromReader(input)); lexer.setSep(delimiter); lexer.removeErrorListeners(); lexer.addErrorListener(errorListener); // create parser CSVParser parser = new CSVParser(new CommonTokenStream(lexer)); parser.removeErrorListeners(); parser.addErrorListener(errorListener); // Specify our entry point CSVParser.FileContext graphContext = parser.file(); // Walk it and attach our listener ParseTreeWalker walker = new ParseTreeWalker(); walker.walk(listener, graphContext); } catch (IOException e) { throw new ImportException("Failed to import CSV graph: " + e.getMessage(), e); } catch (ParseCancellationException pe) { throw new ImportException("Failed to import CSV graph: " + pe.getMessage(), pe); } catch (IllegalArgumentException iae) { throw new ImportException("Failed to import CSV graph: " + iae.getMessage(), iae); } }
/** * Parse a string into either a full PSL Rule or a rule without weight or potential squaring information. */ public static RulePartial loadRulePartial(DataStore data, String input) throws IOException { PSLParser parser = getParser(input); PslRulePartialContext context = null; try { context = parser.pslRulePartial(); } catch (ParseCancellationException ex) { // Cancel the parse and rethrow the cause. throw (RuntimeException)ex.getCause(); } ModelLoader visitor = new ModelLoader(data); return visitor.visitPslRulePartial(context); }
throw new ImportException("Failed to import gml graph: " + e.getMessage(), e); } catch (ParseCancellationException pe) { throw new ImportException("Failed to import gml graph: " + pe.getMessage(), pe); } catch (IllegalArgumentException iae) { throw new ImportException("Failed to import gml graph: " + iae.getMessage(), iae);
@Override public void enterCreate_view(Create_viewContext ctx) { throw new ParseCancellationException("Not finishing parse of CREATE VIEW"); }
/** * Parse and return a Model (collection of rules). * The input should only contain rules and the DataStore should contain all the predicates * used by the rules. */ public static Model load(DataStore data, Reader input) throws IOException { PSLParser parser = getParser(input); ProgramContext program = null; try { program = parser.program(); } catch (ParseCancellationException ex) { // Cancel the parse and rethrow the cause. throw (RuntimeException)ex.getCause(); } ModelLoader visitor = new ModelLoader(data); return visitor.visitProgram(program, parser); }
public ParseCancellationException(Throwable cause) { initCause(cause); }
public class ThrowingErrorListener extends BaseErrorListener { public static final ThrowingErrorListener INSTANCE = new ThrowingErrorListener(); @Override public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) throws ParseCancellationException { throw new ParseCancellationException("line " + line + ":" + charPositionInLine + " " + msg); } }
if (x.getCause() instanceof InputMismatchException) { InputMismatchException xx = (InputMismatchException)x.getCause(); String offend = xx.getOffendingToken().getText(); throw new OrcaException(x, "Invalid SQL. Offending token: {}", offend); if (x.getCause() instanceof NoViableAltException) { NoViableAltException xx = (NoViableAltException)x.getCause(); String offend = xx.getOffendingToken().getText(); throw new OrcaException(x, "Invalid SQL. Offending token: {}", offend);
public ParseCancellationException(String message, Throwable cause) { super(message); initCause(cause); }
/** Instead of recovering from exception {@code e}, re-throw it wrapped * in a {@link ParseCancellationException} so it is not caught by the * rule function catches. Use {@link Exception#getCause()} to get the * original {@link RecognitionException}. */ @Override public void recover(Parser recognizer, RecognitionException e) { for (ParserRuleContext context = recognizer.getContext(); context != null; context = context.getParent()) { context.exception = e; } throw new ParseCancellationException(e); }
public <T extends ExecutionResult> T execute() { assertNotNull(arguments, "Arguments can't be null"); LOGGER.info("Executing request. Operation name: {}. Request: {} ", operationName, requestQuery); Parser parser = new Parser(); Document document; try { document = parser.parseDocument(requestQuery); } catch (ParseCancellationException e) { RecognitionException recognitionException = (RecognitionException) e.getCause(); SourceLocation sourceLocation = new SourceLocation(recognitionException.getOffendingToken().getLine(), recognitionException.getOffendingToken().getCharPositionInLine()); InvalidSyntaxError invalidSyntaxError = new InvalidSyntaxError(sourceLocation); return (T) new GraphQLRxExecutionResult(Observable.just(null), Observable.just(Arrays.asList(invalidSyntaxError))); } Validator validator = new Validator(); List<ValidationError> validationErrors = validator.validateDocument(graphQLSchemaHolder.getGraphQLSchema(), document); if (validationErrors.size() > 0) { return (T) new GraphQLRxExecutionResult(Observable.just(null), Observable.just(validationErrors)); } if (executionStrategy == null) { if (executorService == null) { executionStrategy = new GraphQLDefaultRxExecutionStrategy(graphQLSchemaHolder, maxQueryDepth, maxQueryComplexity); } else { executionStrategy = new GraphQLExecutorServiceRxExecutionStrategy(graphQLSchemaHolder, executorService, maxQueryDepth, maxQueryComplexity); } } RxExecution execution = new RxExecution(graphQLSchemaHolder, maxQueryDepth, maxQueryComplexity, executionStrategy); ExecutionResult executionResult = execution.execute(graphQLSchemaHolder.getGraphQLSchema(), context, document, operationName, arguments); return (T) (executionResult instanceof GraphQLRxExecutionResult ? executionResult : new GraphQLRxExecutionResult(Observable.just(executionResult.getData()), Observable.just(executionResult.getErrors()))); }
public ParseCancellationException(String message, Throwable cause) { super(message); initCause(cause); }
/** Make sure we don't attempt to recover inline; if the parser * successfully recovers, it won't throw an exception. */ @Override public Token recoverInline(Parser recognizer) throws RecognitionException { InputMismatchException e = new InputMismatchException(recognizer); for (ParserRuleContext context = recognizer.getContext(); context != null; context = context.getParent()) { context.exception = e; } throw new ParseCancellationException(e); }
private static GlobNode parse(ANTLRInputStream input) throws GlobParseException { GlobLexer lexer = new GlobLexer(input); CommonTokenStream tokenStream = new CommonTokenStream(lexer); GlobParser parser = new GlobParser(tokenStream); parser.setErrorHandler(new BailErrorStrategy()); ParseTreeWalker walker = new ParseTreeWalker(); GlobListener listener = new GlobListener(); try { walker.walk(listener, parser.rootGlob()); } catch (ParseCancellationException e) { RecognitionException ex = ((RecognitionException) e.getCause()); throw new GlobParseException("Unable to parse glob: Error at token " + ex.getOffendingToken().getText() + " at position " + ex.getOffendingToken().getLine() + ":" + ex.getOffendingToken().getCharPositionInLine(), ex); } return listener.popNode(); }
public ParseCancellationException(String message, Throwable cause) { super(message); initCause(cause); }
@Override public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) { throw new ParseCancellationException(msg, e); } });