-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParadoxFile.g4
68 lines (57 loc) · 2.07 KB
/
ParadoxFile.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
grammar ParadoxFile;
config: (assignment)*;
assignment: field OPERATOR? value;
field: string | symbol | variable | LIST_START;
value: integer | percent | real | date | string | symbol | variable | variable_expression | map | array | list | constructor;
symbol: string | INT | REAL | SYMBOL;
string: DSTRING | SSTRING | CSTRING;
integer: INT;
real: REAL;
date: DATE;
percent: PCT;
map: BLOCK_START (assignment)* BLOCK_END;
array
: BLOCK_START value COMMA? ((value | assignment) COMMA?)* BLOCK_END
| BLOCK_START (assignment COMMA?)+ value COMMA? ((value | assignment) COMMA?)* BLOCK_END
;
variable: VARIABLE_START SYMBOL | VARIABLE_START INT;
variable_expression: VARIABLE_START VARIABLE_EXPRESSION_START expression VARIABLE_EXPRESSION_END;
expression
: expression MULTIPLY_DIVIDE expression
| expression PLUS_MINUS expression
| ABS_VALUE expression ABS_VALUE
| OPEN_PARENS expression CLOSE_PARENS
| PLUS_MINUS value
| value
;
list: LIST_START (SYMBOL | string);
constructor: symbol array;
OPERATOR: '=' | '<>' | '>' | '<' | '<=' | '>=' | '!=' | '==';
BLOCK_START: '{';
BLOCK_END: '}';
VARIABLE_START: '@' '\\'?;
VARIABLE_EXPRESSION_START: '[';
VARIABLE_EXPRESSION_END: ']';
ABS_VALUE: '|';
OPEN_PARENS: '(';
CLOSE_PARENS: ')';
LIST_START: 'list';
INT: PLUS_MINUS?[0-9]+;
PCT: PLUS_MINUS?[0-9]+'%';
REAL: PLUS_MINUS?[0-9]*'.'[0-9]+;
DATE: [0-9]+'.'[0-9]+'.'[0-9]+;
SSTRING : '\'' (~('"' | '\\') | '\\' ('"' | '\\'))* '\'';
DSTRING : '"' (~('"' | '\\') | '\\' ('"' | '\\'))* '"';
CSTRING: '“' (~('"' | '\\') | '\\' ('"' | '\\'))* '”';
SYMBOL: SYMBOL_START (| SYMBOL_END | SYMBOL_INNER+ SYMBOL_END);
PLUS_MINUS: PLUS_MINUS_F;
MULTIPLY_DIVIDE: MULTIPLY_DIVIDE_F;
COMMA: ',';
WHITESPACE: [ \t\n\r] + -> skip;
LINE_COMMENT: '#'~[\r\n]* -> channel(HIDDEN);
fragment STRING_DELIM: ('"' | '\'');
fragment PLUS_MINUS_F: [-+];
fragment MULTIPLY_DIVIDE_F: [*/];
fragment SYMBOL_START: [0-9\p{Cased}\p{Ideographic}·“”’$_];
fragment SYMBOL_INNER: [\p{Cased}\p{Ideographic}0-9'·“”’&/$|:@_.?^%-];
fragment SYMBOL_END: [\p{Cased}\p{Ideographic}0-9'·“”’&/$:@_.%-];