Skip to content
Snippets Groups Projects
Commit 4ac9b428 authored by stratact's avatar stratact
Browse files

Add support for Multiple Indices in arrays (Fixes #472)

parent 1300013c
No related branches found
No related tags found
No related merge requests found
......@@ -75,3 +75,9 @@ end
let array = [ 1 2 3 4 5 ]
let as_string = @array
echo $as_string
let array = [1 2 3 4 5 6 7 8 9 10]
echo @array[0 1 7..]
echo @array[2 3 5..]
echo @array[5.. 3 2]
echo @array[5..8 1..3 9 2]
......@@ -54,3 +54,7 @@ a b c d e
😉
😉
1 2 3 4 5
1 2 8 9 10
3 4 6 7 8 9 10
6 7 8 9 10 4 3
6 7 8 2 3 10 3
......@@ -205,10 +205,32 @@ pub(crate) fn expand_string<E: Expander>(
match word {
WordToken::Brace(_) => {
contains_brace = true;
token_buffer.push(word);
}
_ => (),
WordToken::ArrayVariable(data, contains_quote, selection) => {
if let Select::Key(key) = selection {
if key.key.contains(' ') {
for index in key.key.split(' ') {
let select = index.parse::<Select>().unwrap_or(Select::None);
token_buffer.push(
WordToken::ArrayVariable(
data,
contains_quote,
select,
)
);
token_buffer.push(WordToken::Whitespace(" "));
}
token_buffer.pop(); // Pop out the last unneeded whitespace token
} else {
token_buffer.push(WordToken::ArrayVariable(data, contains_quote, Select::Key(key)));
}
} else {
token_buffer.push(WordToken::ArrayVariable(data, contains_quote, selection));
}
}
_ => token_buffer.push(word),
}
token_buffer.push(word);
}
None if original.is_empty() => {
token_buffer.push(WordToken::Normal("".into(), true, false));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment