forked from grahamegrieve/fhirpath
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fhirpath.g4
73 lines (51 loc) · 1.62 KB
/
fhirpath.g4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
grammar fhirpath;
// Grammar rules
//version without precedence and left-recursion
//expression: term (righthand)*;
//righthand: op term | '.' function;
//term: '(' expression ')' | fpconst | predicate;
//op: LOGIC | COMP | '*' | '/' | '+' | '-' | '|' | '&';
prog: line (line)*;
line: ID ( '(' predicate ')') ':' expr '\r'? '\n';
expr:
expr ('*' | '/') expr |
expr ('+' | '-') expr |
expr ('|' | '&') expr |
expr COMP expr |
expr LOGIC expr |
'(' expr ')' |
predicate |
fpconst;
predicate : (root_spec | item) ('.' item)* ;
item: element recurse? | function | axis_spec | '(' expr ')';
element: ID CHOICE?;
recurse: '*';
axis_spec: '*' | '**' ;
root_spec: '$context' | '$resource' | '$parent';
function: ID '(' param_list? ')';
param_list: expr (',' expr)*;
fpconst: STRING |
'-'? NUMBER |
BOOL |
CONST;
// Lexical rules
LOGIC: 'and' | 'or' | 'xor';
COMP: '=' | '~' | '!=' | '!~' | '>' | '<' | '<=' | '>=' | 'in';
BOOL: 'true' | 'false';
CONST: '%' ALPHANUM (ALPHANUM | [\-.])*;
STRING: '"' (ESC | ~["\\])* '"' | // " delineated string
'\'' (ESC | ~[\'\\])* '\''; // ' delineated string
fragment ESC: '\\' (["'\\/bfnrt] | UNICODE); // allow \", \', \\, \/, \b, etc. and \uXXX
fragment UNICODE: 'u' HEX HEX HEX HEX;
fragment HEX: [0-9a-fA-F];
NUMBER: INT '.' [0-9]+ EXP? |
INT EXP |
INT;
fragment INT: '0' | [1-9][0-9]*;
fragment EXP: [Ee] [+\-]? INT;
CHOICE: '[x]';
ID: ALPHA ALPHANUM* ;
fragment ALPHA: [a-zA-Z];
fragment ALPHANUM: ALPHA | [0-9];
WS: [ \r\n\t]+ -> skip;
COMMENT: '{' (~'}')* '}' -> skip;