@Override protected void configure() { bind(Importer.class).to(ImporterImpl.class); bind(FileDescriptorLoader.class).to(FileDescriptorLoaderImpl.class); bind(ANTLRErrorListener.class).to(ParseErrorLogger.class); bind(ANTLRErrorStrategy.class).to(BailErrorStrategy.class); bind(ProtoContext.class) .annotatedWith(Names.named(DESCRIPTOR_PROTO)) .toProvider(DefaultDescriptorProtoProvider.class); Multibinder<ProtoContextPostProcessor> postProcessors = Multibinder .newSetBinder(binder(), ProtoContextPostProcessor.class); postProcessors.addBinding().to(ImportsPostProcessor.class); postProcessors.addBinding().to(TypeRegistratorPostProcessor.class); postProcessors.addBinding().to(TypeResolverPostProcessor.class); postProcessors.addBinding().to(ExtensionRegistratorPostProcessor.class); postProcessors.addBinding().to(OptionsPostProcessor.class); postProcessors.addBinding().to(UserTypeValidationPostProcessor.class); install(new FactoryModuleBuilder() .implement(FileReader.class, MultiPathFileReader.class) .build(FileReaderFactory.class)); }
public void syntaxError(Recognizer<?, ?> aRecognizer, Object aOffendingSymbol, int aLine, int aCharIndex, String aMessage, RecognitionException aException) { ANTLRErrorStrategy errorHandler = myParser.getErrorHandler(); if (LOGGER.isWarnEnabled()) { LOGGER.warn(aMessage + " [" + aLine + ":" + aCharIndex + "]"); } /* * Setting the lexer exception in the parser since I don't see a * getNumberOfSyntaxErrors() method in the lexer (like in antlr3) and * the lexer's errors aren't being reported by parser's method * * I may just be missing the correct way this should be handled(?) */ if (aException instanceof LexerNoViableAltException) { NoViableAltException exception = new NoViableAltException(myParser); errorHandler.reportError(myParser, exception); } else { errorHandler.reportError(myParser, aException); } }
Builder(final ANTLRErrorStrategy errorStrategy, final IBaseProtoErrorListener errorListener, final FileDescriptors.Builder fileBuilder) { dirs = new LinkedHashMap<URI, Set<URI>>(); sources = new LinkedHashMap<URI, String>(); sourceProtos = new ArrayList<FileDescriptorProto>(); this.errorStrategy = Objects.requireNonNull(errorStrategy); this.errorListener = Objects.requireNonNull(errorListener); this.fileBuilder = Objects.requireNonNull(fileBuilder); }
Builder(final ANTLRErrorStrategy errorStrategy, final IBaseProtoErrorListener errorListener) { this(errorStrategy, errorListener, FileDescriptors.newBuilder()); }
ErrorStrategy(ANTLRErrorStrategy delegate) { this.delegate = delegate; }
/** * Set the error handler strategy for ANTLR. If not set, {@link DefaultErrorStrategy} is used. * * @param errorStrategy ANTLR error strategy * @return builder */ public Builder setErrorStrategy(ANTLRErrorStrategy errorStrategy) { this.errorStrategy = errorStrategy; return this; }