Search in sources :

Example 26 with FHIRLexer

use of org.hl7.fhir.r4b.utils.FHIRLexer in project org.hl7.fhir.core by hapifhir.

the class StructureMapUtilities method parseUses.

private void parseUses(StructureMap result, FHIRLexer lexer) throws FHIRException {
    lexer.token("uses");
    StructureMapStructureComponent st = result.addStructure();
    st.setUrl(lexer.readConstant("url"));
    if (lexer.hasToken("alias")) {
        lexer.token("alias");
        st.setAlias(lexer.take());
    }
    lexer.token("as");
    st.setMode(StructureMapModelMode.fromCode(lexer.take()));
    lexer.skipToken(";");
    if (lexer.hasComment()) {
        st.setDocumentation(lexer.take().substring(2).trim());
    }
    lexer.skipComments();
}
Also used : StructureMapStructureComponent(org.hl7.fhir.r4.model.StructureMap.StructureMapStructureComponent)

Example 27 with FHIRLexer

use of org.hl7.fhir.r4b.utils.FHIRLexer in project org.hl7.fhir.core by hapifhir.

the class FHIRPathEngine method gatherPrecedence.

private ExpressionNode gatherPrecedence(FHIRLexer lexer, ExpressionNode start, EnumSet<Operation> ops) {
    assert (start.isProximal());
    // is there anything to do?
    boolean work = false;
    ExpressionNode focus = start.getOpNext();
    if (ops.contains(start.getOperation())) {
        while (focus != null && focus.getOperation() != null) {
            work = work || !ops.contains(focus.getOperation());
            focus = focus.getOpNext();
        }
    } else {
        while (focus != null && focus.getOperation() != null) {
            work = work || ops.contains(focus.getOperation());
            focus = focus.getOpNext();
        }
    }
    if (!work) {
        return start;
    }
    // entry point: tricky
    ExpressionNode group;
    if (ops.contains(start.getOperation())) {
        group = newGroup(lexer, start);
        group.setProximal(true);
        focus = start;
        start = group;
    } else {
        ExpressionNode node = start;
        focus = node.getOpNext();
        while (!ops.contains(focus.getOperation())) {
            node = focus;
            focus = focus.getOpNext();
        }
        group = newGroup(lexer, focus);
        node.setOpNext(group);
    }
    // focus points at the group.group
    do {
        // run until we find the end of the sequence
        while (ops.contains(focus.getOperation())) {
            focus = focus.getOpNext();
        }
        if (focus.getOperation() != null) {
            group.setOperation(focus.getOperation());
            group.setOpNext(focus.getOpNext());
            focus.setOperation(null);
            focus.setOpNext(null);
            // now look for another sequence, and start it
            ExpressionNode node = group;
            focus = group.getOpNext();
            if (focus != null) {
                while (focus != null && !ops.contains(focus.getOperation())) {
                    node = focus;
                    focus = focus.getOpNext();
                }
                if (focus != null) {
                    // && (focus.Operation in Ops) - must be true
                    group = newGroup(lexer, focus);
                    node.setOpNext(group);
                }
            }
        }
    } while (focus != null && focus.getOperation() != null);
    return start;
}
Also used : ExpressionNode(org.hl7.fhir.r4b.model.ExpressionNode)

Example 28 with FHIRLexer

use of org.hl7.fhir.r4b.utils.FHIRLexer in project org.hl7.fhir.core by hapifhir.

the class FHIRPathEngine method parse.

public ExpressionNode parse(String path, String name) throws FHIRLexerException {
    FHIRLexer lexer = new FHIRLexer(path, name);
    if (lexer.done()) {
        throw lexer.error("Path cannot be empty");
    }
    ExpressionNode result = parseExpression(lexer, true);
    if (!lexer.done()) {
        throw lexer.error("Premature ExpressionNode termination at unexpected token \"" + lexer.getCurrent() + "\"");
    }
    result.check();
    return result;
}
Also used : ExpressionNode(org.hl7.fhir.r4b.model.ExpressionNode)

Example 29 with FHIRLexer

use of org.hl7.fhir.r4b.utils.FHIRLexer in project org.hl7.fhir.core by hapifhir.

the class FHIRPathEngine method parse.

/**
 * Parse a path that is part of some other syntax
 *
 * @return
 * @throws PathEngineException
 * @throws Exception
 */
public ExpressionNode parse(FHIRLexer lexer) throws FHIRLexerException {
    ExpressionNode result = parseExpression(lexer, true);
    result.check();
    return result;
}
Also used : ExpressionNode(org.hl7.fhir.r4b.model.ExpressionNode)

Example 30 with FHIRLexer

use of org.hl7.fhir.r4b.utils.FHIRLexer in project org.hl7.fhir.core by hapifhir.

the class FHIRPathEngine method parsePartial.

/**
 * Parse a path for later use using execute
 *
 * @param path
 * @return
 * @throws PathEngineException
 * @throws Exception
 */
public ExpressionNodeWithOffset parsePartial(String path, int i) throws FHIRLexerException {
    FHIRLexer lexer = new FHIRLexer(path, i);
    if (lexer.done())
        throw lexer.error("Path cannot be empty");
    ExpressionNode result = parseExpression(lexer, true);
    result.check();
    return new ExpressionNodeWithOffset(lexer.getCurrentStart(), result);
}
Also used : ExpressionNode(org.hl7.fhir.r4.model.ExpressionNode)

Aggregations

ExpressionNode (org.hl7.fhir.r4.model.ExpressionNode)8 ExpressionNode (org.hl7.fhir.dstu2016may.model.ExpressionNode)7 ExpressionNode (org.hl7.fhir.dstu3.model.ExpressionNode)7 ExpressionNode (org.hl7.fhir.r4b.model.ExpressionNode)6 ExpressionNode (org.hl7.fhir.r5.model.ExpressionNode)6 ExpressionNode (org.hl7.fhir.dstu2.model.ExpressionNode)5 BigDecimal (java.math.BigDecimal)3 HashMap (java.util.HashMap)3 SourceLocation (org.hl7.fhir.utilities.SourceLocation)3 StringType (org.hl7.fhir.dstu3.model.StringType)2 StringType (org.hl7.fhir.r4.model.StringType)2 Function (org.hl7.fhir.dstu2.model.ExpressionNode.Function)1 SourceLocation (org.hl7.fhir.dstu2.model.ExpressionNode.SourceLocation)1 FunctionDetails (org.hl7.fhir.dstu2.utils.FHIRPathEngine.IEvaluationContext.FunctionDetails)1 ConceptMap (org.hl7.fhir.dstu2016may.model.ConceptMap)1 SourceElementComponent (org.hl7.fhir.dstu2016may.model.ConceptMap.SourceElementComponent)1 TargetElementComponent (org.hl7.fhir.dstu2016may.model.ConceptMap.TargetElementComponent)1 Function (org.hl7.fhir.dstu2016may.model.ExpressionNode.Function)1 SourceLocation (org.hl7.fhir.dstu2016may.model.ExpressionNode.SourceLocation)1 IdType (org.hl7.fhir.dstu2016may.model.IdType)1