Add special lexing for regexes after `=~`
This commit is contained in:
parent
0d9f854862
commit
c7e42b8e96
|
@ -18,22 +18,35 @@ Words with special characters
|
|||
echo {o[k]}
|
||||
echo }}}
|
||||
echo ]]] ===
|
||||
[[ "35d8b" =~ ^[0-9a-fA-F] ]] || echo {nomatch}
|
||||
|
||||
---
|
||||
|
||||
(program
|
||||
(command (command_name (word)) (concatenation (word) (word)))
|
||||
(command (command_name (word)) (word))
|
||||
(command (command_name (word)) (word) (word))
|
||||
(list
|
||||
(bracket_command
|
||||
(string)
|
||||
(word)
|
||||
(concatenation (word) (word)))
|
||||
(command
|
||||
(command_name (word))
|
||||
(concatenation (word)))))
|
||||
(command (command_name (word)) (word) (word)))
|
||||
|
||||
=============================
|
||||
The regex operator
|
||||
=============================
|
||||
|
||||
[[ "35d8b" =~ ^[0-9a-fA-F] ]]
|
||||
[[ $CMD =~ (^|;)update_terminal_cwd($|;) ]]
|
||||
[[ ! " ${completions[*]} " =~ " $alias_cmd " ]]
|
||||
|
||||
---
|
||||
|
||||
(program
|
||||
(bracket_command
|
||||
(string)
|
||||
(regex))
|
||||
(bracket_command
|
||||
(simple_expansion (variable_name))
|
||||
(regex))
|
||||
(bracket_command
|
||||
(word)
|
||||
(string (expansion (subscript (variable_name) (word))))
|
||||
(string (simple_expansion (variable_name)))))
|
||||
|
||||
=============================
|
||||
Simple variable expansions
|
||||
|
|
20
grammar.js
20
grammar.js
|
@ -179,10 +179,20 @@ module.exports = grammar({
|
|||
$._statement
|
||||
)),
|
||||
|
||||
bracket_command: $ => choice(
|
||||
seq('[', repeat1($._expression), ']'),
|
||||
seq('[[', repeat1($._expression), ']]')
|
||||
),
|
||||
bracket_command: $ => {
|
||||
const contents = repeat1(choice(
|
||||
$._expression,
|
||||
seq('=~', choice(
|
||||
$.regex,
|
||||
$._expression
|
||||
))
|
||||
))
|
||||
|
||||
return choice(
|
||||
seq('[', contents, ']'),
|
||||
seq('[[', contents, ']]')
|
||||
)
|
||||
},
|
||||
|
||||
// Commands
|
||||
|
||||
|
@ -383,6 +393,8 @@ module.exports = grammar({
|
|||
seq('\\', noneOf('\\s'))
|
||||
))),
|
||||
|
||||
regex: $ => /\S+/,
|
||||
|
||||
_terminator: $ => choice(';', ';;', '\n', '&')
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue