forked from patrickchugh/terravision
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhcl2.lark.old
73 lines (59 loc) · 3.3 KB
/
hcl2.lark.old
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
start : new_line_or_comment? body new_line_or_comment?
body : (attribute | block)*
attribute : identifier "=" expression (new_line_or_comment)?
block : identifier (identifier | STRING_LIT)* "{" (new_line_or_comment)? body "}" new_line_or_comment
new_line_and_or_comma: new_line_or_comment | "," | "," new_line_or_comment
new_line_or_comment: ( /\n/ | /#.*\n/ | /\/\/.*\n/ )+
identifier : /[a-zA-Z_][a-zA-Z0-9_-]*/
?expression : expr_term | operation | conditional
conditional : expression "?" new_line_or_comment? expression new_line_or_comment? ":" new_line_or_comment? expression
?operation : unary_op | binary_op
!unary_op : ("-" | "!") expr_term
binary_op : expression binary_term
!binary_operator : "==" | "!=" | "<" | ">" | "<=" | ">=" | "-" | "*" | "/" | "%" | "&&" | "||" | "+"
binary_term : binary_operator new_line_or_comment? expression
expr_term : "(" new_line_or_comment? expression new_line_or_comment? ")"
| float_lit
| int_lit
| STRING_LIT
| tuple
| object
| function_call
| index_expr_term
| get_attr_expr_term
| identifier
| heredoc_template
| heredoc_template_trim
| attr_splat_expr_term
| full_splat_expr_term
| for_tuple_expr
| for_object_expr
STRING_LIT : "\"" (STRING_CHARS | INTERPOLATION)* "\""
STRING_CHARS : /(?:(?!\${)([^"\\]|\\.))+/+ // any character except '"" unless inside a interpolation string
INTERPOLATION : "${" /[^}]+/ "}"
int_lit : DECIMAL+
!float_lit: DECIMAL+ "." DECIMAL+ (EXP_MARK DECIMAL+)?
| DECIMAL+ ("." DECIMAL+)? EXP_MARK DECIMAL+
DECIMAL : "0".."9"
EXP_MARK : ("e" | "E") ("+" | "-")?
tuple : "[" (new_line_or_comment? expression (new_line_or_comment? "," new_line_or_comment? expression)* new_line_or_comment? ","?)? new_line_or_comment? "]"
object : "{" new_line_or_comment? (object_elem (new_line_and_or_comma object_elem )* new_line_and_or_comma?)? "}"
object_elem : (identifier | expression) ("=" | ":") expression
heredoc_template : /<<(?P<heredoc>[a-zA-Z][a-zA-Z0-9._-]+)\n(?:.|\n)+?\n+\s*(?P=heredoc)/
heredoc_template_trim : /<<-(?P<heredoc_trim>[a-zA-Z][a-zA-Z0-9._-]+)\n(?:.|\n)+?\n+\s*(?P=heredoc_trim)/
function_call : identifier "(" new_line_or_comment? arguments? new_line_or_comment? ")"
arguments : (expression (new_line_or_comment? "," new_line_or_comment? expression)* ("," | "...")? new_line_or_comment?)
index_expr_term : expr_term index
get_attr_expr_term : expr_term get_attr
attr_splat_expr_term : expr_term attr_splat
full_splat_expr_term : expr_term full_splat
index : "[" new_line_or_comment? expression new_line_or_comment? "]" | "." DECIMAL+
?get_attr : "." identifier
?attr_splat : ".*" get_attr*
?full_splat : "[" "*" "]" (get_attr | index)*
!for_tuple_expr : "[" new_line_or_comment? for_intro new_line_or_comment? expression new_line_or_comment? for_cond? new_line_or_comment? "]"
!for_object_expr : "{" new_line_or_comment? for_intro expression "=>" expression "..."? new_line_or_comment? for_cond? new_line_or_comment? "}"
!for_intro : "for" new_line_or_comment? identifier ("," identifier new_line_or_comment?)? new_line_or_comment? "in" new_line_or_comment? expression ":" new_line_or_comment?
!for_cond : "if" new_line_or_comment? expression
%ignore /[ \t]+/
%ignore /\/\*(.|\n)*?(\*\/)/