Compare commits
5 Commits
9d9325f8f9
...
3a793b84cd
Author | SHA1 | Date |
---|---|---|
Shadowfacts | 3a793b84cd | |
Ryan Despain | 275effdfc0 | |
oxalica | 4094e3a040 | |
Martin Jambon | 7fb8506cbe | |
Martin Jambon | c93070d720 |
|
@ -1,7 +1,7 @@
|
||||||
[package]
|
[package]
|
||||||
name = "tree-sitter-bash"
|
name = "tree-sitter-bash"
|
||||||
description = "bash grammar for the tree-sitter parsing library"
|
description = "bash grammar for the tree-sitter parsing library"
|
||||||
version = "0.19.0"
|
version = "0.20.0"
|
||||||
keywords = ["incremental", "parsing", "bash"]
|
keywords = ["incremental", "parsing", "bash"]
|
||||||
categories = ["parsing", "text-editors"]
|
categories = ["parsing", "text-editors"]
|
||||||
repository = "https://github.com/tree-sitter/tree-sitter-bash"
|
repository = "https://github.com/tree-sitter/tree-sitter-bash"
|
||||||
|
@ -23,7 +23,7 @@ include = [
|
||||||
path = "bindings/rust/lib.rs"
|
path = "bindings/rust/lib.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tree-sitter = "0.19"
|
tree-sitter = "0.20"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
cc = "1.0"
|
cc = "1.0"
|
||||||
|
|
|
@ -35,7 +35,7 @@ pub const NODE_TYPES: &'static str = include_str!("../../src/node-types.json");
|
||||||
|
|
||||||
// Uncomment these to include any queries that this grammar contains
|
// Uncomment these to include any queries that this grammar contains
|
||||||
|
|
||||||
// pub const HIGHLIGHTS_QUERY: &'static str = include_str!("../../queries/highlights.scm");
|
pub const HIGHLIGHTS_QUERY: &'static str = include_str!("../../queries/highlights.scm");
|
||||||
// pub const INJECTIONS_QUERY: &'static str = include_str!("../../queries/injections.scm");
|
// pub const INJECTIONS_QUERY: &'static str = include_str!("../../queries/injections.scm");
|
||||||
// pub const LOCALS_QUERY: &'static str = include_str!("../../queries/locals.scm");
|
// pub const LOCALS_QUERY: &'static str = include_str!("../../queries/locals.scm");
|
||||||
// pub const TAGS_QUERY: &'static str = include_str!("../../queries/tags.scm");
|
// pub const TAGS_QUERY: &'static str = include_str!("../../queries/tags.scm");
|
||||||
|
|
|
@ -355,3 +355,18 @@ echo -ne "\033k$1\033\\" > /dev/stderr
|
||||||
(redirected_statement
|
(redirected_statement
|
||||||
(command (command_name (word)) (word) (string (simple_expansion (variable_name))))
|
(command (command_name (word)) (word) (string (simple_expansion (variable_name))))
|
||||||
(file_redirect (word))))
|
(file_redirect (word))))
|
||||||
|
|
||||||
|
================================================================================
|
||||||
|
Words containing bare '#'
|
||||||
|
================================================================================
|
||||||
|
|
||||||
|
curl -# localhost #comment without space
|
||||||
|
nix build nixpkgs#hello -v # comment with space
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
(program
|
||||||
|
(command (command_name (word)) (word) (word))
|
||||||
|
(comment)
|
||||||
|
(command (command_name (word)) (word) (word) (word))
|
||||||
|
(comment))
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
# See https://zsh.sourceforge.io/Doc/Release/Expansion.html#Parameter-Expansion-Flags
|
||||||
|
=============================
|
||||||
|
Parameter Expansion Flags
|
||||||
|
=============================
|
||||||
|
echo ${(v)V}
|
||||||
|
echo ${(s.:.)V}
|
||||||
|
echo ${(@)V}
|
||||||
|
echo ${()V}
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
(program
|
||||||
|
(command (command_name (word)) (expansion (expansion_flags) (variable_name)))
|
||||||
|
(command (command_name (word)) (expansion (expansion_flags) (variable_name)))
|
||||||
|
(command (command_name (word)) (expansion (expansion_flags) (variable_name)))
|
||||||
|
(command (command_name (word)) (expansion (expansion_flags) (variable_name))))
|
||||||
|
|
||||||
|
=============================
|
||||||
|
Parameter Expansion Flags Quotes
|
||||||
|
=============================
|
||||||
|
echo "${(v_sldkfj_sdklfj)V}"
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
(program
|
||||||
|
(command (command_name (word)) (string (expansion (expansion_flags) (variable_name)))))
|
||||||
|
=============================
|
||||||
|
Parameter Expansion Invalid Flags
|
||||||
|
=============================
|
||||||
|
echo "${(())V}"
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
(program
|
||||||
|
(command (command_name (word)) (string (expansion (ERROR) (expansion_flags) (ERROR (word))))))
|
19
grammar.js
19
grammar.js
|
@ -8,7 +8,6 @@ const SPECIAL_CHARACTERS = [
|
||||||
'|', '&', ';',
|
'|', '&', ';',
|
||||||
'\\',
|
'\\',
|
||||||
'\\s',
|
'\\s',
|
||||||
'#',
|
|
||||||
];
|
];
|
||||||
|
|
||||||
module.exports = grammar({
|
module.exports = grammar({
|
||||||
|
@ -491,8 +490,12 @@ module.exports = grammar({
|
||||||
|
|
||||||
string_expansion: $ => seq('$', choice($.string, $.raw_string)),
|
string_expansion: $ => seq('$', choice($.string, $.raw_string)),
|
||||||
|
|
||||||
|
// See https://zsh.sourceforge.io/Doc/Release/Expansion.html#Parameter-Expansion-Flags
|
||||||
|
expansion_flags: ($) => seq("(", repeat(/[^()]/), ")"),
|
||||||
|
|
||||||
expansion: $ => seq(
|
expansion: $ => seq(
|
||||||
'${',
|
'${',
|
||||||
|
optional($.expansion_flags),
|
||||||
optional(choice('#', '!')),
|
optional(choice('#', '!')),
|
||||||
optional(choice(
|
optional(choice(
|
||||||
seq(
|
seq(
|
||||||
|
@ -537,10 +540,16 @@ module.exports = grammar({
|
||||||
|
|
||||||
_special_variable_name: $ => alias(choice('*', '@', '?', '-', '$', '0', '_'), $.special_variable_name),
|
_special_variable_name: $ => alias(choice('*', '@', '?', '-', '$', '0', '_'), $.special_variable_name),
|
||||||
|
|
||||||
word: $ => token(repeat1(choice(
|
word: $ => token(seq(
|
||||||
noneOf(...SPECIAL_CHARACTERS),
|
choice(
|
||||||
seq('\\', noneOf('\\s'))
|
noneOf('#', ...SPECIAL_CHARACTERS),
|
||||||
))),
|
seq('\\', noneOf('\\s'))
|
||||||
|
),
|
||||||
|
repeat(choice(
|
||||||
|
noneOf(...SPECIAL_CHARACTERS),
|
||||||
|
seq('\\', noneOf('\\s'))
|
||||||
|
))
|
||||||
|
)),
|
||||||
|
|
||||||
test_operator: $ => token(prec(1, seq('-', /[a-zA-Z]+/))),
|
test_operator: $ => token(prec(1, seq('-', /[a-zA-Z]+/))),
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,8 @@
|
||||||
"scope": "source.bash",
|
"scope": "source.bash",
|
||||||
"file-types": [
|
"file-types": [
|
||||||
"sh",
|
"sh",
|
||||||
"bash"
|
"bash",
|
||||||
|
"zsh"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
|
@ -46,6 +46,7 @@
|
||||||
">>"
|
">>"
|
||||||
"<"
|
"<"
|
||||||
"|"
|
"|"
|
||||||
|
(expansion_flags)
|
||||||
] @operator
|
] @operator
|
||||||
|
|
||||||
(
|
(
|
||||||
|
|
|
@ -433,8 +433,17 @@
|
||||||
"type": "SEQ",
|
"type": "SEQ",
|
||||||
"members": [
|
"members": [
|
||||||
{
|
{
|
||||||
"type": "STRING",
|
"type": "CHOICE",
|
||||||
"value": "while"
|
"members": [
|
||||||
|
{
|
||||||
|
"type": "STRING",
|
||||||
|
"value": "while"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "STRING",
|
||||||
|
"value": "until"
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "FIELD",
|
"type": "FIELD",
|
||||||
|
@ -2144,6 +2153,26 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"expansion_flags": {
|
||||||
|
"type": "SEQ",
|
||||||
|
"members": [
|
||||||
|
{
|
||||||
|
"type": "STRING",
|
||||||
|
"value": "("
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "REPEAT",
|
||||||
|
"content": {
|
||||||
|
"type": "PATTERN",
|
||||||
|
"value": "[^()]"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "STRING",
|
||||||
|
"value": ")"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
"expansion": {
|
"expansion": {
|
||||||
"type": "SEQ",
|
"type": "SEQ",
|
||||||
"members": [
|
"members": [
|
||||||
|
@ -2151,6 +2180,18 @@
|
||||||
"type": "STRING",
|
"type": "STRING",
|
||||||
"value": "${"
|
"value": "${"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "CHOICE",
|
||||||
|
"members": [
|
||||||
|
{
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "expansion_flags"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "BLANK"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "CHOICE",
|
"type": "CHOICE",
|
||||||
"members": [
|
"members": [
|
||||||
|
@ -2461,29 +2502,56 @@
|
||||||
"word": {
|
"word": {
|
||||||
"type": "TOKEN",
|
"type": "TOKEN",
|
||||||
"content": {
|
"content": {
|
||||||
"type": "REPEAT1",
|
"type": "SEQ",
|
||||||
"content": {
|
"members": [
|
||||||
"type": "CHOICE",
|
{
|
||||||
"members": [
|
"type": "CHOICE",
|
||||||
{
|
"members": [
|
||||||
"type": "PATTERN",
|
{
|
||||||
"value": "[^'\"<>{}\\[\\]()`$|&;\\\\\\s#]"
|
"type": "PATTERN",
|
||||||
},
|
"value": "[^#'\"<>{}\\[\\]()`$|&;\\\\\\s]"
|
||||||
{
|
},
|
||||||
"type": "SEQ",
|
{
|
||||||
|
"type": "SEQ",
|
||||||
|
"members": [
|
||||||
|
{
|
||||||
|
"type": "STRING",
|
||||||
|
"value": "\\"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "PATTERN",
|
||||||
|
"value": "[^\\s]"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "REPEAT",
|
||||||
|
"content": {
|
||||||
|
"type": "CHOICE",
|
||||||
"members": [
|
"members": [
|
||||||
{
|
{
|
||||||
"type": "STRING",
|
"type": "PATTERN",
|
||||||
"value": "\\"
|
"value": "[^'\"<>{}\\[\\]()`$|&;\\\\\\s]"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "PATTERN",
|
"type": "SEQ",
|
||||||
"value": "[^\\s]"
|
"members": [
|
||||||
|
{
|
||||||
|
"type": "STRING",
|
||||||
|
"value": "\\"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "PATTERN",
|
||||||
|
"value": "[^\\s]"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
}
|
||||||
}
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"test_operator": {
|
"test_operator": {
|
||||||
|
|
|
@ -638,6 +638,10 @@
|
||||||
"type": "concatenation",
|
"type": "concatenation",
|
||||||
"named": true
|
"named": true
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "expansion_flags",
|
||||||
|
"named": true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "regex",
|
"type": "regex",
|
||||||
"named": true
|
"named": true
|
||||||
|
@ -657,6 +661,11 @@
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "expansion_flags",
|
||||||
|
"named": true,
|
||||||
|
"fields": {}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "file_redirect",
|
"type": "file_redirect",
|
||||||
"named": true,
|
"named": true,
|
||||||
|
@ -1639,6 +1648,10 @@
|
||||||
"type": "unsetenv",
|
"type": "unsetenv",
|
||||||
"named": false
|
"named": false
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "until",
|
||||||
|
"named": false
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "variable_name",
|
"type": "variable_name",
|
||||||
"named": true
|
"named": true
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue