fix: immediate `#`s are allowed in a concatenation, as well as variable assignments

pull/559/head
Amaan Qureshi 2023-08-12 12:14:13 +07:00
parent a3935656b6
commit 91d8161935
No known key found for this signature in database
GPG Key ID: E67890ADC4227273
3 changed files with 80 additions and 3 deletions

@ -685,3 +685,66 @@ nix build nixpkgs#hello -v # comment with space
(word)
(word))
(comment))
================================================================================
Words containing # that are not comments
================================================================================
echo 'word'#not-comment # a legit comment
echo $(uname -a)#not-comment # a legit comment
echo `uname -a`#not-comment # a legit comment
echo $hey#not-comment # a legit comment
var=#not-comment # a legit comment
echo "'$var'" # -> '#not-comment'
--------------------------------------------------------------------------------
(program
(command
(command_name
(word))
(concatenation
(raw_string)
(word)))
(comment)
(command
(command_name
(word))
(concatenation
(command_substitution
(command
(command_name
(word))
(word)))
(word)))
(comment)
(command
(command_name
(word))
(concatenation
(command_substitution
(command
(command_name
(word))
(word)))
(word)))
(comment)
(command
(command_name
(word))
(concatenation
(simple_expansion
(variable_name))
(word)))
(comment)
(variable_assignment
(variable_name)
(word))
(comment)
(command
(command_name
(word))
(string
(simple_expansion
(variable_name))))
(comment))

@ -300,7 +300,7 @@ module.exports = grammar({
choice('=~', '=='),
choice($._literal, $.regex)
)
)))
))),
)),
command_name: $ => $._literal,
@ -317,7 +317,8 @@ module.exports = grammar({
field('value', choice(
$._literal,
$.array,
$._empty_value
$._empty_value,
alias($._comment_word, $.word),
))
),
@ -334,6 +335,7 @@ module.exports = grammar({
field('descriptor', optional($.file_descriptor)),
choice('<', '>', '>>', '&>', '&>>', '<&', '>&', '>|'),
field('destination', $._literal)
field('destination', $._literal),
)),
heredoc_redirect: $ => seq(
@ -449,6 +451,7 @@ module.exports = grammar({
choice(
$._primary_expression,
$._special_character,
alias($._comment_word, $.word),
)
))),
optional(seq($._concat, '$'))
@ -538,6 +541,17 @@ module.exports = grammar({
),
comment: $ => token(prec(-10, /#.*/)),
_comment_word: $ => token(prec(-9, seq(
choice(
noneOf(...SPECIAL_CHARACTERS),
seq('\\', noneOf('\\s'))
),
repeat(choice(
noneOf(...SPECIAL_CHARACTERS),
seq('\\', noneOf('\\s')),
"\\ ",
))
))),
_simple_variable_name: $ => alias(/\w+/, $.variable_name),

2
src/scanner.c vendored

@ -264,7 +264,7 @@ static bool scan(Scanner *scanner, TSLexer *lexer, const bool *valid_symbols) {
lexer->lookahead == '<' || lexer->lookahead == ')' ||
lexer->lookahead == '(' || lexer->lookahead == ';' ||
lexer->lookahead == '&' || lexer->lookahead == '|' ||
lexer->lookahead == '`' || lexer->lookahead == '#' ||
lexer->lookahead == '`' ||
(lexer->lookahead == '}' && valid_symbols[CLOSING_BRACE]) ||
(lexer->lookahead == ']' && valid_symbols[CLOSING_BRACKET]))) {
lexer->result_symbol = CONCAT;