Skip to content

Instantly share code, notes, and snippets.

@niquola
Created April 28, 2023 13:37
Show Gist options
  • Save niquola/9c723fcb6fc30c44f3e033c44c2033eb to your computer and use it in GitHub Desktop.
Save niquola/9c723fcb6fc30c44f3e033c44c2033eb to your computer and use it in GitHub Desktop.
grammar fhirpathmini;
path : expr EOF ;
expr : expr AMPERSAND expr # concatexpr
| chain # chainexpr
;
chain : ( variable | element ) (DOT ( element | funcall | where ) | index)*;
variable : VARIABLE ;
element : IDENTIFIER ;
funcall : FIRST '(' ')'
| JOIN '(' string ')'
;
index : '[' int ']' ;
int : INT;
where : WHERE '(' predicate ')';
predicate : expr eq ( expr | string )
| expr comp ( expr | number )
| predicate boolop predicate
;
string : STRING ;
number : NUMBER;
eq : ('=' | '!=');
comp : ('<=' | '<' | '>' | '>=' | '=' );
boolop : ('or' | 'and');
// Lexer rules
IDENTIFIER : [_a-zA-Z][_a-zA-Z0-9]* ;
VARIABLE : '%' IDENTIFIER;
DOT : '.';
AMPERSAND : '&';
FIRST : 'first';
JOIN : 'join';
WHERE : 'where';
LPAREN : '(';
RPAREN : ')';
LBRACKET : '[';
RBRACKET : ']';
EQUAL : '=';
GT : '>';
GTE : '>=';
LT : '<';
LTE : '<=';
AND : 'and';
OR : 'or';
STRING : '\'' ~('\'')* '\'' ;
INT : [0-9]+;
NUMBER : INT('.' INT)? ;
WS : [ \t\r\n]+ -> skip;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment