Expose inner elements of variables and argument:
- Purpose: Better support nvim-treesitter highlighting
This commit is contained in:
parent
4076762484
commit
672fb317c4
|
@ -25,7 +25,7 @@ message([[An argument]])
|
||||||
(command_invocation
|
(command_invocation
|
||||||
(identifier)
|
(identifier)
|
||||||
(arguments
|
(arguments
|
||||||
(argument (bracket_argument))
|
(argument (bracket_argument (bracket_content)))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -41,7 +41,7 @@ message([[An argument]])
|
||||||
(command_invocation
|
(command_invocation
|
||||||
(identifier)
|
(identifier)
|
||||||
(arguments
|
(arguments
|
||||||
(argument (bracket_argument))
|
(argument (bracket_argument (bracket_content)))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -57,9 +57,9 @@ message([[First argument]] [[Second argument]])
|
||||||
(command_invocation
|
(command_invocation
|
||||||
(identifier)
|
(identifier)
|
||||||
(arguments
|
(arguments
|
||||||
(argument (bracket_argument))
|
(argument (bracket_argument (bracket_content)))
|
||||||
(seperation (space))
|
(seperation (space))
|
||||||
(argument (bracket_argument))
|
(argument (bracket_argument (bracket_content)))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -79,9 +79,9 @@ message(
|
||||||
(identifier)
|
(identifier)
|
||||||
(seperation (space))
|
(seperation (space))
|
||||||
(arguments
|
(arguments
|
||||||
(argument (bracket_argument))
|
(argument (bracket_argument (bracket_content)))
|
||||||
(seperation (space))
|
(seperation (space))
|
||||||
(argument (bracket_argument))
|
(argument (bracket_argument (bracket_content)))
|
||||||
(seperation (line_ending (newline)))
|
(seperation (line_ending (newline)))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -100,7 +100,7 @@ with line break
|
||||||
(command_invocation
|
(command_invocation
|
||||||
(identifier)
|
(identifier)
|
||||||
(arguments
|
(arguments
|
||||||
(argument (bracket_argument))
|
(argument (bracket_argument (bracket_content)))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
@ -25,7 +25,7 @@ message("An argument")
|
||||||
(command_invocation
|
(command_invocation
|
||||||
(identifier)
|
(identifier)
|
||||||
(arguments
|
(arguments
|
||||||
(argument (quoted_argument))
|
(argument (quoted_argument (quoted_element)))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -41,9 +41,9 @@ message("First argument" "Second argument")
|
||||||
(command_invocation
|
(command_invocation
|
||||||
(identifier)
|
(identifier)
|
||||||
(arguments
|
(arguments
|
||||||
(argument (quoted_argument))
|
(argument (quoted_argument (quoted_element)))
|
||||||
(seperation (space))
|
(seperation (space))
|
||||||
(argument (quoted_argument))
|
(argument (quoted_argument (quoted_element)))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -60,7 +60,7 @@ with line break")
|
||||||
(command_invocation
|
(command_invocation
|
||||||
(identifier)
|
(identifier)
|
||||||
(arguments
|
(arguments
|
||||||
(argument (quoted_argument))
|
(argument (quoted_argument (quoted_element)))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -78,7 +78,9 @@ message("${var}")
|
||||||
(arguments
|
(arguments
|
||||||
(argument
|
(argument
|
||||||
(quoted_argument
|
(quoted_argument
|
||||||
(variable_ref (normal_var))
|
(quoted_element
|
||||||
|
(variable_ref (normal_var (variable)))
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -98,8 +100,10 @@ message("${var} ${var}")
|
||||||
(arguments
|
(arguments
|
||||||
(argument
|
(argument
|
||||||
(quoted_argument
|
(quoted_argument
|
||||||
(variable_ref (normal_var))
|
(quoted_element
|
||||||
(variable_ref (normal_var))
|
(variable_ref (normal_var (variable)))
|
||||||
|
(variable_ref (normal_var (variable)))
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
@ -88,7 +88,7 @@ STATUS)
|
||||||
====================
|
====================
|
||||||
Variable referencing
|
Variable referencing
|
||||||
====================
|
====================
|
||||||
message(${var})
|
message(${var_ref})
|
||||||
---
|
---
|
||||||
|
|
||||||
(source_file
|
(source_file
|
||||||
|
@ -97,7 +97,7 @@ message(${var})
|
||||||
(arguments
|
(arguments
|
||||||
(argument
|
(argument
|
||||||
(unquoted_argument
|
(unquoted_argument
|
||||||
(variable_ref (normal_var))
|
(variable_ref (normal_var (variable)))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
20
grammar.js
20
grammar.js
|
@ -24,13 +24,13 @@ module.exports = grammar({
|
||||||
$.env_var,
|
$.env_var,
|
||||||
$.cache_var,
|
$.cache_var,
|
||||||
),
|
),
|
||||||
_literal_variable: $ => choice(
|
variable: $ => repeat1(choice(
|
||||||
/[a-zA-Z0-9/_.+-]/,
|
/[a-zA-Z0-9/_.+-]/,
|
||||||
$.escape_sequence,
|
$.escape_sequence,
|
||||||
),
|
)),
|
||||||
normal_var: $ => seq('${', repeat1($._literal_variable), '}'),
|
normal_var: $ => seq('${', $.variable, '}'),
|
||||||
env_var: $ => seq('$ENV{', repeat1($._literal_variable), '}'),
|
env_var: $ => seq('$ENV{', $.variable, '}'),
|
||||||
cache_var: $ => seq('$CACHE{', repeat1($._literal_variable), '}'),
|
cache_var: $ => seq('$CACHE{', $.variable, '}'),
|
||||||
|
|
||||||
argument: $ => choice(
|
argument: $ => choice(
|
||||||
$.bracket_argument,
|
$.bracket_argument,
|
||||||
|
@ -40,20 +40,20 @@ module.exports = grammar({
|
||||||
|
|
||||||
bracket_argument: $ => seq(
|
bracket_argument: $ => seq(
|
||||||
$._bracket_open,
|
$._bracket_open,
|
||||||
optional($._bracket_content),
|
optional($.bracket_content),
|
||||||
$._bracket_close,
|
$._bracket_close,
|
||||||
),
|
),
|
||||||
_bracket_open: $ => seq('[', repeat('='), '['),
|
_bracket_open: $ => seq('[', repeat('='), '['),
|
||||||
_bracket_content: $ => repeat1(/[^\]]/),
|
bracket_content: $ => repeat1(/[^\]]/),
|
||||||
_bracket_close: $ => seq(']', repeat('='), ']'),
|
_bracket_close: $ => seq(']', repeat('='), ']'),
|
||||||
|
|
||||||
quoted_argument: $ => seq('"', repeat($._quoted_element), '"'),
|
quoted_argument: $ => seq('"', optional($.quoted_element), '"'),
|
||||||
_quoted_element: $ => choice(
|
quoted_element: $ => repeat1(choice(
|
||||||
$.variable_ref,
|
$.variable_ref,
|
||||||
/[^\\"]/,
|
/[^\\"]/,
|
||||||
$.escape_sequence,
|
$.escape_sequence,
|
||||||
seq('\\', $.newline),
|
seq('\\', $.newline),
|
||||||
),
|
)),
|
||||||
|
|
||||||
unquoted_argument: $ => repeat1(
|
unquoted_argument: $ => repeat1(
|
||||||
choice(
|
choice(
|
||||||
|
|
128
src/grammar.json
128
src/grammar.json
|
@ -96,18 +96,21 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"_literal_variable": {
|
"variable": {
|
||||||
"type": "CHOICE",
|
"type": "REPEAT1",
|
||||||
"members": [
|
"content": {
|
||||||
{
|
"type": "CHOICE",
|
||||||
"type": "PATTERN",
|
"members": [
|
||||||
"value": "[a-zA-Z0-9/_.+-]"
|
{
|
||||||
},
|
"type": "PATTERN",
|
||||||
{
|
"value": "[a-zA-Z0-9/_.+-]"
|
||||||
"type": "SYMBOL",
|
},
|
||||||
"name": "escape_sequence"
|
{
|
||||||
}
|
"type": "SYMBOL",
|
||||||
]
|
"name": "escape_sequence"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"normal_var": {
|
"normal_var": {
|
||||||
"type": "SEQ",
|
"type": "SEQ",
|
||||||
|
@ -117,11 +120,8 @@
|
||||||
"value": "${"
|
"value": "${"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "REPEAT1",
|
"type": "SYMBOL",
|
||||||
"content": {
|
"name": "variable"
|
||||||
"type": "SYMBOL",
|
|
||||||
"name": "_literal_variable"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "STRING",
|
"type": "STRING",
|
||||||
|
@ -137,11 +137,8 @@
|
||||||
"value": "$ENV{"
|
"value": "$ENV{"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "REPEAT1",
|
"type": "SYMBOL",
|
||||||
"content": {
|
"name": "variable"
|
||||||
"type": "SYMBOL",
|
|
||||||
"name": "_literal_variable"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "STRING",
|
"type": "STRING",
|
||||||
|
@ -157,11 +154,8 @@
|
||||||
"value": "$CACHE{"
|
"value": "$CACHE{"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "REPEAT1",
|
"type": "SYMBOL",
|
||||||
"content": {
|
"name": "variable"
|
||||||
"type": "SYMBOL",
|
|
||||||
"name": "_literal_variable"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "STRING",
|
"type": "STRING",
|
||||||
|
@ -198,7 +192,7 @@
|
||||||
"members": [
|
"members": [
|
||||||
{
|
{
|
||||||
"type": "SYMBOL",
|
"type": "SYMBOL",
|
||||||
"name": "_bracket_content"
|
"name": "bracket_content"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "BLANK"
|
"type": "BLANK"
|
||||||
|
@ -231,7 +225,7 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"_bracket_content": {
|
"bracket_content": {
|
||||||
"type": "REPEAT1",
|
"type": "REPEAT1",
|
||||||
"content": {
|
"content": {
|
||||||
"type": "PATTERN",
|
"type": "PATTERN",
|
||||||
|
@ -266,11 +260,16 @@
|
||||||
"value": "\""
|
"value": "\""
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "REPEAT",
|
"type": "CHOICE",
|
||||||
"content": {
|
"members": [
|
||||||
"type": "SYMBOL",
|
{
|
||||||
"name": "_quoted_element"
|
"type": "SYMBOL",
|
||||||
}
|
"name": "quoted_element"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "BLANK"
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "STRING",
|
"type": "STRING",
|
||||||
|
@ -278,35 +277,38 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"_quoted_element": {
|
"quoted_element": {
|
||||||
"type": "CHOICE",
|
"type": "REPEAT1",
|
||||||
"members": [
|
"content": {
|
||||||
{
|
"type": "CHOICE",
|
||||||
"type": "SYMBOL",
|
"members": [
|
||||||
"name": "variable_ref"
|
{
|
||||||
},
|
"type": "SYMBOL",
|
||||||
{
|
"name": "variable_ref"
|
||||||
"type": "PATTERN",
|
},
|
||||||
"value": "[^\\\\\"]"
|
{
|
||||||
},
|
"type": "PATTERN",
|
||||||
{
|
"value": "[^\\\\\"]"
|
||||||
"type": "SYMBOL",
|
},
|
||||||
"name": "escape_sequence"
|
{
|
||||||
},
|
"type": "SYMBOL",
|
||||||
{
|
"name": "escape_sequence"
|
||||||
"type": "SEQ",
|
},
|
||||||
"members": [
|
{
|
||||||
{
|
"type": "SEQ",
|
||||||
"type": "STRING",
|
"members": [
|
||||||
"value": "\\"
|
{
|
||||||
},
|
"type": "STRING",
|
||||||
{
|
"value": "\\"
|
||||||
"type": "SYMBOL",
|
},
|
||||||
"name": "newline"
|
{
|
||||||
}
|
"type": "SYMBOL",
|
||||||
]
|
"name": "newline"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"unquoted_argument": {
|
"unquoted_argument": {
|
||||||
"type": "REPEAT1",
|
"type": "REPEAT1",
|
||||||
|
|
|
@ -44,6 +44,21 @@
|
||||||
{
|
{
|
||||||
"type": "bracket_argument",
|
"type": "bracket_argument",
|
||||||
"named": true,
|
"named": true,
|
||||||
|
"fields": {},
|
||||||
|
"children": {
|
||||||
|
"multiple": false,
|
||||||
|
"required": false,
|
||||||
|
"types": [
|
||||||
|
{
|
||||||
|
"type": "bracket_content",
|
||||||
|
"named": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "bracket_content",
|
||||||
|
"named": true,
|
||||||
"fields": {}
|
"fields": {}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -51,11 +66,11 @@
|
||||||
"named": true,
|
"named": true,
|
||||||
"fields": {},
|
"fields": {},
|
||||||
"children": {
|
"children": {
|
||||||
"multiple": true,
|
"multiple": false,
|
||||||
"required": false,
|
"required": true,
|
||||||
"types": [
|
"types": [
|
||||||
{
|
{
|
||||||
"type": "escape_sequence",
|
"type": "variable",
|
||||||
"named": true
|
"named": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -93,11 +108,11 @@
|
||||||
"named": true,
|
"named": true,
|
||||||
"fields": {},
|
"fields": {},
|
||||||
"children": {
|
"children": {
|
||||||
"multiple": true,
|
"multiple": false,
|
||||||
"required": false,
|
"required": true,
|
||||||
"types": [
|
"types": [
|
||||||
{
|
{
|
||||||
"type": "escape_sequence",
|
"type": "variable",
|
||||||
"named": true
|
"named": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -128,11 +143,11 @@
|
||||||
"named": true,
|
"named": true,
|
||||||
"fields": {},
|
"fields": {},
|
||||||
"children": {
|
"children": {
|
||||||
"multiple": true,
|
"multiple": false,
|
||||||
"required": false,
|
"required": true,
|
||||||
"types": [
|
"types": [
|
||||||
{
|
{
|
||||||
"type": "escape_sequence",
|
"type": "variable",
|
||||||
"named": true
|
"named": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -142,6 +157,21 @@
|
||||||
"type": "quoted_argument",
|
"type": "quoted_argument",
|
||||||
"named": true,
|
"named": true,
|
||||||
"fields": {},
|
"fields": {},
|
||||||
|
"children": {
|
||||||
|
"multiple": false,
|
||||||
|
"required": false,
|
||||||
|
"types": [
|
||||||
|
{
|
||||||
|
"type": "quoted_element",
|
||||||
|
"named": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "quoted_element",
|
||||||
|
"named": true,
|
||||||
|
"fields": {},
|
||||||
"children": {
|
"children": {
|
||||||
"multiple": true,
|
"multiple": true,
|
||||||
"required": false,
|
"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",
|
"type": "variable_ref",
|
||||||
"named": true,
|
"named": true,
|
||||||
|
|
1923
src/parser.c
1923
src/parser.c
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue