Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 23 additions & 25 deletions fhir-model/FHIRPath.g4
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
grammar FHIRPath;

// Grammar rules
// [FHIRPath](http://hl7.org/fhirpath/N1) Normative Release

//prog: line (line)*;
//line: ID ( '(' expr ')') ':' expr '\r'? '\n';
Expand Down Expand Up @@ -35,13 +36,14 @@ literal
| ('true' | 'false') #booleanLiteral
| STRING #stringLiteral
| NUMBER #numberLiteral
| DATE #dateLiteral
| DATETIME #dateTimeLiteral
| TIME #timeLiteral
| quantity #quantityLiteral
;

externalConstant
: '%' identifier
: '%' ( identifier | STRING )
;

invocation // Terms that can be used after the function/member invocation '.'
Expand Down Expand Up @@ -90,6 +92,8 @@ identifier
: IDENTIFIER
| DELIMITEDIDENTIFIER
| 'as'
| 'contains'
| 'in'
| 'is'
;

Expand All @@ -98,40 +102,34 @@ identifier
Lexical rules
*****************************************************************/

// Not sure why, but with these as lexical rules, when the grammar is imported into CQL, they are not correctly recognized
// Moving the same rules into the literal production rule above corrects the issue
//EMPTY
// : '{' '}'
// ; // To create an empty array (and avoid a NULL literal)
/*
NOTE: The goal of these rules in the grammar is to provide a date
token to the parser. As such it is not attempting to validate that
the date is a correct date, that task is for the parser or interpreter.
*/

//BOOL
// : 'true'
// | 'false'
// ;
DATE
: '@' DATEFORMAT
;

DATETIME
: '@'
[0-9][0-9][0-9][0-9] // year
(
'-'[0-9][0-9] // month
(
'-'[0-9][0-9] // day
(
'T' TIMEFORMAT
)?
)?
)?
'Z'? // UTC specifier
: '@' DATEFORMAT 'T' (TIMEFORMAT TIMEZONEOFFSETFORMAT?)?
;

TIME
: '@' 'T' TIMEFORMAT
;

fragment DATEFORMAT
: [0-9][0-9][0-9][0-9] ('-'[0-9][0-9] ('-'[0-9][0-9])?)?
;

fragment TIMEFORMAT
:
[0-9][0-9] (':'[0-9][0-9] (':'[0-9][0-9] ('.'[0-9]+)?)?)?
('Z' | ('+' | '-') [0-9][0-9]':'[0-9][0-9])? // timezone
: [0-9][0-9] (':'[0-9][0-9] (':'[0-9][0-9] ('.'[0-9]+)?)?)?
;

fragment TIMEZONEOFFSETFORMAT
: ('Z' | ('+' | '-') [0-9][0-9]':'[0-9][0-9])
;

IDENTIFIER
Expand Down
2 changes: 1 addition & 1 deletion fhir-model/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
<version>4.5.3</version>
<version>4.7.2</version>
</dependency>
<dependency>
<groupId>net.jcip</groupId>
Expand Down
153 changes: 153 additions & 0 deletions fhir-model/src/main/java/com/ibm/fhir/model/path/FHIRPath.interp
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
token literal names:
null
'.'
'['
']'
'+'
'-'
'*'
'/'
'div'
'mod'
'&'
'is'
'as'
'|'
'<='
'<'
'>'
'>='
'='
'~'
'!='
'!~'
'in'
'contains'
'and'
'or'
'xor'
'implies'
'('
')'
'{'
'}'
'true'
'false'
'%'
'$this'
'$index'
'$total'
','
'year'
'month'
'week'
'day'
'hour'
'minute'
'second'
'millisecond'
'years'
'months'
'weeks'
'days'
'hours'
'minutes'
'seconds'
'milliseconds'
null
null
null
null
null
null
null
null
null
null

token symbolic names:
null
null
null
null
null
null
null
null
null
null
null
null
null
null
null
null
null
null
null
null
null
null
null
null
null
null
null
null
null
null
null
null
null
null
null
null
null
null
null
null
null
null
null
null
null
null
null
null
null
null
null
null
null
null
null
DATE
DATETIME
TIME
IDENTIFIER
DELIMITEDIDENTIFIER
STRING
NUMBER
WS
COMMENT
LINE_COMMENT

rule names:
expression
term
literal
externalConstant
invocation
function
paramList
quantity
unit
dateTimePrecision
pluralDateTimePrecision
typeSpecifier
qualifiedIdentifier
identifier


atn:
[3, 24715, 42794, 33075, 47597, 16764, 15335, 30598, 22884, 3, 66, 152, 4, 2, 9, 2, 4, 3, 9, 3, 4, 4, 9, 4, 4, 5, 9, 5, 4, 6, 9, 6, 4, 7, 9, 7, 4, 8, 9, 8, 4, 9, 9, 9, 4, 10, 9, 10, 4, 11, 9, 11, 4, 12, 9, 12, 4, 13, 9, 13, 4, 14, 9, 14, 4, 15, 9, 15, 3, 2, 3, 2, 3, 2, 3, 2, 5, 2, 35, 10, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 7, 2, 75, 10, 2, 12, 2, 14, 2, 78, 11, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 3, 87, 10, 3, 3, 4, 3, 4, 3, 4, 3, 4, 3, 4, 3, 4, 3, 4, 3, 4, 3, 4, 5, 4, 98, 10, 4, 3, 5, 3, 5, 3, 5, 5, 5, 103, 10, 5, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 5, 6, 110, 10, 6, 3, 7, 3, 7, 3, 7, 5, 7, 115, 10, 7, 3, 7, 3, 7, 3, 8, 3, 8, 3, 8, 7, 8, 122, 10, 8, 12, 8, 14, 8, 125, 11, 8, 3, 9, 3, 9, 5, 9, 129, 10, 9, 3, 10, 3, 10, 3, 10, 5, 10, 134, 10, 10, 3, 11, 3, 11, 3, 12, 3, 12, 3, 13, 3, 13, 3, 14, 3, 14, 3, 14, 7, 14, 145, 10, 14, 12, 14, 14, 14, 148, 11, 14, 3, 15, 3, 15, 3, 15, 2, 3, 2, 16, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 2, 14, 3, 2, 6, 7, 3, 2, 8, 11, 4, 2, 6, 7, 12, 12, 3, 2, 16, 19, 3, 2, 20, 23, 3, 2, 24, 25, 3, 2, 27, 28, 3, 2, 13, 14, 3, 2, 34, 35, 3, 2, 41, 48, 3, 2, 49, 56, 5, 2, 13, 14, 24, 25, 60, 61, 2, 171, 2, 34, 3, 2, 2, 2, 4, 86, 3, 2, 2, 2, 6, 97, 3, 2, 2, 2, 8, 99, 3, 2, 2, 2, 10, 109, 3, 2, 2, 2, 12, 111, 3, 2, 2, 2, 14, 118, 3, 2, 2, 2, 16, 126, 3, 2, 2, 2, 18, 133, 3, 2, 2, 2, 20, 135, 3, 2, 2, 2, 22, 137, 3, 2, 2, 2, 24, 139, 3, 2, 2, 2, 26, 141, 3, 2, 2, 2, 28, 149, 3, 2, 2, 2, 30, 31, 8, 2, 1, 2, 31, 35, 5, 4, 3, 2, 32, 33, 9, 2, 2, 2, 33, 35, 5, 2, 2, 13, 34, 30, 3, 2, 2, 2, 34, 32, 3, 2, 2, 2, 35, 76, 3, 2, 2, 2, 36, 37, 12, 12, 2, 2, 37, 38, 9, 3, 2, 2, 38, 75, 5, 2, 2, 13, 39, 40, 12, 11, 2, 2, 40, 41, 9, 4, 2, 2, 41, 75, 5, 2, 2, 12, 42, 43, 12, 9, 2, 2, 43, 44, 7, 15, 2, 2, 44, 75, 5, 2, 2, 10, 45, 46, 12, 8, 2, 2, 46, 47, 9, 5, 2, 2, 47, 75, 5, 2, 2, 9, 48, 49, 12, 7, 2, 2, 49, 50, 9, 6, 2, 2, 50, 75, 5, 2, 2, 8, 51, 52, 12, 6, 2, 2, 52, 53, 9, 7, 2, 2, 53, 75, 5, 2, 2, 7, 54, 55, 12, 5, 2, 2, 55, 56, 7, 26, 2, 2, 56, 75, 5, 2, 2, 6, 57, 58, 12, 4, 2, 2, 58, 59, 9, 8, 2, 2, 59, 75, 5, 2, 2, 5, 60, 61, 12, 3, 2, 2, 61, 62, 7, 29, 2, 2, 62, 75, 5, 2, 2, 4, 63, 64, 12, 15, 2, 2, 64, 65, 7, 3, 2, 2, 65, 75, 5, 10, 6, 2, 66, 67, 12, 14, 2, 2, 67, 68, 7, 4, 2, 2, 68, 69, 5, 2, 2, 2, 69, 70, 7, 5, 2, 2, 70, 75, 3, 2, 2, 2, 71, 72, 12, 10, 2, 2, 72, 73, 9, 9, 2, 2, 73, 75, 5, 24, 13, 2, 74, 36, 3, 2, 2, 2, 74, 39, 3, 2, 2, 2, 74, 42, 3, 2, 2, 2, 74, 45, 3, 2, 2, 2, 74, 48, 3, 2, 2, 2, 74, 51, 3, 2, 2, 2, 74, 54, 3, 2, 2, 2, 74, 57, 3, 2, 2, 2, 74, 60, 3, 2, 2, 2, 74, 63, 3, 2, 2, 2, 74, 66, 3, 2, 2, 2, 74, 71, 3, 2, 2, 2, 75, 78, 3, 2, 2, 2, 76, 74, 3, 2, 2, 2, 76, 77, 3, 2, 2, 2, 77, 3, 3, 2, 2, 2, 78, 76, 3, 2, 2, 2, 79, 87, 5, 10, 6, 2, 80, 87, 5, 6, 4, 2, 81, 87, 5, 8, 5, 2, 82, 83, 7, 30, 2, 2, 83, 84, 5, 2, 2, 2, 84, 85, 7, 31, 2, 2, 85, 87, 3, 2, 2, 2, 86, 79, 3, 2, 2, 2, 86, 80, 3, 2, 2, 2, 86, 81, 3, 2, 2, 2, 86, 82, 3, 2, 2, 2, 87, 5, 3, 2, 2, 2, 88, 89, 7, 32, 2, 2, 89, 98, 7, 33, 2, 2, 90, 98, 9, 10, 2, 2, 91, 98, 7, 62, 2, 2, 92, 98, 7, 63, 2, 2, 93, 98, 7, 57, 2, 2, 94, 98, 7, 58, 2, 2, 95, 98, 7, 59, 2, 2, 96, 98, 5, 16, 9, 2, 97, 88, 3, 2, 2, 2, 97, 90, 3, 2, 2, 2, 97, 91, 3, 2, 2, 2, 97, 92, 3, 2, 2, 2, 97, 93, 3, 2, 2, 2, 97, 94, 3, 2, 2, 2, 97, 95, 3, 2, 2, 2, 97, 96, 3, 2, 2, 2, 98, 7, 3, 2, 2, 2, 99, 102, 7, 36, 2, 2, 100, 103, 5, 28, 15, 2, 101, 103, 7, 62, 2, 2, 102, 100, 3, 2, 2, 2, 102, 101, 3, 2, 2, 2, 103, 9, 3, 2, 2, 2, 104, 110, 5, 28, 15, 2, 105, 110, 5, 12, 7, 2, 106, 110, 7, 37, 2, 2, 107, 110, 7, 38, 2, 2, 108, 110, 7, 39, 2, 2, 109, 104, 3, 2, 2, 2, 109, 105, 3, 2, 2, 2, 109, 106, 3, 2, 2, 2, 109, 107, 3, 2, 2, 2, 109, 108, 3, 2, 2, 2, 110, 11, 3, 2, 2, 2, 111, 112, 5, 28, 15, 2, 112, 114, 7, 30, 2, 2, 113, 115, 5, 14, 8, 2, 114, 113, 3, 2, 2, 2, 114, 115, 3, 2, 2, 2, 115, 116, 3, 2, 2, 2, 116, 117, 7, 31, 2, 2, 117, 13, 3, 2, 2, 2, 118, 123, 5, 2, 2, 2, 119, 120, 7, 40, 2, 2, 120, 122, 5, 2, 2, 2, 121, 119, 3, 2, 2, 2, 122, 125, 3, 2, 2, 2, 123, 121, 3, 2, 2, 2, 123, 124, 3, 2, 2, 2, 124, 15, 3, 2, 2, 2, 125, 123, 3, 2, 2, 2, 126, 128, 7, 63, 2, 2, 127, 129, 5, 18, 10, 2, 128, 127, 3, 2, 2, 2, 128, 129, 3, 2, 2, 2, 129, 17, 3, 2, 2, 2, 130, 134, 5, 20, 11, 2, 131, 134, 5, 22, 12, 2, 132, 134, 7, 62, 2, 2, 133, 130, 3, 2, 2, 2, 133, 131, 3, 2, 2, 2, 133, 132, 3, 2, 2, 2, 134, 19, 3, 2, 2, 2, 135, 136, 9, 11, 2, 2, 136, 21, 3, 2, 2, 2, 137, 138, 9, 12, 2, 2, 138, 23, 3, 2, 2, 2, 139, 140, 5, 26, 14, 2, 140, 25, 3, 2, 2, 2, 141, 146, 5, 28, 15, 2, 142, 143, 7, 3, 2, 2, 143, 145, 5, 28, 15, 2, 144, 142, 3, 2, 2, 2, 145, 148, 3, 2, 2, 2, 146, 144, 3, 2, 2, 2, 146, 147, 3, 2, 2, 2, 147, 27, 3, 2, 2, 2, 148, 146, 3, 2, 2, 2, 149, 150, 9, 13, 2, 2, 150, 29, 3, 2, 2, 2, 14, 34, 74, 76, 86, 97, 102, 109, 114, 123, 128, 133, 146]
19 changes: 10 additions & 9 deletions fhir-model/src/main/java/com/ibm/fhir/model/path/FHIRPath.tokens
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,16 @@ T__50=51
T__51=52
T__52=53
T__53=54
DATETIME=55
TIME=56
IDENTIFIER=57
DELIMITEDIDENTIFIER=58
STRING=59
NUMBER=60
WS=61
COMMENT=62
LINE_COMMENT=63
DATE=55
DATETIME=56
TIME=57
IDENTIFIER=58
DELIMITEDIDENTIFIER=59
STRING=60
NUMBER=61
WS=62
COMMENT=63
LINE_COMMENT=64
'.'=1
'['=2
']'=3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public abstract class FHIRPathAbstractNode implements FHIRPathNode {
protected final String name;
protected final String path;
protected final FHIRPathType type;
protected final FHIRPathPrimitiveValue value;
protected final FHIRPathSystemValue value;
protected final Collection<FHIRPathNode> children;

protected FHIRPathAbstractNode(Builder builder) {
Expand Down Expand Up @@ -49,7 +49,7 @@ public boolean hasValue() {
}

@Override
public FHIRPathPrimitiveValue getValue() {
public FHIRPathSystemValue getValue() {
return value;
}

Expand Down Expand Up @@ -87,7 +87,7 @@ public static abstract class Builder implements FHIRPathNode.Builder {
// optional
protected String name;
protected String path;
protected FHIRPathPrimitiveValue value;
protected FHIRPathSystemValue value;
protected Collection<FHIRPathNode> children = new ArrayList<>();

protected Builder(FHIRPathType type) {
Expand All @@ -108,7 +108,7 @@ public Builder path(String path) {
}

@Override
public Builder value(FHIRPathPrimitiveValue value) {
public Builder value(FHIRPathSystemValue value) {
children.remove(this.value);
this.value = value;
children.add(this.value);
Expand Down
Loading