@Override public CompileStatus compile(Path path) throws CompileException { try { return compile(CharStreams.fromPath(path)); } catch (IOException e) { throw new CompileException(e.getMessage(), e); } catch (Exception e) { throw new CompileException(e.getMessage(), e); } }
throw new DirectiveParseException(e.getMessage(), e.iterator()); } catch (IllegalAccessException | InstantiationException e) { throw new DirectiveParseException(e.getMessage());
@Override public CompileStatus compile(Location location) throws CompileException { try { return compile(CharStreams.fromStream(location.getInputStream())); } catch (IOException e) { throw new CompileException(e.getMessage(), e); } catch (Exception e) { throw new CompileException(e.getMessage(), e); } }
private CompileStatus compile(CharStream stream) throws CompileException { try { SyntaxErrorListener errorListener = new SyntaxErrorListener(); DirectivesLexer lexer = new DirectivesLexer(stream); lexer.removeErrorListeners(); lexer.addErrorListener(errorListener); DirectivesParser parser = new DirectivesParser(new CommonTokenStream(lexer)); parser.removeErrorListeners(); parser.addErrorListener(errorListener); parser.setErrorHandler(new GrammarParserInterpreter.BailButConsumeErrorStrategy()); parser.setBuildParseTree(true); ParseTree tree = parser.statements(); if(errorListener.hasErrors()) { return new CompileStatus(true, errorListener.iterator()); } RecipeVisitor visitor = new RecipeVisitor(); visitor.visit(tree); RecipeSymbol symbol = visitor.getCompiledUnit(); return new CompileStatus(symbol); } catch (StringIndexOutOfBoundsException e) { throw new CompileException("Issue in compiling directives"); } } }