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
This commit is contained in:
parent
7fb8506cbe
commit
4094e3a040
|
@ -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))
|
||||
|
|
15
grammar.js
15
grammar.js
|
@ -8,7 +8,6 @@ const SPECIAL_CHARACTERS = [
|
|||
'|', '&', ';',
|
||||
'\\',
|
||||
'\\s',
|
||||
'#',
|
||||
];
|
||||
|
||||
module.exports = grammar({
|
||||
|
@ -537,10 +536,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]+/))),
|
||||
|
||||
|
|
|
@ -2470,29 +2470,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": {
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue