Search in sources :

Example 1 with SearchLexer

use of org.jabref.search.SearchLexer in project jabref by JabRef.

the class GrammarBasedSearchRule method init.

private void init(String query) throws ParseCancellationException {
    if (Objects.equals(this.query, query)) {
        return;
    }
    SearchLexer lexer = new SearchLexer(new ANTLRInputStream(query));
    // no infos on file system
    lexer.removeErrorListeners();
    lexer.addErrorListener(ThrowingErrorListener.INSTANCE);
    SearchParser parser = new SearchParser(new CommonTokenStream(lexer));
    // no infos on file system
    parser.removeErrorListeners();
    parser.addErrorListener(ThrowingErrorListener.INSTANCE);
    // ParseCancelationException on parse errors
    parser.setErrorHandler(new BailErrorStrategy());
    tree = parser.start();
    this.query = query;
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) BailErrorStrategy(org.antlr.v4.runtime.BailErrorStrategy) SearchLexer(org.jabref.search.SearchLexer) SearchParser(org.jabref.search.SearchParser) ANTLRInputStream(org.antlr.v4.runtime.ANTLRInputStream)

Aggregations

ANTLRInputStream (org.antlr.v4.runtime.ANTLRInputStream)1 BailErrorStrategy (org.antlr.v4.runtime.BailErrorStrategy)1 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)1 SearchLexer (org.jabref.search.SearchLexer)1 SearchParser (org.jabref.search.SearchParser)1