Created
April 28, 2023 13:37
-
-
Save niquola/9c723fcb6fc30c44f3e033c44c2033eb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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