Add length operator in variable expansions
This commit is contained in:
parent
3abfbbd7bd
commit
403361626d
|
@ -136,3 +136,21 @@ find "`dirname $file`" -name "$base"'*'
|
|||
(word)
|
||||
(string (simple_expansion (variable_name)))
|
||||
(raw_string)))
|
||||
|
||||
=========================================
|
||||
Arrays and array expansions
|
||||
=========================================
|
||||
|
||||
a=()
|
||||
b=(1 2 3)
|
||||
|
||||
echo ${a[@]}
|
||||
echo ${#b[@]}
|
||||
|
||||
---
|
||||
|
||||
(program
|
||||
(environment_variable_assignment (variable_name) (array))
|
||||
(environment_variable_assignment (variable_name) (array (word) (word) (word)))
|
||||
(command (command_name) (expansion (variable_name)))
|
||||
(command (command_name) (expansion (variable_name))))
|
||||
|
|
11
grammar.js
11
grammar.js
|
@ -14,7 +14,8 @@ module.exports = grammar({
|
|||
$._heredoc_middle,
|
||||
$._heredoc_end,
|
||||
$.file_descriptor,
|
||||
$._empty_value
|
||||
$._empty_value,
|
||||
'#'
|
||||
],
|
||||
|
||||
extras: $ => [
|
||||
|
@ -241,11 +242,15 @@ module.exports = grammar({
|
|||
|
||||
expansion: $ => seq(
|
||||
'${',
|
||||
choice(
|
||||
$._variable_name,
|
||||
seq('#', $._variable_name),
|
||||
seq(
|
||||
$._variable_name,
|
||||
optional(seq(
|
||||
choice(':', ':?', '=', ':-'),
|
||||
$._expression
|
||||
)),
|
||||
)
|
||||
),
|
||||
'}'
|
||||
),
|
||||
|
||||
|
|
|
@ -847,16 +847,33 @@
|
|||
"type": "STRING",
|
||||
"value": "${"
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_variable_name"
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "#"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_variable_name"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_variable_name"
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
|
@ -883,9 +900,6 @@
|
|||
"name": "_expression"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -1111,6 +1125,10 @@
|
|||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_empty_value"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "#"
|
||||
}
|
||||
],
|
||||
"inline": [
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -13,6 +13,7 @@ enum TokenType {
|
|||
HEREDOC_END,
|
||||
FILE_DESCRIPTOR,
|
||||
EMPTY_VALUE,
|
||||
LENGTH_OPERATOR
|
||||
};
|
||||
|
||||
struct Scanner {
|
||||
|
@ -115,6 +116,16 @@ struct Scanner {
|
|||
}
|
||||
}
|
||||
|
||||
if (valid_symbols[LENGTH_OPERATOR]) {
|
||||
if (lexer->lookahead == '#') {
|
||||
advance(lexer);
|
||||
if (iswalpha(lexer->lookahead)) {
|
||||
lexer->result_symbol = LENGTH_OPERATOR;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue