Skip to content

Commit 2e56204

Browse files
committed
Add support for terraform
1 parent a2246a4 commit 2e56204

File tree

7 files changed

+22847
-16415
lines changed

7 files changed

+22847
-16415
lines changed

grammar.js

+119
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,125 @@ module.exports = grammar(terra, {
4949
'end'
5050
),
5151

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+
52171
statement: ($, old) => choice(
53172
old,
54173
$.test_statement,

queries/highlights.scm

+28
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,31 @@
2222
"end"
2323
] @keyword)
2424

25+
(type_constraints
26+
[
27+
"where"
28+
] @keyword)
29+
30+
(terraform_function_definition
31+
[
32+
"terraform"
33+
"end"
34+
] @keyword)
35+
36+
(terraform_function_implementation
37+
[
38+
"terraform"
39+
"end"
40+
] @keyword)
41+
42+
(terraform_function_implementation
43+
[
44+
"terraform"
45+
"end"
46+
] @keyword)
47+
48+
(concept_implementation
49+
[
50+
"concept"
51+
"end"
52+
] @keyword)

0 commit comments

Comments
 (0)