本文整理匯總了Java中org.antlr.v4.runtime.ANTLRErrorListener類的典型用法代碼示例。如果您正苦於以下問題:Java ANTLRErrorListener類的具體用法?Java ANTLRErrorListener怎麽用?Java ANTLRErrorListener使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ANTLRErrorListener類屬於org.antlr.v4.runtime包,在下文中一共展示了ANTLRErrorListener類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: configure
import org.antlr.v4.runtime.ANTLRErrorListener; //導入依賴的package包/類
@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));
}
示例2: ANTLRParseTreeToPSIConverter
import org.antlr.v4.runtime.ANTLRErrorListener; //導入依賴的package包/類
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);
}
}
}
}
}
示例3: parseStream
import org.antlr.v4.runtime.ANTLRErrorListener; //導入依賴的package包/類
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;
}
示例4: parseExpressionStream
import org.antlr.v4.runtime.ANTLRErrorListener; //導入依賴的package包/類
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;
}
示例5: setUpParser
import org.antlr.v4.runtime.ANTLRErrorListener; //導入依賴的package包/類
/**
* 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;
}
示例6: AstBuilderListener
import org.antlr.v4.runtime.ANTLRErrorListener; //導入依賴的package包/類
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));
}
});
}
示例7: create
import org.antlr.v4.runtime.ANTLRErrorListener; //導入依賴的package包/類
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;
}
示例8: createParser
import org.antlr.v4.runtime.ANTLRErrorListener; //導入依賴的package包/類
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;
}
示例9: getErrors
import org.antlr.v4.runtime.ANTLRErrorListener; //導入依賴的package包/類
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();
}
示例10: parseProgram
import org.antlr.v4.runtime.ANTLRErrorListener; //導入依賴的package包/類
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;
}
示例11: createANTLRErrorListener
import org.antlr.v4.runtime.ANTLRErrorListener; //導入依賴的package包/類
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));
}
};
}
示例12: lexerError
import org.antlr.v4.runtime.ANTLRErrorListener; //導入依賴的package包/類
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);
}
示例13: getErrors
import org.antlr.v4.runtime.ANTLRErrorListener; //導入依賴的package包/類
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();
}
示例14: getParser
import org.antlr.v4.runtime.ANTLRErrorListener; //導入依賴的package包/類
/**
* 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;
}
示例15: collect
import org.antlr.v4.runtime.ANTLRErrorListener; //導入依賴的package包/類
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;
}