Compare commits

..

5 Commits

Author SHA1 Message Date
Shadowfacts 3a793b84cd Use tree-sitter 0.20 2022-05-27 22:48:28 -04:00
Ryan Despain 275effdfc0
adding zsh expansion flagsSee https://zsh.sourceforge.io/Doc/Release/Expansion.html\#Parameter-Expansion-Flags (#115) 2021-12-15 08:53:04 -08:00
oxalica 4094e3a040
Handle words containing bare '#' (#109)
* Handle words containing bare '#'

Only a word beginning with a '#' starts a comment. A word can contain
'#' character without escaping as long as it is not the first character.

See: Bash Reference Manual section '3.1.3 Comments'
https://www.gnu.org/software/bash/manual/bash.html#Comments

* Regenerate
2021-11-01 09:59:27 -07:00
Martin Jambon 7fb8506cbe
Merge pull request #112 from tree-sitter/mj-until
Add support for 'until' loops
2021-10-16 14:38:43 -07:00
Martin Jambon c93070d720 Regenerate files 2021-10-16 01:46:22 -07:00
10 changed files with 127780 additions and 101841 deletions

View File

@ -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"

View File

@ -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");

View File

@ -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))

35
corpus/zsh.txt Normal file
View File

@ -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))))))

View File

@ -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]+/))),

View File

@ -30,7 +30,8 @@
"scope": "source.bash",
"file-types": [
"sh",
"bash"
"bash",
"zsh"
]
}
]

View File

@ -46,6 +46,7 @@
">>"
"<"
"|"
(expansion_flags)
] @operator
(

104
src/grammar.json vendored
View File

@ -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": {

13
src/node-types.json vendored
View File

@ -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

229425
src/parser.c vendored

File diff suppressed because it is too large Load Diff