當前位置: 首頁>>代碼示例>>Java>>正文


Java ANTLRErrorListener類代碼示例

本文整理匯總了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));
}
 
開發者ID:protostuff,項目名稱:protostuff-compiler,代碼行數:24,代碼來源:ParserModule.java

示例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);
				}
			}
		}
	}
}
 
開發者ID:antlr,項目名稱:jetbrains,代碼行數:21,代碼來源:ANTLRParseTreeToPSIConverter.java

示例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;
}
 
開發者ID:pshdl,項目名稱:org.pshdl,代碼行數:17,代碼來源:PSHDLParser.java

示例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;
}
 
開發者ID:pshdl,項目名稱:org.pshdl,代碼行數:17,代碼來源:PSHDLParser.java

示例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;
}
 
開發者ID:rydnr,項目名稱:queryj,代碼行數:31,代碼來源:AbstractTemplatesTest.java

示例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));
		}
	});
}
 
開發者ID:antlr,項目名稱:intellij-plugin-v4,代碼行數:22,代碼來源:AstBuilderListener.java

示例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;
}
 
開發者ID:AndreasWBartels,項目名稱:libraries,代碼行數:13,代碼來源:JSSDParserFactory.java

示例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;
}
 
開發者ID:burtcorp,項目名稱:jmespath-java,代碼行數:10,代碼來源:AntlrHelper.java

示例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();
}
 
開發者ID:junichi11,項目名稱:netbeans-editorconfig-editor,代碼行數:11,代碼來源:ECParserResult.java

示例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;
}
 
開發者ID:Rospaccio,項目名稱:arithmetic,代碼行數:11,代碼來源:TestArithmeticParser.java

示例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));
        }
    };
}
 
開發者ID:apache,項目名稱:groovy,代碼行數:13,代碼來源:AstBuilder.java

示例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);
}
 
開發者ID:antlr,項目名稱:jetbrains-plugin-st4,代碼行數:9,代碼來源:STLexer.java

示例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();
}
 
開發者ID:welovecoding,項目名稱:editorconfig-netbeans,代碼行數:11,代碼來源:ECParserResult.java

示例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;
}
 
開發者ID:sfera-labs,項目名稱:sfera,代碼行數:24,代碼來源:Parser.java

示例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;
}
 
開發者ID:jooby-project,項目名稱:jooby,代碼行數:16,代碼來源:DocParser.java


注:本文中的org.antlr.v4.runtime.ANTLRErrorListener類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。