@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));
}
java类org.antlr.v4.runtime.ANTLRErrorListener的实例源码
ParserModule.java 文件源码
项目:protostuff-compiler
阅读 21
收藏 0
点赞 0
评论 0
ANTLRParseTreeToPSIConverter.java 文件源码
项目:jetbrains
阅读 18
收藏 0
点赞 0
评论 0
public ANTLRParseTreeToPSIConverter(Language language, Parser parser, PsiBuilder builder) {
this.language = language;
this.builder = builder;
this.tokenElementTypes = PSIElementTypeFactory.getTokenIElementTypes(language);
this.ruleElementTypes = PSIElementTypeFactory.getRuleIElementTypes(language);
for (ANTLRErrorListener listener : parser.getErrorListeners()) {
if (listener instanceof SyntaxErrorListener) {
syntaxErrors = ((SyntaxErrorListener)listener).getSyntaxErrors();
for (SyntaxError error : syntaxErrors) {
// record first error per token
int StartIndex = error.getOffendingSymbol().getStartIndex();
if ( !tokenToErrorMap.containsKey(StartIndex) ) {
tokenToErrorMap.put(StartIndex, error);
}
}
}
}
}
PSHDLParser.java 文件源码
项目:org.pshdl
阅读 18
收藏 0
点赞 0
评论 0
private static HDLPackage parseStream(CharStream input, String libURI, final Set<Problem> syntaxProblems, String src) {
final PSHDLLangLexer lexer = new PSHDLLangLexer(input);
final CommonTokenStream tokens = new CommonTokenStream(lexer);
final PSHDLLang parser = new PSHDLLang(tokens);
final ANTLRErrorListener listener = new SyntaxErrorCollector(tokens, syntaxProblems);
lexer.removeErrorListeners();
lexer.addErrorListener(listener);
parser.removeErrorListeners();
parser.addErrorListener(listener);
final PsModelContext psModel = parser.psModel();
if (syntaxProblems.size() == 0) {
final HDLPackage hdl = ParserToModelExtension.toHDL(tokens, psModel, libURI, src);
return hdl;
}
return null;
}
PSHDLParser.java 文件源码
项目:org.pshdl
阅读 15
收藏 0
点赞 0
评论 0
private static HDLExpression parseExpressionStream(CharStream input, final Set<Problem> syntaxProblems) {
final PSHDLLangLexer lexer = new PSHDLLangLexer(input);
final CommonTokenStream tokens = new CommonTokenStream(lexer);
final ANTLRErrorListener parserListener = new SyntaxErrorCollector(tokens, syntaxProblems);
final PSHDLLang parser = new PSHDLLang(tokens);
parser.removeErrorListeners();
parser.addErrorListener(parserListener);
lexer.removeErrorListeners();
lexer.addErrorListener(parserListener);
final PsExpressionContext psExpression = parser.psExpression();
if (syntaxProblems.size() == 0) {
final HDLExpression hdl = ParserToModelExtension.toHDLExpression(tokens, psExpression);
return hdl;
}
return null;
}
AbstractTemplatesTest.java 文件源码
项目:queryj
阅读 18
收藏 0
点赞 0
评论 0
/**
* Sets up the Java parser.
* @param javaFile the Java contents to parse.
* @return the {@link JavaParser} instance.
* @throws RecognitionException if the format is invalid.
* @throws IOException if the source cannot be read.
*/
@SuppressWarnings("unchecked")
@NotNull
protected JavaParser setUpParser(@NotNull final File javaFile)
throws RecognitionException,
IOException
{
@NotNull final JavaParser result;
@NotNull final JavaLexer t_Lexer =
new JavaLexer(new ANTLRFileStream(javaFile.getAbsolutePath()));
@NotNull final ANTLRErrorListener errorListener = new PropagatingErrorListener(javaFile);
t_Lexer.addErrorListener(errorListener);
@NotNull final CommonTokenStream t_Tokens = new CommonTokenStream(t_Lexer);
result = new JavaParser(t_Tokens);
result.addErrorListener(errorListener);
return result;
}
AstBuilderListener.java 文件源码
项目:intellij-plugin-v4
阅读 21
收藏 0
点赞 0
评论 0
public AstBuilderListener(Language language, Parser parser, PsiBuilder builder) {
this.language = language;
this.builder = builder;
this.tokenElementTypes = PSIElementTypeFactory.getTokenIElementTypes(language, Arrays.asList(parser.getTokenNames()));
this.ruleElementTypes = PSIElementTypeFactory.getRuleIElementTypes(language, Arrays.asList(parser.getRuleNames()));
for (ANTLRErrorListener listener : parser.getErrorListeners()) {
if (listener instanceof SyntaxErrorListener) {
syntaxErrors.addAll(((SyntaxErrorListener)listener).getSyntaxErrors());
}
}
Collections.sort(syntaxErrors, new Comparator<SyntaxError>() {
@Override
public int compare(SyntaxError o1, SyntaxError o2) {
return Integer.valueOf(getStart(o1)).compareTo(getStart(o2));
}
});
}
JSSDParserFactory.java 文件源码
项目:libraries
阅读 17
收藏 0
点赞 0
评论 0
public JSSDParser create(final JSSDLexer lexer, final ANTLRErrorListener errorListener) {
if (errorListener != null) {
lexer.removeErrorListeners();
}
lexer.addErrorListener(errorListener);
final JSSDParser parser = new JSSDParser(new CommonTokenStream(lexer));
if (errorListener != null) {
parser.removeErrorListeners();
}
parser.addErrorListener(errorListener);
return parser;
}
AntlrHelper.java 文件源码
项目:jmespath-java
阅读 14
收藏 0
点赞 0
评论 0
public static JmesPathParser createParser(String input, ANTLRErrorListener errorListener) {
JmesPathLexer lexer = createLexer(input, errorListener);
CommonTokenStream tokens = new CommonTokenStream(lexer);
JmesPathParser parser = new JmesPathParser(tokens);
parser.removeErrorListener(ConsoleErrorListener.INSTANCE);
parser.addErrorListener(errorListener);
parser.setBuildParseTree(true);
return parser;
}
ECParserResult.java 文件源码
项目:netbeans-editorconfig-editor
阅读 16
收藏 0
点赞 0
评论 0
public List<SyntaxError> getErrors() {
List<? extends ANTLRErrorListener> errorListeners = parser.getErrorListeners();
for (ANTLRErrorListener errorListener : errorListeners) {
if (errorListener instanceof EditorConfigErrorListener) {
EditorConfigErrorListener ecErrorListener = (EditorConfigErrorListener) errorListener;
return ecErrorListener.getErrorMessages();
}
}
return Collections.emptyList();
}
TestArithmeticParser.java 文件源码
项目:arithmetic
阅读 20
收藏 0
点赞 0
评论 0
public static ProgramContext parseProgram(String program, ANTLRErrorListener errorListener) throws IOException
{
CharStream inputCharStream = new ANTLRInputStream(new StringReader(program));
TokenSource tokenSource = new ArithmeticLexer(inputCharStream);
TokenStream inputTokenStream = new CommonTokenStream(tokenSource);
ArithmeticParser parser = new ArithmeticParser(inputTokenStream);
parser.addErrorListener(errorListener);
ProgramContext context = parser.program();
return context;
}
AstBuilder.java 文件源码
项目:groovy
阅读 18
收藏 0
点赞 0
评论 0
private ANTLRErrorListener createANTLRErrorListener() {
return new ANTLRErrorListener() {
@Override
public void syntaxError(
Recognizer recognizer,
Object offendingSymbol, int line, int charPositionInLine,
String msg, RecognitionException e) {
collectSyntaxError(new SyntaxException(msg, line, charPositionInLine + 1));
}
};
}
STLexer.java 文件源码
项目:jetbrains-plugin-st4
阅读 19
收藏 0
点赞 0
评论 0
public void lexerError(int start, int stop) {
System.err.println("ST lexerError " + start + ".." + stop);
ANTLRErrorListener listener = getErrorListenerDispatch();
final String text = input.getText(Interval.of(start, stop));
final Token t = newToken(Token.INVALID_TYPE, text, start, stop, getLine(), getCharPositionInLine());
listener.syntaxError(this, t, getLine(), getCharPositionInLine(),
"Bad char or token error in template: "+ text, null);
}
ECParserResult.java 文件源码
项目:editorconfig-netbeans
阅读 19
收藏 0
点赞 0
评论 0
public List<SyntaxError> getErrors() {
List<? extends ANTLRErrorListener> errorListeners = parser.getErrorListeners();
for (ANTLRErrorListener errorListener : errorListeners) {
if (errorListener instanceof EditorConfigErrorListener) {
EditorConfigErrorListener ecErrorListener = (EditorConfigErrorListener) errorListener;
return ecErrorListener.getErrorMessages();
}
}
return Collections.emptyList();
}
Parser.java 文件源码
项目:sfera
阅读 19
收藏 0
点赞 0
评论 0
/**
* Builds a {@link SferaScriptGrammarParser} for the specified input and
* with the specified error listener.
*
* @param input
* the input
* @param errorListener
* the error listener
* @return the built parser
*/
private static SferaScriptGrammarParser getParser(CharStream input,
ANTLRErrorListener errorListener) {
SferaScriptGrammarLexer lexer = new SferaScriptGrammarLexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
SferaScriptGrammarParser parser = new SferaScriptGrammarParser(tokens);
lexer.removeErrorListeners();
lexer.addErrorListener(errorListener);
parser.removeErrorListeners();
parser.addErrorListener(errorListener);
return parser;
}
DocParser.java 文件源码
项目:jooby
阅读 27
收藏 0
点赞 0
评论 0
public List<DocItem> collect(Path file) throws IOException {
this.file = file;
doc = new ArrayList<>();
CharStream input = CharStreams.fromPath(file, StandardCharsets.UTF_8);
FuzzyDocLexer lexer = new FuzzyDocLexer(input);
ANTLRErrorListener error = errorListener(LoggerFactory.getLogger(DocCollector.class), file);
lexer.removeErrorListeners();
lexer.addErrorListener(error);
TokenStream tokens = new CommonTokenStream(lexer);
FuzzyDocParser parser = new FuzzyDocParser(tokens);
parser.removeErrorListeners();
parser.addErrorListener(error);
ParseTreeWalker.DEFAULT.walk(this, parser.source());
return doc;
}
DocParser.java 文件源码
项目:jooby
阅读 14
收藏 0
点赞 0
评论 0
private static ANTLRErrorListener errorListener(final Logger log, Path file) {
return new BaseErrorListener() {
@Override
public void syntaxError(final Recognizer<?, ?> recognizer, final Object offendingSymbol,
final int line,
final int charPositionInLine, final String msg, final RecognitionException e) {
log.debug("{}:{}:{} {}", file, line, charPositionInLine, msg);
}
};
}
DocParser.java 文件源码
项目:jooby
阅读 38
收藏 0
点赞 0
评论 0
private static JavadocParser.DocumentationContext parseJavadoc(Path file, String doc) {
ANTLRErrorListener error = errorListener(LoggerFactory.getLogger(DocCollector.class), file);
CharStream stream = CharStreams.fromString(doc == null ? "" : doc);
JavadocLexer lexer = new JavadocLexer(stream);
lexer.removeErrorListeners();
lexer.addErrorListener(error);
CommonTokenStream tokens = new CommonTokenStream(lexer);
JavadocParser parser = new JavadocParser(tokens);
parser.removeErrorListeners();
parser.addErrorListener(error);
return parser.documentation();
}
JSSDParserFactory.java 文件源码
项目:libraries
阅读 15
收藏 0
点赞 0
评论 0
public JSSDParser create(final InputStream inputStream, final String encoding, final ANTLRErrorListener errorListener)
throws IOException {
return create(new InputStreamReader(inputStream, encoding), errorListener);
}
JSSDParserFactory.java 文件源码
项目:libraries
阅读 16
收藏 0
点赞 0
评论 0
public JSSDParser create(final Reader reader, final ANTLRErrorListener errorListener) throws IOException {
return create(CharStreams.fromReader(reader), errorListener);
}
JSSDParserFactory.java 文件源码
项目:libraries
阅读 16
收藏 0
点赞 0
评论 0
public JSSDParser create(final CharStream stream, final ANTLRErrorListener errorListener) {
return create(new JSSDLexer(stream), errorListener);
}
AntlrHelper.java 文件源码
项目:jmespath-java
阅读 15
收藏 0
点赞 0
评论 0
private static JmesPathLexer createLexer(String input, ANTLRErrorListener errorListener) {
JmesPathLexer lexer = new JmesPathLexer(new ANTLRInputStream(input));
lexer.removeErrorListener(ConsoleErrorListener.INSTANCE);
lexer.addErrorListener(errorListener);
return lexer;
}
Program.java 文件源码
项目:eo
阅读 19
收藏 0
点赞 0
评论 0
/**
* Compile it to Java and save.
* @throws IOException If fails
*/
public void compile() throws IOException {
final String[] lines = new TextOf(this.input).asString().split("\n");
final ANTLRErrorListener errors = new BaseErrorListener() {
// @checkstyle ParameterNumberCheck (10 lines)
@Override
public void syntaxError(final Recognizer<?, ?> recognizer,
final Object symbol, final int line,
final int position, final String msg,
final RecognitionException error) {
throw new CompileException(
String.format(
"[%d:%d] %s: \"%s\"",
line, position, msg, lines[line - 1]
),
error
);
}
};
final ProgramLexer lexer = new ProgramLexer(
CharStreams.fromStream(this.input.stream())
);
lexer.removeErrorListeners();
lexer.addErrorListener(errors);
final ProgramParser parser = new ProgramParser(
new CommonTokenStream(lexer)
);
parser.removeErrorListeners();
parser.addErrorListener(errors);
final Tree tree = parser.program().ret;
new IoCheckedScalar<>(
new And(
tree.java().entrySet(),
path -> {
new LengthOf(
new TeeInput(
path.getValue(),
this.target.apply(path.getKey())
)
).value();
}
)
).value();
}
FileDescriptorLoaderImpl.java 文件源码
项目:protostuff-compiler
阅读 16
收藏 0
点赞 0
评论 0
@Inject
public FileDescriptorLoaderImpl(ANTLRErrorListener errorListener, Set<ProtoContextPostProcessor> postProcessors) {
this.errorListener = errorListener;
this.postProcessors = postProcessors;
}
Builder.java 文件源码
项目:ecmascript-parser
阅读 18
收藏 0
点赞 0
评论 0
public Lexer withErrorListener(ANTLRErrorListener listener) {
this.lexer.removeErrorListeners();
this.lexer.addErrorListener(listener);
return this;
}
Builder.java 文件源码
项目:ecmascript-parser
阅读 25
收藏 0
点赞 0
评论 0
public Parser withErrorListener(ANTLRErrorListener listener) {
this.parser.removeErrorListeners();
this.parser.addErrorListener(listener);
return this;
}
ConfigurationParser.java 文件源码
项目:rocana-configuration
阅读 24
收藏 0
点赞 0
评论 0
public <T> T parse(Reader reader, Class<T> targetType) throws IOException {
logger.debug("Parsing configuration for type:{}", targetType);
ANTLRErrorListener listener = new BaseErrorListener() {
@Override
public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) {
throw new ConfigurationException(String.format("Unable to parse configuration: %s (at line:%s pos:%s)", msg, line, charPositionInLine), e);
}
};
TypeDescriptor typeDescriptor = TypeMapping.ofType(targetType);
ANTLRInputStream inputStream = new ANTLRInputStream(reader);
ConfigurationLexer lexer = new ConfigurationLexer(inputStream);
lexer.removeErrorListeners();
lexer.addErrorListener(listener);
CommonTokenStream tokenStream = new CommonTokenStream(lexer);
com.rocana.configuration.antlr.ConfigurationParser parser = new com.rocana.configuration.antlr.ConfigurationParser(tokenStream);
parser.removeErrorListeners();
parser.addErrorListener(listener);
ParseTree parseTree = parser.config();
logger.debug("Parsed configuration:{}", parseTree.toStringTree(parser));
Visitor<T> visitor = new Visitor<>(typeDescriptor);
visitor.visit(parseTree);
logger.debug("Configured object:{}", visitor.getResult());
return visitor.getResult();
}
Parser.java 文件源码
项目:sfera
阅读 23
收藏 0
点赞 0
评论 0
/**
* Builds a {@link SferaScriptGrammarParser} for the specified reader and
* with the specified error listener.
*
* @param r
* the reader
* @param errorListener
* the error listener
* @return the built parser
* @throws IOException
* if an I/O error occurs
*/
public static SferaScriptGrammarParser getParser(Reader r, ANTLRErrorListener errorListener)
throws IOException {
return getParser(new ANTLRInputStream(r), errorListener);
}