当前位置: 首页>>代码示例>>Java>>正文


Java BailErrorStrategy类代码示例

本文整理汇总了Java中org.antlr.v4.runtime.BailErrorStrategy的典型用法代码示例。如果您正苦于以下问题:Java BailErrorStrategy类的具体用法?Java BailErrorStrategy怎么用?Java BailErrorStrategy使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


BailErrorStrategy类属于org.antlr.v4.runtime包,在下文中一共展示了BailErrorStrategy类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: newParser

import org.antlr.v4.runtime.BailErrorStrategy; //导入依赖的package包/类
public static <L extends Lexer, P extends Parser> P newParser(
    Function<CharStream, L> lexerFactory,
    Function<TokenStream, P> parserFactory,
    String input,
    boolean useBailErrorStrategy,
    boolean removeErrorListeners) {
  CharStream charStream = new ANTLRInputStream(input);
  L lexer = lexerFactory.apply(charStream);
  if (removeErrorListeners) {
    lexer.removeErrorListeners();
  }

  TokenStream tokenStream = new CommonTokenStream(lexer);
  P parser = parserFactory.apply(tokenStream);
  if (useBailErrorStrategy) {
    parser.setErrorHandler(new BailErrorStrategy());
  }
  if (removeErrorListeners) {
    parser.removeErrorListeners();
  }

  return parser;
}
 
开发者ID:nkouevda,项目名称:antlr-examples,代码行数:24,代码来源:ParserUtil.java

示例2: readMatrix

import org.antlr.v4.runtime.BailErrorStrategy; //导入依赖的package包/类
private Object readMatrix(List<Object> parameters) {
  String rationalString = in.nextLine();

  MatrixLexer matrixLexer = new MatrixLexer(new ANTLRInputStream(rationalString));

  MatrixParser matrixParser = new MatrixParser(new CommonTokenStream(matrixLexer));

  matrixParser.setErrorHandler(new BailErrorStrategy());

  try {
    MatrixParser.MatrixContext matrixContext = matrixParser.matrix();

    return Matrix.fromMatrixContext(matrixContext, Scope.NULL_SCOPE);
  } catch (ParseCancellationException e) {
    throw new InvalidReadRuntimeError("Invalid input read from stdin! Expected matrix format!");
  }
}
 
开发者ID:daergoth,项目名称:MatrixC,代码行数:18,代码来源:InputOutputDeclarationSource.java

示例3: parse

import org.antlr.v4.runtime.BailErrorStrategy; //导入依赖的package包/类
static MysqlParser.ScriptContext parse(CharStream cs) {
    MysqlLexer lexer = new MysqlLexer(cs);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    tokens.setTokenSource(lexer);
    MysqlParser parser = new MysqlParser(tokens);
    parser.setErrorHandler(new BailErrorStrategy());
    boolean success = false;
    try {
        MysqlParser.ScriptContext script = parser.script();
        success = true;
        return script;
    }
    finally {
        if (!success && (parser.lastStatement != null)) {
            _log.debug("last passed statement: {}", ((ParseTree)parser.lastStatement).getText());
        }
    }
}
 
开发者ID:waterguo,项目名称:antsdb,代码行数:19,代码来源:MysqlParserFactory.java

示例4: compileFiles

import org.antlr.v4.runtime.BailErrorStrategy; //导入依赖的package包/类
private void compileFiles(List<RawFile> files, OOPSourceCodeModel srcModel, List<String> projectFileTypes) {
    for (RawFile file : files) {
        try {
            CharStream charStream = new ANTLRInputStream(file.content());
            GolangLexer lexer = new GolangLexer(charStream);
            TokenStream tokens = new CommonTokenStream(lexer);
            GolangParser parser = new GolangParser(tokens);
            SourceFileContext sourceFileContext = parser.sourceFile();
            parser.setErrorHandler(new BailErrorStrategy());
            parser.getInterpreter().setPredictionMode(PredictionMode.SLL);
            ParseTreeWalker walker = new ParseTreeWalker();
            GolangBaseListener listener = new GoLangTreeListener(srcModel, projectFileTypes, file);
            walker.walk(listener, sourceFileContext);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
 
开发者ID:Zir0-93,项目名称:clarpse,代码行数:19,代码来源:ClarpseGoCompiler.java

示例5: parse

import org.antlr.v4.runtime.BailErrorStrategy; //导入依赖的package包/类
public static Program parse(String source) {
	RankPLLexer lexer = new RankPLLexer(new ANTLRInputStream(source));
	TokenStream tokens = new CommonTokenStream(lexer);
	RankPLParser parser = new RankPLParser(tokens);
	parser.setErrorHandler(new BailErrorStrategy());
	ConcreteParser classVisitor = new ConcreteParser();

	// Parse
	Program program = null;
	try {
		program = (Program) classVisitor.visit(parser.program());
	} catch (ParseCancellationException e) {
		System.out.println("Syntax error");
		lexer = new RankPLLexer(new ANTLRInputStream(source));
		tokens = new CommonTokenStream(lexer);
		parser = new RankPLParser(tokens);
		classVisitor = new ConcreteParser();
		try {
			program = (Program) classVisitor.visit(parser.program());
		} catch (Exception ex) {
			// Ignore
		}
		return null;
	}
	return program;
}
 
开发者ID:tjitze,项目名称:RankPL,代码行数:27,代码来源:RankPL.java

示例6: configure

import org.antlr.v4.runtime.BailErrorStrategy; //导入依赖的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

示例7: parseEnumBlock

import org.antlr.v4.runtime.BailErrorStrategy; //导入依赖的package包/类
private Enum parseEnumBlock(String input) {
    CharStream stream = CharStreams.fromString(input);
    ProtoLexer lexer = new ProtoLexer(stream);
    lexer.removeErrorListeners();
    lexer.addErrorListener(TestUtils.ERROR_LISTENER);
    CommonTokenStream tokenStream = new CommonTokenStream(lexer);
    ProtoParser parser = new ProtoParser(tokenStream);
    parser.setErrorHandler(new BailErrorStrategy());
    parser.removeErrorListeners();
    parser.addErrorListener(TestUtils.ERROR_LISTENER);
    ProtoContext context = new ProtoContext("test.proto");
    Proto proto = new Proto();
    context.push(proto);
    EnumParseListener enumParseListener = new EnumParseListener(tokenStream, context);
    OptionParseListener optionParseListener = new OptionParseListener(tokenStream, context);
    parser.addParseListener(enumParseListener);
    parser.addParseListener(optionParseListener);
    parser.enumBlock();
    return proto.getEnums().get(0);
}
 
开发者ID:protostuff,项目名称:protostuff-compiler,代码行数:21,代码来源:EnumParseListenerTest.java

示例8: can_parse_an_interface_with_extends_and_a_single_method

import org.antlr.v4.runtime.BailErrorStrategy; //导入依赖的package包/类
@Test public void can_parse_an_interface_with_extends_and_a_single_method()
    throws Exception {
    String input =
        "public interface Resolver\n"
        + "    extends Serializable {\n\n"

        + "    public int resolve(String value);\n"
        + "}\n";

    Java8Lexer lexer = new Java8Lexer(new ANTLRInputStream(input));

    CommonTokenStream tokens = new CommonTokenStream(lexer);

    Java8Parser parser = new Java8Parser(tokens);
    parser.setErrorHandler(new BailErrorStrategy());
    ParseTree ast = parser.compilationUnit();
    Assert.assertNotNull(ast);
}
 
开发者ID:rydnr,项目名称:JavaCSS,代码行数:19,代码来源:Java8ParserTest.java

示例9: parses_a_simple_input

import org.antlr.v4.runtime.BailErrorStrategy; //导入依赖的package包/类
@Test
public void parses_a_simple_input() {
    String input =
        ".packageDeclaration #identifier::before {\n"
      + "    content: \"  \";\n"
      + "}\n";

    StringTemplateCSSLexer lexer = new StringTemplateCSSLexer(new ANTLRInputStream(input));

    CommonTokenStream tokens = new CommonTokenStream(lexer);

    StringTemplateCSSParser parser = new StringTemplateCSSParser(tokens);
    parser.setErrorHandler(new BailErrorStrategy());
    ParseTree ast = parser.css();
    Assert.assertNotNull(ast);
}
 
开发者ID:rydnr,项目名称:JavaCSS,代码行数:17,代码来源:StringTemplateCSSParserTest.java

示例10: parses_another_simple_input

import org.antlr.v4.runtime.BailErrorStrategy; //导入依赖的package包/类
@Test
public void parses_another_simple_input() {
    String input =
          "  .packageDeclaration \";\"::after {\n"
        + "    content: \"\\n\\n\";\n"
        + "  }";

    StringTemplateCSSLexer lexer = new StringTemplateCSSLexer(new ANTLRInputStream(input));

    CommonTokenStream tokens = new CommonTokenStream(lexer);

    StringTemplateCSSParser parser = new StringTemplateCSSParser(tokens);
    parser.setErrorHandler(new BailErrorStrategy());
    ParseTree ast = parser.css();
    Assert.assertNotNull(ast);
}
 
开发者ID:rydnr,项目名称:JavaCSS,代码行数:17,代码来源:StringTemplateCSSParserTest.java

示例11: parse

import org.antlr.v4.runtime.BailErrorStrategy; //导入依赖的package包/类
/**
 * Compile request to AST.
 *
 * @param path request
 * @return AST parse tree
 */
public static ParseTree parse(String path) {
    String normalizedPath = Paths.get(path).normalize().toString().replace(File.separatorChar, '/');
    if (normalizedPath.startsWith("/")) {
        normalizedPath = normalizedPath.substring(1);
    }
    ANTLRInputStream is = new ANTLRInputStream(normalizedPath);
    CoreLexer lexer = new CoreLexer(is);
    lexer.removeErrorListeners();
    lexer.addErrorListener(new BaseErrorListener() {
        @Override
        public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line,
                                int charPositionInLine, String msg, RecognitionException e) {
            throw new ParseCancellationException(msg, e);
        }
    });
    CoreParser parser = new CoreParser(new CommonTokenStream(lexer));
    parser.setErrorHandler(new BailErrorStrategy());
    return parser.start();
}
 
开发者ID:yahoo,项目名称:elide,代码行数:26,代码来源:Elide.java

示例12: parse

import org.antlr.v4.runtime.BailErrorStrategy; //导入依赖的package包/类
/**
 * Compile request to AST.
 * @param path request
 * @return AST
 */
public static ParseTree parse(String path) {
    ANTLRInputStream is = new ANTLRInputStream(path);
    CoreLexer lexer = new CoreLexer(is);
    lexer.removeErrorListeners();
    lexer.addErrorListener(new BaseErrorListener() {
        @Override
        public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line,
                int charPositionInLine, String msg, RecognitionException e) {
            throw new ParseCancellationException(e);
        }
    });
    CoreParser parser = new CoreParser(new CommonTokenStream(lexer));
    parser.setErrorHandler(new BailErrorStrategy());
    return parser.start();
}
 
开发者ID:yahoo,项目名称:elide,代码行数:21,代码来源:JsonApiParser.java

示例13: parseExpression

import org.antlr.v4.runtime.BailErrorStrategy; //导入依赖的package包/类
public static ParseTree parseExpression(String expression) {
    ANTLRInputStream is = new ANTLRInputStream(expression);
    ExpressionLexer lexer = new ExpressionLexer(is);
    lexer.removeErrorListeners();
    lexer.addErrorListener(new BaseErrorListener() {
        @Override
        public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line,
                                int charPositionInLine, String msg, RecognitionException e) {
            throw new ParseCancellationException(msg, e);
        }
    });
    ExpressionParser parser = new ExpressionParser(new CommonTokenStream(lexer));
    parser.setErrorHandler(new BailErrorStrategy());
    lexer.reset();
    return parser.start();
}
 
开发者ID:yahoo,项目名称:elide,代码行数:17,代码来源:EntityPermissions.java

示例14: testParseWorkingExamples

import org.antlr.v4.runtime.BailErrorStrategy; //导入依赖的package包/类
@Test
public void testParseWorkingExamples() throws IOException {
	FileVisitor<Path> workingFilesVisitior = new SimpleFileVisitor<Path>() {
		@Override
		public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
			System.out.println("Testing parser input from file \""+file.toString()+"\"");
			ANTLRFileStream antlrStream = new ANTLRFileStream(file.toString());
			MiniJLexer lexer = new MiniJLexer(antlrStream);
			TokenStream tokens = new CommonTokenStream(lexer);
			MiniJParser parser = new MiniJParser(tokens);
			parser.setErrorHandler(new BailErrorStrategy());
			parser.prog();
			return super.visitFile(file, attrs);
		}
	};
	Files.walkFileTree(EXAMPLE_PROGRAM_PATH_WORKING, workingFilesVisitior);
}
 
开发者ID:tiborgo,项目名称:MiniJCompiler,代码行数:18,代码来源:MiniJParserTest.java

示例15: testParseFailingExamples

import org.antlr.v4.runtime.BailErrorStrategy; //导入依赖的package包/类
@Test
public void testParseFailingExamples() throws IOException {
	FileVisitor<Path> workingFilesVisitior = new SimpleFileVisitor<Path>() {
		@Override
		public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
			System.out.println("Testing parser input from file \""+file.toString()+"\"");
			ANTLRFileStream antlrStream = new ANTLRFileStream(file.toString());
			MiniJLexer lexer = new MiniJLexer(antlrStream);
			TokenStream tokens = new CommonTokenStream(lexer);
			MiniJParser parser = new MiniJParser(tokens);
			parser.setErrorHandler(new BailErrorStrategy());
			/*
			 * Catch all exceptions first, to ensure that every single
			 * compilation unit exits with an Exception. Otherwise, this
			 * method will return after the first piece of code.
			 */
			try {
				parser.prog();
				fail("The example "+file.toString()+" should have failed, but was accepted by the parser.");
			} catch (ParseCancellationException e) {
			}
			return super.visitFile(file, attrs);
		}
	};
	Files.walkFileTree(EXAMPLE_PROGRAM_PATH_FAILING, workingFilesVisitior);
}
 
开发者ID:tiborgo,项目名称:MiniJCompiler,代码行数:27,代码来源:MiniJParserTest.java


注:本文中的org.antlr.v4.runtime.BailErrorStrategy类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。