fix operations; add one line blocks
This commit is contained in:
21
grammar.js
21
grammar.js
@@ -15,6 +15,8 @@ module.exports = grammar({
|
||||
conflicts: $ => [
|
||||
// string literals are just quoted template without template stuff
|
||||
[$.string_lit, $.quoted_template],
|
||||
// empty block may be both
|
||||
[$.block, $.one_line_block],
|
||||
],
|
||||
|
||||
externals: $ => [
|
||||
@@ -39,6 +41,7 @@ module.exports = grammar({
|
||||
choice(
|
||||
$.attribute,
|
||||
$.block,
|
||||
$.one_line_block,
|
||||
$._newlines,
|
||||
),
|
||||
)),
|
||||
@@ -60,6 +63,15 @@ module.exports = grammar({
|
||||
optional($._newlines),
|
||||
)),
|
||||
|
||||
one_line_block: $ => seq(
|
||||
$.identifier,
|
||||
repeat(choice($.string_lit, $.identifier)),
|
||||
$._block_start,
|
||||
optional(seq($.identifier, '=', $.expression)),
|
||||
$._block_end,
|
||||
$._newlines,
|
||||
),
|
||||
|
||||
_block_start: $ => '{',
|
||||
_block_end: $ => '}',
|
||||
|
||||
@@ -74,6 +86,9 @@ module.exports = grammar({
|
||||
$.conditional,
|
||||
),
|
||||
|
||||
// operations are documented as expressions, but our real world samples
|
||||
// contain instances of operations without parentheses. think for example:
|
||||
// x = a == "" && b != ""
|
||||
_expr_term: $ => choice(
|
||||
$.literal_value,
|
||||
$.template_expr,
|
||||
@@ -181,22 +196,28 @@ module.exports = grammar({
|
||||
|
||||
for_expr: $ => choice($.for_tuple_expr, $.for_object_expr),
|
||||
|
||||
// newlines
|
||||
for_tuple_expr: $ => seq(
|
||||
$._tuple_start,
|
||||
optional($._newlines),
|
||||
$.for_intro,
|
||||
$.expression,
|
||||
optional($.for_cond),
|
||||
optional($._newlines),
|
||||
$._tuple_end,
|
||||
),
|
||||
|
||||
// newlines
|
||||
for_object_expr: $ => seq(
|
||||
$._object_start,
|
||||
optional($._newlines),
|
||||
$.for_intro,
|
||||
$.expression,
|
||||
'=>',
|
||||
$.expression,
|
||||
optional($.ellipsis),
|
||||
optional($.for_cond),
|
||||
optional($._newlines),
|
||||
$._object_end,
|
||||
),
|
||||
|
||||
|
||||
118
src/grammar.json
118
src/grammar.json
@@ -21,6 +21,10 @@
|
||||
"type": "SYMBOL",
|
||||
"name": "block"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "one_line_block"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_newlines"
|
||||
@@ -127,6 +131,68 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"one_line_block": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "identifier"
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "string_lit"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "identifier"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_block_start"
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "identifier"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "="
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "expression"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_block_end"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_newlines"
|
||||
}
|
||||
]
|
||||
},
|
||||
"_block_start": {
|
||||
"type": "STRING",
|
||||
"value": "{"
|
||||
@@ -763,6 +829,18 @@
|
||||
"type": "SYMBOL",
|
||||
"name": "_tuple_start"
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_newlines"
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "for_intro"
|
||||
@@ -783,6 +861,18 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_newlines"
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_tuple_end"
|
||||
@@ -796,6 +886,18 @@
|
||||
"type": "SYMBOL",
|
||||
"name": "_object_start"
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_newlines"
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "for_intro"
|
||||
@@ -836,6 +938,18 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_newlines"
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_object_end"
|
||||
@@ -1487,6 +1601,10 @@
|
||||
[
|
||||
"string_lit",
|
||||
"quoted_template"
|
||||
],
|
||||
[
|
||||
"block",
|
||||
"one_line_block"
|
||||
]
|
||||
],
|
||||
"precedences": [],
|
||||
|
||||
@@ -126,6 +126,10 @@
|
||||
{
|
||||
"type": "block",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "one_line_block",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -514,6 +518,29 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "one_line_block",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "identifier",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "string_lit",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "operation",
|
||||
"named": true,
|
||||
|
||||
19741
src/parser.c
19741
src/parser.c
File diff suppressed because it is too large
Load Diff
@@ -110,3 +110,32 @@ block_1 {
|
||||
(identifier))
|
||||
(block
|
||||
(identifier))))))
|
||||
|
||||
================================================================================
|
||||
one line block
|
||||
================================================================================
|
||||
|
||||
locals { timestamp = regex_replace(timestamp(), "[- TZ:]", "") }
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(config_file
|
||||
(body
|
||||
(one_line_block
|
||||
(identifier)
|
||||
(identifier)
|
||||
(expression
|
||||
(function_call
|
||||
(identifier)
|
||||
(function_arguments
|
||||
(expression
|
||||
(function_call
|
||||
(identifier)))
|
||||
(expression
|
||||
(literal_value
|
||||
(string_lit
|
||||
(template_literal))))
|
||||
(expression
|
||||
(template_expr
|
||||
(quoted_template)))))))))
|
||||
|
||||
Reference in New Issue
Block a user