Skip to content

Commit a87b709

Browse files
committed
fix: allow empty string literals
1 parent 8a13647 commit a87b709

File tree

7 files changed

+5360
-5302
lines changed

7 files changed

+5360
-5302
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ housekeeping:
77
* regenerate parser
88
* fix clang+windows CI job
99

10+
fix:
11+
* allow empty string literals
12+
1013
## 0.6.0 - 2021-09-20
1114

1215
feature:

grammar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ module.exports = grammar({
108108

109109
string_lit: $ => prec(PREC.string_lit, seq(
110110
$.quoted_template_start,
111-
$.template_literal,
111+
optional($.template_literal),
112112
$.quoted_template_end,
113113
)),
114114

src/grammar.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,16 @@
313313
"name": "quoted_template_start"
314314
},
315315
{
316-
"type": "SYMBOL",
317-
"name": "template_literal"
316+
"type": "CHOICE",
317+
"members": [
318+
{
319+
"type": "SYMBOL",
320+
"name": "template_literal"
321+
},
322+
{
323+
"type": "BLANK"
324+
}
325+
]
318326
},
319327
{
320328
"type": "SYMBOL",

src/parser.c

Lines changed: 5293 additions & 5283 deletions
Large diffs are not rendered by default.

test/corpus/blocks.txt

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,25 @@ block_1 {}
2929
(block_start)
3030
(block_end))))
3131

32+
================================================================================
33+
basic block with empty type
34+
================================================================================
35+
36+
block_1 "" {
37+
}
38+
39+
--------------------------------------------------------------------------------
40+
41+
(config_file
42+
(body
43+
(block
44+
(identifier)
45+
(string_lit
46+
(quoted_template_start)
47+
(quoted_template_end))
48+
(block_start)
49+
(block_end))))
50+
3251
================================================================================
3352
block with attribute
3453
================================================================================
@@ -166,8 +185,8 @@ locals { timestamp = regex_replace(timestamp(), "[- TZ:]", "") }
166185
(template_literal)
167186
(quoted_template_end))))
168187
(expression
169-
(template_expr
170-
(quoted_template
188+
(literal_value
189+
(string_lit
171190
(quoted_template_start)
172191
(quoted_template_end)))))))))
173192
(block_end))))

test/corpus/real_world.txt

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ resource "azurerm_storage_blob" "proxy_cert" {
126126
(identifier))
127127
(get_attr
128128
(identifier))
129-
(template_expr
130-
(quoted_template
129+
(literal_value
130+
(string_lit
131131
(quoted_template_start)
132132
(quoted_template_end))))))
133133
(expression
@@ -158,8 +158,8 @@ resource "azurerm_storage_blob" "proxy_cert" {
158158
(identifier))
159159
(get_attr
160160
(identifier))
161-
(template_expr
162-
(quoted_template
161+
(literal_value
162+
(string_lit
163163
(quoted_template_start)
164164
(quoted_template_end))))))
165165
(expression
@@ -203,8 +203,8 @@ resource "azurerm_storage_blob" "proxy_cert" {
203203
(identifier))
204204
(get_attr
205205
(identifier))
206-
(template_expr
207-
(quoted_template
206+
(literal_value
207+
(string_lit
208208
(quoted_template_start)
209209
(quoted_template_end))))))
210210
(expression
@@ -259,8 +259,8 @@ resource "azurerm_storage_blob" "proxy_cert" {
259259
(identifier))
260260
(get_attr
261261
(identifier))
262-
(template_expr
263-
(quoted_template
262+
(literal_value
263+
(string_lit
264264
(quoted_template_start)
265265
(quoted_template_end))))))
266266
(expression
@@ -315,8 +315,8 @@ resource "azurerm_storage_blob" "proxy_cert" {
315315
(identifier))
316316
(get_attr
317317
(identifier))
318-
(template_expr
319-
(quoted_template
318+
(literal_value
319+
(string_lit
320320
(quoted_template_start)
321321
(quoted_template_end))))))
322322
(expression
@@ -396,16 +396,16 @@ resource "azurerm_storage_blob" "proxy_cert" {
396396
(identifier))
397397
(get_attr
398398
(identifier))
399-
(template_expr
400-
(quoted_template
399+
(literal_value
400+
(string_lit
401401
(quoted_template_start)
402402
(quoted_template_end)))))
403403
(variable_expr
404404
(identifier))))
405405
(get_attr
406406
(identifier))
407-
(template_expr
408-
(quoted_template
407+
(literal_value
408+
(string_lit
409409
(quoted_template_start)
410410
(quoted_template_end))))))
411411
(expression

test/corpus/strings.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
================================================================================
2+
empty string
3+
================================================================================
4+
5+
foo = ""
6+
7+
--------------------------------------------------------------------------------
8+
9+
(config_file
10+
(body
11+
(attribute
12+
(identifier)
13+
(expression
14+
(literal_value
15+
(string_lit
16+
(quoted_template_start)
17+
(quoted_template_end)))))))
18+
119
================================================================================
220
unescaped tab
321
================================================================================

0 commit comments

Comments
 (0)