@@ -49,6 +49,125 @@ module.exports = grammar(terra, {
49
49
'end'
50
50
) ,
51
51
52
+
53
+ terraform_function_definition : ( $ ) => seq (
54
+ 'terraform' ,
55
+ $ . _terraform_function_body
56
+ ) ,
57
+
58
+ terraform_function_implementation : ( $ ) => seq (
59
+ 'terraform' ,
60
+ field ( 'name' , $ . _function_name ) ,
61
+ $ . _terraform_function_body
62
+ ) ,
63
+
64
+ _local_terraform_function_implementation : ( $ ) => seq (
65
+ 'local' ,
66
+ 'terraform' ,
67
+ field ( 'name' , choice ( $ . identifier , $ . escape_expression ) ) ,
68
+ $ . _terraform_function_body
69
+ ) ,
70
+
71
+ _terraform_function_body : ( $ ) => seq (
72
+ field ( 'parameters' , $ . terraform_function_parameters ) ,
73
+ optional ( field ( 'concepts' , $ . type_constraints ) ) ,
74
+ field ( 'body' , optional_block ( $ ) ) ,
75
+ 'end'
76
+ ) ,
77
+
78
+ terraform_function_parameters : ( $ ) => seq (
79
+ '(' ,
80
+ optional ( $ . _terraform_parameter_list ) ,
81
+ ')' ,
82
+ ) ,
83
+
84
+ type_constraints : ( $ ) => seq (
85
+ 'where' ,
86
+ '{' ,
87
+ optional ( $ . _constrained_types_list ) ,
88
+ '}'
89
+ ) ,
90
+
91
+ _terraform_parameter_list : ( $ ) => choice (
92
+ seq (
93
+ list_seq (
94
+ choice (
95
+ $ . _typed_declaration ,
96
+ $ . identifier ,
97
+ $ . escape_expression ,
98
+ ) ,
99
+ ','
100
+ ) ,
101
+ optional ( seq ( ',' , $ . terraform_vararg_expression ) )
102
+ ) ,
103
+ $ . terraform_vararg_expression
104
+ ) ,
105
+
106
+ terraform_vararg_expression : ( $ ) => seq (
107
+ field ( 'name' , $ . identifier ) ,
108
+ $ . vararg_expression
109
+ ) ,
110
+
111
+ _constrained_types_list : ( $ ) => list_seq (
112
+ choice (
113
+ $ . identifier ,
114
+ seq ( $ . identifier , ':' , choice ( $ . string , $ . number , $ . _type_specifier ) ) ,
115
+ ) ,
116
+ ','
117
+ ) ,
118
+
119
+ concept_implementation : ( $ ) => seq (
120
+ 'concept' ,
121
+ field ( 'name' , $ . _function_name ) ,
122
+ $ . _concept_body ,
123
+ ) ,
124
+
125
+ _local_concept_implementation : ( $ ) => seq (
126
+ 'local' ,
127
+ 'concept' ,
128
+ field ( 'name' , choice ( $ . identifier , $ . escape_expression ) ) ,
129
+ $ . _concept_body ,
130
+ ) ,
131
+
132
+ _regular_concept_body : ( $ ) => seq (
133
+ field ( 'body' , optional_block ( $ ) ) ,
134
+ 'end'
135
+ ) ,
136
+
137
+ _parametrized_concept_body : ( $ ) => seq (
138
+ field (
139
+ 'parameters' ,
140
+ seq ( '(' , optional ( list_seq ( $ . expression , ',' ) ) , ')' )
141
+ ) ,
142
+ field ( 'concepts' , $ . type_constraints ) ,
143
+ field ( 'body' , optional_block ( $ ) ) ,
144
+ 'end'
145
+ ) ,
146
+
147
+ _concept_body : ( $ ) => choice (
148
+ $ . _regular_concept_body ,
149
+ $ . _parametrized_concept_body ,
150
+ ) ,
151
+
152
+ declaration : ( $ , old ) => choice (
153
+ old ,
154
+ $ . terraform_function_implementation ,
155
+ alias (
156
+ $ . _local_terraform_function_implementation ,
157
+ $ . terraform_function_implementation
158
+ ) ,
159
+ $ . concept_implementation ,
160
+ alias (
161
+ $ . _local_concept_implementation ,
162
+ $ . concept_implementation
163
+ ) ,
164
+ ) ,
165
+
166
+ expression : ( $ , old ) => choice (
167
+ old ,
168
+ $ . terraform_function_definition ,
169
+ ) ,
170
+
52
171
statement : ( $ , old ) => choice (
53
172
old ,
54
173
$ . test_statement ,
0 commit comments