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]
|
||||
name = "tree-sitter-bash"
|
||||
description = "bash grammar for the tree-sitter parsing library"
|
||||
version = "0.19.0"
|
||||
version = "0.20.0"
|
||||
keywords = ["incremental", "parsing", "bash"]
|
||||
categories = ["parsing", "text-editors"]
|
||||
repository = "https://github.com/tree-sitter/tree-sitter-bash"
|
||||
|
@ -23,7 +23,7 @@ include = [
|
|||
path = "bindings/rust/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
tree-sitter = "0.19"
|
||||
tree-sitter = "0.20"
|
||||
|
||||
[build-dependencies]
|
||||
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
|
||||
|
||||
// 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 LOCALS_QUERY: &'static str = include_str!("../../queries/locals.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
|
||||
(command (command_name (word)) (word) (string (simple_expansion (variable_name))))
|
||||
(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',
|
||||
'#',
|
||||
];
|
||||
|
||||
module.exports = grammar({
|
||||
|
@ -491,8 +490,12 @@ module.exports = grammar({
|
|||
|
||||
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(
|
||||
'${',
|
||||
optional($.expansion_flags),
|
||||
optional(choice('#', '!')),
|
||||
optional(choice(
|
||||
seq(
|
||||
|
@ -537,10 +540,16 @@ module.exports = grammar({
|
|||
|
||||
_special_variable_name: $ => alias(choice('*', '@', '?', '-', '$', '0', '_'), $.special_variable_name),
|
||||
|
||||
word: $ => token(repeat1(choice(
|
||||
noneOf(...SPECIAL_CHARACTERS),
|
||||
seq('\\', noneOf('\\s'))
|
||||
))),
|
||||
word: $ => token(seq(
|
||||
choice(
|
||||
noneOf('#', ...SPECIAL_CHARACTERS),
|
||||
seq('\\', noneOf('\\s'))
|
||||
),
|
||||
repeat(choice(
|
||||
noneOf(...SPECIAL_CHARACTERS),
|
||||
seq('\\', noneOf('\\s'))
|
||||
))
|
||||
)),
|
||||
|
||||
test_operator: $ => token(prec(1, seq('-', /[a-zA-Z]+/))),
|
||||
|
||||
|
|
|
@ -30,7 +30,8 @@
|
|||
"scope": "source.bash",
|
||||
"file-types": [
|
||||
"sh",
|
||||
"bash"
|
||||
"bash",
|
||||
"zsh"
|
||||
]
|
||||
}
|
||||
]
|
||||
|
|
|
@ -46,6 +46,7 @@
|
|||
">>"
|
||||
"<"
|
||||
"|"
|
||||
(expansion_flags)
|
||||
] @operator
|
||||
|
||||
(
|
||||
|
|
|
@ -433,8 +433,17 @@
|
|||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "while"
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "while"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "until"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "FIELD",
|
||||
|
@ -2144,6 +2153,26 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
"expansion_flags": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "("
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "PATTERN",
|
||||
"value": "[^()]"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": ")"
|
||||
}
|
||||
]
|
||||
},
|
||||
"expansion": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
|
@ -2151,6 +2180,18 @@
|
|||
"type": "STRING",
|
||||
"value": "${"
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "expansion_flags"
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
|
@ -2461,29 +2502,56 @@
|
|||
"word": {
|
||||
"type": "TOKEN",
|
||||
"content": {
|
||||
"type": "REPEAT1",
|
||||
"content": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "PATTERN",
|
||||
"value": "[^'\"<>{}\\[\\]()`$|&;\\\\\\s#]"
|
||||
},
|
||||
{
|
||||
"type": "SEQ",
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "PATTERN",
|
||||
"value": "[^#'\"<>{}\\[\\]()`$|&;\\\\\\s]"
|
||||
},
|
||||
{
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "\\"
|
||||
},
|
||||
{
|
||||
"type": "PATTERN",
|
||||
"value": "[^\\s]"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "\\"
|
||||
"type": "PATTERN",
|
||||
"value": "[^'\"<>{}\\[\\]()`$|&;\\\\\\s]"
|
||||
},
|
||||
{
|
||||
"type": "PATTERN",
|
||||
"value": "[^\\s]"
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "\\"
|
||||
},
|
||||
{
|
||||
"type": "PATTERN",
|
||||
"value": "[^\\s]"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"test_operator": {
|
||||
|
|
|
@ -638,6 +638,10 @@
|
|||
"type": "concatenation",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "expansion_flags",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "regex",
|
||||
"named": true
|
||||
|
@ -657,6 +661,11 @@
|
|||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "expansion_flags",
|
||||
"named": true,
|
||||
"fields": {}
|
||||
},
|
||||
{
|
||||
"type": "file_redirect",
|
||||
"named": true,
|
||||
|
@ -1639,6 +1648,10 @@
|
|||
"type": "unsetenv",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "until",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "variable_name",
|
||||
"named": true
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue