Search in sources :

Example 16 with FHIRLexerException

use of org.hl7.fhir.r5.utils.FHIRLexer.FHIRLexerException 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.r5.model.ExpressionNode)

Example 17 with FHIRLexerException

use of org.hl7.fhir.r5.utils.FHIRLexer.FHIRLexerException 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 18 with FHIRLexerException

use of org.hl7.fhir.r5.utils.FHIRLexer.FHIRLexerException 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 19 with FHIRLexerException

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

the class FHIRLexer method processConstant.

public String processConstant(String s) throws FHIRLexerException {
    StringBuilder b = new StringBuilder();
    int i = 1;
    while (i < s.length() - 1) {
        char ch = s.charAt(i);
        if (ch == '\\') {
            i++;
            switch(s.charAt(i)) {
                case 't':
                    b.append('\t');
                    break;
                case 'r':
                    b.append('\r');
                    break;
                case 'n':
                    b.append('\n');
                    break;
                case 'f':
                    b.append('\f');
                    break;
                case '\'':
                    b.append('\'');
                    break;
                case '"':
                    b.append('"');
                    break;
                case '`':
                    b.append('`');
                    break;
                case '\\':
                    b.append('\\');
                    break;
                case '/':
                    b.append('/');
                    break;
                case 'u':
                    i++;
                    int uc = Integer.parseInt(s.substring(i, i + 4), 16);
                    b.append((char) uc);
                    i = i + 4;
                    break;
                default:
                    throw new FHIRLexerException("Unknown character escape \\" + s.charAt(i));
            }
        } else {
            b.append(ch);
            i++;
        }
    }
    return b.toString();
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder)

Example 20 with FHIRLexerException

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

the class FHIRLexer method processFixedName.

public String processFixedName(String s) throws FHIRLexerException {
    StringBuilder b = new StringBuilder();
    int i = 1;
    while (i < s.length() - 1) {
        char ch = s.charAt(i);
        if (ch == '\\') {
            i++;
            switch(s.charAt(i)) {
                case 't':
                    b.append('\t');
                    break;
                case 'r':
                    b.append('\r');
                    break;
                case 'n':
                    b.append('\n');
                    break;
                case 'f':
                    b.append('\f');
                    break;
                case '\'':
                    b.append('\'');
                    break;
                case '"':
                    b.append('"');
                    break;
                case '\\':
                    b.append('\\');
                    break;
                case '/':
                    b.append('/');
                    break;
                case 'u':
                    i++;
                    int uc = Integer.parseInt(s.substring(i, i + 4), 16);
                    b.append((char) uc);
                    i = i + 4;
                    break;
                default:
                    throw new FHIRLexerException("Unknown character escape \\" + s.charAt(i));
            }
        } else {
            b.append(ch);
            i++;
        }
    }
    return b.toString();
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder)

Aggregations

CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)9 ExpressionNode (org.hl7.fhir.r5.model.ExpressionNode)6 ExpressionNode (org.hl7.fhir.dstu2.model.ExpressionNode)5 ExpressionNode (org.hl7.fhir.r4.model.ExpressionNode)4 ExpressionNode (org.hl7.fhir.r4b.model.ExpressionNode)4 BigDecimal (java.math.BigDecimal)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 ExpressionNode (org.hl7.fhir.dstu2016may.model.ExpressionNode)3 ExpressionNode (org.hl7.fhir.dstu3.model.ExpressionNode)3 PathEngineException (org.hl7.fhir.exceptions.PathEngineException)3 SourceLocation (org.hl7.fhir.utilities.SourceLocation)3 Base (org.hl7.fhir.dstu2.model.Base)2 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)2 FHIRException (org.hl7.fhir.exceptions.FHIRException)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 List (java.util.List)1 NotImplementedException (org.apache.commons.lang3.NotImplementedException)1 TypeRefComponent (org.hl7.fhir.dstu2.model.ElementDefinition.TypeRefComponent)1