-
-
Notifications
You must be signed in to change notification settings - Fork 116
/
Copy pathxlm-macro.lark.template
42 lines (42 loc) · 2.17 KB
/
xlm-macro.lark.template
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
start: "=" expression
function_call: [NAME|STRING] L_PRA arglist R_PRA | cell L_PRA arglist R_PRA | defined_name L_PRA arglist R_PRA | function_call L_PRA arglist R_PRA
arglist: (argument LIST_SEPARATOR)* argument
argument: expression |
cell: a1_notation_cell | r1c1_notation_cell
a1_notation_cell: [NAME "!" | "'" /[^']+/i "'!"| "!"] /\$?([a-qs-z][a-z]?)\$?\d+\b|\$?(r[a-bd-z]?)\$?\d+\b(?!C)/i
r1c1_notation_cell: [NAME "!" | "'" /[^']+/i "'!" | "!"] ROW [REF | INT ] COL [REF | INT ]
defined_name: (NAME EXCLAMATION| "'" /[^']+/i "'" EXCLAMATION| EXCLAMATION) NAME
?expression: concat_expression (CMPOP concat_expression)*
?concat_expression: additive_expression (CONCATOP additive_expression)*
?additive_expression: multiplicative_expression (ADDITIVEOP multiplicative_expression)*
?multiplicative_expression: final (MULTIOP final)*
?final: L_PRA expression R_PRA | function_call | cell | range | atom | NAME | defined_name | array
array: "{" (constant ARRAY_SEPARATOR)* constant "}"
?constant: STRING | NUMBER
?range: cell COLON cell | cell COLON cell COLON cell
?atom: NUMBER | STRING | BOOLEAN | ERROR
ADDITIVEOP: "+" | "-"
MULTIOP: "*" | "/"
CMPOP: ">=" | "<=" | "<" [">"] | ">" | "="
CONCATOP: "&"
COLON: ":"
STRING: /\"([^\"]|\"\")*\"/i
BOOLEAN: "TRUE" | "FALSE"
ERROR: "#REF!" | "#DIV/0!" | "#N/A" | "#NAME?" | "#NULL!" | "#NUM!" | "#VALUE!" | "#GETTING_DATA"
ROW: "R" | "r"
COL: "C" | "c"
L_PRA: "("
R_PRA: ")"
L_BRAC: "{{XLLEFTBRACKET}}"
R_BRAC: "{{XLRIGHTBRACKET}}"
EXCLAMATION: "!"
DOT: "."
LIST_SEPARATOR: "{{XLLISTSEPARATOR}}"
ARRAY_SEPARATOR: ";"
REF: L_BRAC SIGNED_INT R_BRAC
%import common.SIGNED_INT -> SIGNED_INT
%import common.INT -> INT
%import common.SIGNED_FLOAT -> SIGNED_FLOAT
NUMBER: SIGNED_FLOAT | SIGNED_INT
NAME: /[j-qsu-z](?!\d{1,6}\b)[_\\.?a-z0-9]+\b|t(?!\d{1,6}\b|rue\b)[_\\.?a-z0-9]+\b|[_\\][_\\.?a-z0-9]*\b|r(?!(\[|(\d{0,5}c\d{0,3}\b)|(\d{1,6}\b)))[_\\.?a-z0-9]*\b(?!\[)|c(?!(\[|\d{0,3}r\d{0,5}\b|[a-z]?\d{1,6}\b))[_\\.?a-z0-9]*\b(?!\[)|[a-bd-eg-h](?![a-z]\d{1,5}\b|\d{1,5}\b)[_.\\?a-z0-9]*\b|f(?![a-z]\d{1,5}\b|\d{1,5}\b|alse\b)[_.\\?a-z0-9]*\b|i(?![a-v]\d+\b|\d+\b)[_.\\?a-z0-9]*\b|[_\\a-bd-qs-z]\b/i
%ignore " " // Disregard spaces in text