Expose inner elements of variables and argument:

- Purpose: Better support nvim-treesitter highlighting
This commit is contained in:
Uy Ha 2021-05-28 22:12:15 +02:00
parent 4076762484
commit 672fb317c4
7 changed files with 1088 additions and 1082 deletions

View file

@ -25,7 +25,7 @@ message([[An argument]])
(command_invocation
(identifier)
(arguments
(argument (bracket_argument))
(argument (bracket_argument (bracket_content)))
)
)
)
@ -41,7 +41,7 @@ message([[An argument]])
(command_invocation
(identifier)
(arguments
(argument (bracket_argument))
(argument (bracket_argument (bracket_content)))
)
)
)
@ -57,9 +57,9 @@ message([[First argument]] [[Second argument]])
(command_invocation
(identifier)
(arguments
(argument (bracket_argument))
(argument (bracket_argument (bracket_content)))
(seperation (space))
(argument (bracket_argument))
(argument (bracket_argument (bracket_content)))
)
)
)
@ -79,9 +79,9 @@ message(
(identifier)
(seperation (space))
(arguments
(argument (bracket_argument))
(argument (bracket_argument (bracket_content)))
(seperation (space))
(argument (bracket_argument))
(argument (bracket_argument (bracket_content)))
(seperation (line_ending (newline)))
)
)
@ -100,7 +100,7 @@ with line break
(command_invocation
(identifier)
(arguments
(argument (bracket_argument))
(argument (bracket_argument (bracket_content)))
)
)
)

View file

@ -25,7 +25,7 @@ message("An argument")
(command_invocation
(identifier)
(arguments
(argument (quoted_argument))
(argument (quoted_argument (quoted_element)))
)
)
)
@ -41,9 +41,9 @@ message("First argument" "Second argument")
(command_invocation
(identifier)
(arguments
(argument (quoted_argument))
(argument (quoted_argument (quoted_element)))
(seperation (space))
(argument (quoted_argument))
(argument (quoted_argument (quoted_element)))
)
)
)
@ -60,7 +60,7 @@ with line break")
(command_invocation
(identifier)
(arguments
(argument (quoted_argument))
(argument (quoted_argument (quoted_element)))
)
)
)
@ -78,7 +78,9 @@ message("${var}")
(arguments
(argument
(quoted_argument
(variable_ref (normal_var))
(quoted_element
(variable_ref (normal_var (variable)))
)
)
)
)
@ -98,8 +100,10 @@ message("${var} ${var}")
(arguments
(argument
(quoted_argument
(variable_ref (normal_var))
(variable_ref (normal_var))
(quoted_element
(variable_ref (normal_var (variable)))
(variable_ref (normal_var (variable)))
)
)
)
)

View file

@ -88,7 +88,7 @@ STATUS)
====================
Variable referencing
====================
message(${var})
message(${var_ref})
---
(source_file
@ -97,7 +97,7 @@ message(${var})
(arguments
(argument
(unquoted_argument
(variable_ref (normal_var))
(variable_ref (normal_var (variable)))
)
)
)

View file

@ -24,13 +24,13 @@ module.exports = grammar({
$.env_var,
$.cache_var,
),
_literal_variable: $ => choice(
variable: $ => repeat1(choice(
/[a-zA-Z0-9/_.+-]/,
$.escape_sequence,
),
normal_var: $ => seq('${', repeat1($._literal_variable), '}'),
env_var: $ => seq('$ENV{', repeat1($._literal_variable), '}'),
cache_var: $ => seq('$CACHE{', repeat1($._literal_variable), '}'),
)),
normal_var: $ => seq('${', $.variable, '}'),
env_var: $ => seq('$ENV{', $.variable, '}'),
cache_var: $ => seq('$CACHE{', $.variable, '}'),
argument: $ => choice(
$.bracket_argument,
@ -40,20 +40,20 @@ module.exports = grammar({
bracket_argument: $ => seq(
$._bracket_open,
optional($._bracket_content),
optional($.bracket_content),
$._bracket_close,
),
_bracket_open: $ => seq('[', repeat('='), '['),
_bracket_content: $ => repeat1(/[^\]]/),
bracket_content: $ => repeat1(/[^\]]/),
_bracket_close: $ => seq(']', repeat('='), ']'),
quoted_argument: $ => seq('"', repeat($._quoted_element), '"'),
_quoted_element: $ => choice(
quoted_argument: $ => seq('"', optional($.quoted_element), '"'),
quoted_element: $ => repeat1(choice(
$.variable_ref,
/[^\\"]/,
$.escape_sequence,
seq('\\', $.newline),
),
)),
unquoted_argument: $ => repeat1(
choice(

View file

@ -96,18 +96,21 @@
}
]
},
"_literal_variable": {
"type": "CHOICE",
"members": [
{
"type": "PATTERN",
"value": "[a-zA-Z0-9/_.+-]"
},
{
"type": "SYMBOL",
"name": "escape_sequence"
}
]
"variable": {
"type": "REPEAT1",
"content": {
"type": "CHOICE",
"members": [
{
"type": "PATTERN",
"value": "[a-zA-Z0-9/_.+-]"
},
{
"type": "SYMBOL",
"name": "escape_sequence"
}
]
}
},
"normal_var": {
"type": "SEQ",
@ -117,11 +120,8 @@
"value": "${"
},
{
"type": "REPEAT1",
"content": {
"type": "SYMBOL",
"name": "_literal_variable"
}
"type": "SYMBOL",
"name": "variable"
},
{
"type": "STRING",
@ -137,11 +137,8 @@
"value": "$ENV{"
},
{
"type": "REPEAT1",
"content": {
"type": "SYMBOL",
"name": "_literal_variable"
}
"type": "SYMBOL",
"name": "variable"
},
{
"type": "STRING",
@ -157,11 +154,8 @@
"value": "$CACHE{"
},
{
"type": "REPEAT1",
"content": {
"type": "SYMBOL",
"name": "_literal_variable"
}
"type": "SYMBOL",
"name": "variable"
},
{
"type": "STRING",
@ -198,7 +192,7 @@
"members": [
{
"type": "SYMBOL",
"name": "_bracket_content"
"name": "bracket_content"
},
{
"type": "BLANK"
@ -231,7 +225,7 @@
}
]
},
"_bracket_content": {
"bracket_content": {
"type": "REPEAT1",
"content": {
"type": "PATTERN",
@ -266,11 +260,16 @@
"value": "\""
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_quoted_element"
}
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "quoted_element"
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
@ -278,35 +277,38 @@
}
]
},
"_quoted_element": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "variable_ref"
},
{
"type": "PATTERN",
"value": "[^\\\\\"]"
},
{
"type": "SYMBOL",
"name": "escape_sequence"
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "\\"
},
{
"type": "SYMBOL",
"name": "newline"
}
]
}
]
"quoted_element": {
"type": "REPEAT1",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "variable_ref"
},
{
"type": "PATTERN",
"value": "[^\\\\\"]"
},
{
"type": "SYMBOL",
"name": "escape_sequence"
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "\\"
},
{
"type": "SYMBOL",
"name": "newline"
}
]
}
]
}
},
"unquoted_argument": {
"type": "REPEAT1",

View file

@ -44,6 +44,21 @@
{
"type": "bracket_argument",
"named": true,
"fields": {},
"children": {
"multiple": false,
"required": false,
"types": [
{
"type": "bracket_content",
"named": true
}
]
}
},
{
"type": "bracket_content",
"named": true,
"fields": {}
},
{
@ -51,11 +66,11 @@
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": false,
"multiple": false,
"required": true,
"types": [
{
"type": "escape_sequence",
"type": "variable",
"named": true
}
]
@ -93,11 +108,11 @@
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": false,
"multiple": false,
"required": true,
"types": [
{
"type": "escape_sequence",
"type": "variable",
"named": true
}
]
@ -128,11 +143,11 @@
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": false,
"multiple": false,
"required": true,
"types": [
{
"type": "escape_sequence",
"type": "variable",
"named": true
}
]
@ -142,6 +157,21 @@
"type": "quoted_argument",
"named": true,
"fields": {},
"children": {
"multiple": false,
"required": false,
"types": [
{
"type": "quoted_element",
"named": true
}
]
}
},
{
"type": "quoted_element",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": false,
@ -214,6 +244,21 @@
]
}
},
{
"type": "variable",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "escape_sequence",
"named": true
}
]
}
},
{
"type": "variable_ref",
"named": true,

File diff suppressed because it is too large Load diff