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


Java BaseErrorListener類代碼示例

本文整理匯總了Java中org.antlr.v4.runtime.BaseErrorListener的典型用法代碼示例。如果您正苦於以下問題:Java BaseErrorListener類的具體用法?Java BaseErrorListener怎麽用?Java BaseErrorListener使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


BaseErrorListener類屬於org.antlr.v4.runtime包,在下文中一共展示了BaseErrorListener類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setupPicky

import org.antlr.v4.runtime.BaseErrorListener; //導入依賴的package包/類
private void setupPicky(PainlessParser parser) {
    // Diagnostic listener invokes syntaxError on other listeners for ambiguity issues,
    parser.addErrorListener(new DiagnosticErrorListener(true));
    // a second listener to fail the test when the above happens.
    parser.addErrorListener(new BaseErrorListener() {
        @Override
        public void syntaxError(final Recognizer<?,?> recognizer, final Object offendingSymbol, final int line,
                                final int charPositionInLine, final String msg, final RecognitionException e) {
            throw new AssertionError("line: " + line + ", offset: " + charPositionInLine +
                ", symbol:" + offendingSymbol + " " + msg);
        }
    });

    // Enable exact ambiguity detection (costly). we enable exact since its the default for
    // DiagnosticErrorListener, life is too short to think about what 'inexact ambiguity' might mean.
    parser.getInterpreter().setPredictionMode(PredictionMode.LL_EXACT_AMBIG_DETECTION);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:18,代碼來源:Walker.java

示例2: parseInputStream

import org.antlr.v4.runtime.BaseErrorListener; //導入依賴的package包/類
private void parseInputStream(CharStream inputStream, OboParseResultListener listener) {
  final OboLexer l = new OboLexer(inputStream);
  final Antlr4OboParser p = new Antlr4OboParser(new CommonTokenStream(l));

  p.addErrorListener(new BaseErrorListener() {
    @Override
    public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line,
        int charPositionInLine, String msg, RecognitionException e) {
      throw new IllegalStateException("Failed to parse at line " + line + " due to " + msg, e);
    }
  });

  if (debug) {
    p.addErrorListener(new DiagnosticErrorListener());
  }

  p.addParseListener(new OboParserListener(listener));

  p.oboFile();
}
 
開發者ID:Phenomics,項目名稱:ontolib,代碼行數:21,代碼來源:OboParser.java

示例3: registerErrorListener

import org.antlr.v4.runtime.BaseErrorListener; //導入依賴的package包/類
public static void registerErrorListener(final CoqFTParser parser) {
    parser.removeErrorListeners();
    parser.addErrorListener(new BaseErrorListener() {
        @Override
        public void syntaxError(Recognizer<?, ?> recognizer,
                Object offendingSymbol,
                int line,
                int charPositionInLine,
                String msg,
                RecognitionException e) {
            throw new CoqSyntaxException(parser,
                    (Token)offendingSymbol, line, charPositionInLine, msg,
                    e);
        }
    });
}
 
開發者ID:jhuapl-saralab,項目名稱:exterminator,代碼行數:17,代碼來源:CoqFTParser.java

示例4: testExampleFieldCondition

import org.antlr.v4.runtime.BaseErrorListener; //導入依賴的package包/類
@Test
public void testExampleFieldCondition() throws Exception {
  ScoreLexer l = new ScoreLexer(CharStreams.fromString(expression));
  ScoreParser p = new ScoreParser(new CommonTokenStream(l));
  p.addErrorListener(new BaseErrorListener() {
    @Override
    public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line,
        int charPositionInLine, String msg, RecognitionException e) {
      throw new IllegalStateException(String.format(
          "Failed to parse at line %d position %d due to %s", line, charPositionInLine, msg), e);
    }
  });
  ScoreTranslator visitor = new ScoreTranslator();
  AnyExpressionContext ctx = p.anyExpression();
  String text = visitor.visitAnyExpression(ctx);
  System.out.println(text);
}
 
開發者ID:FIXTradingCommunity,項目名稱:fix-orchestra,代碼行數:18,代碼來源:ScoreTranslatorTest.java

示例5: testExampleFieldCondition

import org.antlr.v4.runtime.BaseErrorListener; //導入依賴的package包/類
@Test
public void testExampleFieldCondition() throws Exception {
  ScoreLexer l = new ScoreLexer(CharStreams.fromString(fieldCondition));
  ScoreParser p = new ScoreParser(new CommonTokenStream(l));
  p.addErrorListener(new BaseErrorListener() {
    @Override
    public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line,
        int charPositionInLine, String msg, RecognitionException e) {
      throw new IllegalStateException(String.format(
          "Failed to parse at line %d position %d due to %s", line, charPositionInLine, msg), e);
    }
  });
  ScoreBaseVisitor<Object> visitor = new ScoreBaseVisitor<>();
  AnyExpressionContext ctx = p.anyExpression();
  Object expression = visitor.visitAnyExpression(ctx);
  //System.out.println(expression.getClass().getSimpleName());
}
 
開發者ID:FIXTradingCommunity,項目名稱:fix-orchestra,代碼行數:18,代碼來源:DslExpressionTest.java

示例6: compileExpression

import org.antlr.v4.runtime.BaseErrorListener; //導入依賴的package包/類
public Statement compileExpression(String expr, MethodDecl method, ModuleInstance module) throws CompileException {
	VbaLexer lexer = new VbaLexer(new org.antlr.v4.runtime.ANTLRInputStream(expr));

	CommonTokenStream tokenStream = new CommonTokenStream(lexer);
	VbaParser parser = new VbaParser(tokenStream);
	parser.setBuildParseTree(true);
	parser.addErrorListener(new BaseErrorListener() {

		@Override
		public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine,
				String msg, RecognitionException e) {
			// errors.add(new CompileException(new SourceLocation(file, line, charPositionInLine, 0),
			// CompileException.SYNTAX_ERROR, msg, ((CommonToken) offendingSymbol).getText()));
			System.err.println(msg);
		}

	});

	EvalStmtContext eval = parser.evalStmt();
	ParserRuleContext c = (ParserRuleContext) eval.getChild(0);
	if (c instanceof ValueStmtContext) {
		return this.compileValueStatement((ValueStmtContext) c, method).getStatement();
	} else {
		return new BlockCompiler(method, this).compileBlockStatement(c);
	}
}
 
開發者ID:inshua,項目名稱:vba-interpreter,代碼行數:27,代碼來源:Compiler.java

示例7: parse

import org.antlr.v4.runtime.BaseErrorListener; //導入依賴的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

示例8: parse

import org.antlr.v4.runtime.BaseErrorListener; //導入依賴的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

示例9: parseExpression

import org.antlr.v4.runtime.BaseErrorListener; //導入依賴的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

示例10: parseJavadocFromFile

import org.antlr.v4.runtime.BaseErrorListener; //導入依賴的package包/類
private static ParseTree parseJavadocFromFile(File file)
    throws IOException {
    final String content = Files.toString(file, Charsets.UTF_8);
    final InputStream in = new ByteArrayInputStream(content.getBytes(Charsets.UTF_8));

    final ANTLRInputStream input = new ANTLRInputStream(in);
    final JavadocLexer lexer = new JavadocLexer(input);
    lexer.removeErrorListeners();

    final BaseErrorListener errorListener = new FailOnErrorListener();
    lexer.addErrorListener(errorListener);

    final CommonTokenStream tokens = new CommonTokenStream(lexer);

    final JavadocParser parser = new JavadocParser(tokens);
    parser.removeErrorListeners();
    parser.addErrorListener(errorListener);

    return parser.javadoc();
}
 
開發者ID:checkstyle,項目名稱:contribution,代碼行數:21,代碼來源:ExpectedParseTreeGenerator.java

示例11: main

import org.antlr.v4.runtime.BaseErrorListener; //導入依賴的package包/類
public static void main(final String[] args) throws Exception {
    final FileInputStream fileInputStream = new FileInputStream(args[0]);
    final GMLLexer gmlLexer = new GMLLexer(new ANTLRInputStream(fileInputStream));
    final GMLParser gmlParser = new GMLParser(new CommonTokenStream(gmlLexer));
    gmlParser.addErrorListener(new BaseErrorListener() {

        @Override
        public void syntaxError(final Recognizer<?, ?> recognizer, final Object offendingSymbol, final int line,
                final int charPositionInLine, final String message, final RecognitionException exception) {
            throw new RuntimeException(message);
        }

    });
    final GMLExtractor gmlExtractor = new GMLExtractor(gmlParser);
    final GMLInterpreter gmlInterpreter = new GMLInterpreter(gmlExtractor);
    gmlInterpreter.interpret();
}
 
開發者ID:klaushauschild1984,項目名稱:gml-tracer,代碼行數:18,代碼來源:GmlTracer.java

示例12: twelveFactorial

import org.antlr.v4.runtime.BaseErrorListener; //導入依賴的package包/類
@Test
public void twelveFactorial() throws IOException {
    final GMLLexer gmlLexer = new GMLLexer(new ANTLRInputStream(getClass().getResourceAsStream("fact.gml")));
    final GMLParser gmlParser = new GMLParser(new CommonTokenStream(gmlLexer));
    gmlParser.addErrorListener(new BaseErrorListener() {

        @Override
        public void syntaxError(final Recognizer<?, ?> theRecognizer, final Object theOffendingSymbol, final int theLine,
                final int theCharPositionInLine, final String theMsg, final RecognitionException theE) {
            Assert.fail(theMsg);
        }

    });
    final GMLExtractor gmlExtractor = new GMLExtractor(gmlParser);
    final GMLInterpreter gmlInterpreter = new GMLInterpreter(gmlExtractor);
    final Stack<Token> tokenStack = gmlInterpreter.interpret();
    Assert.assertEquals(tokenStack.size(), 1);
    final NumberToken result = (NumberToken) tokenStack.pop();
    Assert.assertEquals(result.getValue(), 479001600d);
}
 
開發者ID:klaushauschild1984,項目名稱:gml-tracer,代碼行數:21,代碼來源:GMLInterpreterTest.java

示例13: gmlExtractorTest

import org.antlr.v4.runtime.BaseErrorListener; //導入依賴的package包/類
@Test(dataProvider = "dataProvider")
public void gmlExtractorTest(final String fileName, final int expectedTokenCount) throws IOException {
    final GMLLexer gmlLexer = new GMLLexer(new ANTLRInputStream(getClass().getResourceAsStream(fileName)));
    final GMLParser gmlParser = new GMLParser(new CommonTokenStream(gmlLexer));
    gmlParser.addErrorListener(new BaseErrorListener() {

        @Override
        public void syntaxError(final Recognizer<?, ?> theRecognizer, final Object theOffendingSymbol, final int theLine,
                final int theCharPositionInLine, final String theMsg, final RecognitionException theE) {
            Assert.fail(theMsg);
        }

    });
    final GMLExtractor gmlExtractor = new GMLExtractor(gmlParser);
    final List<Token> tokens = gmlExtractor.extract();
    LOGGER.info(tokens.toString());
    Assert.assertEquals(tokens.size(), expectedTokenCount);
}
 
開發者ID:klaushauschild1984,項目名稱:gml-tracer,代碼行數:19,代碼來源:GMLExtractorTest.java

示例14: parseInput

import org.antlr.v4.runtime.BaseErrorListener; //導入依賴的package包/類
/** Parse data or input file and initialize the parse tree.   */
private void parseInput() {
	if (data == null)
		loadInputFile();
	if (data == null)
		throw new IllegalArgumentException("Unable to load input file or data is missing.");
	ANTLRInputStream input = new ANTLRInputStream(data);
	SaltLexer lexer = new SaltLexer(input);
	lexer.addErrorListener(new BaseErrorListener() {
		@Override
		public void syntaxError(Recognizer<?, ?> arg0, Object arg1, int arg2,
				int arg3, String arg4, RecognitionException arg5) {
			throw new RuntimeException(arg5);
		}
	});
	CommonTokenStream tokens = new CommonTokenStream(lexer);
	SaltParser parser = new SaltParser(tokens);
	tree = parser.document();
	if (parser.getNumberOfSyntaxErrors() > 0) {
		System.out.println("Syntax error in file " + inputFile);
		return;
	}
}
 
開發者ID:mar9000,項目名稱:salt9000,代碼行數:24,代碼來源:SaltProcessor.java

示例15: parse

import org.antlr.v4.runtime.BaseErrorListener; //導入依賴的package包/類
/**
 * Parse the string passed as parameter returning the string representing the structure of the UI
 * described by the parameter.
 * @param document
 * @return
 * @throws Exception
 */
private String parse(String document) throws Exception {
	ANTLRInputStream input = new ANTLRInputStream(document);
	SaltLexer lexer = new SaltLexer(input);
	// The lexer should not recover errors.
	lexer.addErrorListener(new BaseErrorListener() {
		
		@Override
		public void syntaxError(Recognizer<?, ?> arg0, Object arg1, int arg2,
				int arg3, String arg4, RecognitionException arg5) {
			throw new RuntimeException(arg5);
		}
		
	});
	CommonTokenStream tokens = new CommonTokenStream(lexer);
	SaltParser parser = new SaltParser(tokens);
	ParseTree tree = parser.document();
	if (parser.getNumberOfSyntaxErrors() > 0) {
		throw new SyntaxException("Syntax error into the document: " + document);
	}
	//
	SaltTextVisitor visitor = new SaltTextVisitor(parser);
	return visitor.visit(tree);
}
 
開發者ID:mar9000,項目名稱:salt9000,代碼行數:31,代碼來源:SaltTest.java


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