Search in sources :

Example 1 with HL7QueryParsingException

use of org.apache.nifi.hl7.query.exception.HL7QueryParsingException in project nifi by apache.

the class HL7Query method buildReferenceEvaluator.

private Evaluator<?> buildReferenceEvaluator(final Tree tree) {
    switch(tree.getType()) {
        case MESSAGE:
            return new MessageEvaluator();
        case SEGMENT_NAME:
            return new SegmentEvaluator(new StringLiteralEvaluator(tree.getText()));
        case IDENTIFIER:
            return new DeclaredReferenceEvaluator(new StringLiteralEvaluator(tree.getText()));
        case DOT:
            final Tree firstChild = tree.getChild(0);
            final Tree secondChild = tree.getChild(1);
            return new DotEvaluator(buildReferenceEvaluator(firstChild), buildIntegerEvaluator(secondChild));
        case STRING_LITERAL:
            return new StringLiteralEvaluator(tree.getText());
        case NUMBER:
            return new IntegerLiteralEvaluator(Integer.parseInt(tree.getText()));
        default:
            throw new HL7QueryParsingException("Failed to build evaluator for " + tree.getText());
    }
}
Also used : StringLiteralEvaluator(org.apache.nifi.hl7.query.evaluator.literal.StringLiteralEvaluator) DotEvaluator(org.apache.nifi.hl7.query.evaluator.message.DotEvaluator) MessageEvaluator(org.apache.nifi.hl7.query.evaluator.message.MessageEvaluator) HL7QueryParsingException(org.apache.nifi.hl7.query.exception.HL7QueryParsingException) DeclaredReferenceEvaluator(org.apache.nifi.hl7.query.evaluator.message.DeclaredReferenceEvaluator) Tree(org.antlr.runtime.tree.Tree) SegmentEvaluator(org.apache.nifi.hl7.query.evaluator.message.SegmentEvaluator) IntegerLiteralEvaluator(org.apache.nifi.hl7.query.evaluator.literal.IntegerLiteralEvaluator)

Example 2 with HL7QueryParsingException

use of org.apache.nifi.hl7.query.exception.HL7QueryParsingException in project nifi by apache.

the class HL7Query method compile.

public static HL7Query compile(final String query) {
    try {
        final CommonTokenStream lexerTokenStream = createTokenStream(query);
        final HL7QueryParser parser = new HL7QueryParser(lexerTokenStream);
        final Tree tree = (Tree) parser.query().getTree();
        return new HL7Query(tree, query);
    } catch (final HL7QueryParsingException e) {
        throw e;
    } catch (final Exception e) {
        throw new HL7QueryParsingException(e);
    }
}
Also used : CommonTokenStream(org.antlr.runtime.CommonTokenStream) HL7QueryParser(org.apache.nifi.hl7.query.antlr.HL7QueryParser) HL7QueryParsingException(org.apache.nifi.hl7.query.exception.HL7QueryParsingException) Tree(org.antlr.runtime.tree.Tree) HL7QueryParsingException(org.apache.nifi.hl7.query.exception.HL7QueryParsingException)

Example 3 with HL7QueryParsingException

use of org.apache.nifi.hl7.query.exception.HL7QueryParsingException in project nifi by apache.

the class HL7Query method createTokenStream.

private static CommonTokenStream createTokenStream(final String expression) throws HL7QueryParsingException {
    final CharStream input = new ANTLRStringStream(expression);
    final HL7QueryLexer lexer = new HL7QueryLexer(input);
    return new CommonTokenStream(lexer);
}
Also used : ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) CommonTokenStream(org.antlr.runtime.CommonTokenStream) HL7QueryLexer(org.apache.nifi.hl7.query.antlr.HL7QueryLexer) CharStream(org.antlr.runtime.CharStream)

Aggregations

CommonTokenStream (org.antlr.runtime.CommonTokenStream)2 Tree (org.antlr.runtime.tree.Tree)2 HL7QueryParsingException (org.apache.nifi.hl7.query.exception.HL7QueryParsingException)2 ANTLRStringStream (org.antlr.runtime.ANTLRStringStream)1 CharStream (org.antlr.runtime.CharStream)1 HL7QueryLexer (org.apache.nifi.hl7.query.antlr.HL7QueryLexer)1 HL7QueryParser (org.apache.nifi.hl7.query.antlr.HL7QueryParser)1 IntegerLiteralEvaluator (org.apache.nifi.hl7.query.evaluator.literal.IntegerLiteralEvaluator)1 StringLiteralEvaluator (org.apache.nifi.hl7.query.evaluator.literal.StringLiteralEvaluator)1 DeclaredReferenceEvaluator (org.apache.nifi.hl7.query.evaluator.message.DeclaredReferenceEvaluator)1 DotEvaluator (org.apache.nifi.hl7.query.evaluator.message.DotEvaluator)1 MessageEvaluator (org.apache.nifi.hl7.query.evaluator.message.MessageEvaluator)1 SegmentEvaluator (org.apache.nifi.hl7.query.evaluator.message.SegmentEvaluator)1