diff --git a/README.md b/README.md index eada5d7a376885ac8895308d70f88a156c83e9ca..009d3f162d638c5de93211a43a402b144bfb86a3 100644 --- a/README.md +++ b/README.md @@ -17,9 +17,9 @@ core functionality is complete. Features below: - [x] Array Expressions (**[]**) - [x] Array-based Command Substitution (**@[]**) - [x] String-based Command Substitution (**$()**) -- [ ] String-to-Array Methods (**@split(var, ' ')**) -- [ ] Array-to-String Methods (**$join(array, ', ')**) -- [ ] Array Splicing +- [ ] Array Methods (**@split(var, ' ')**) +- [ ] String Methods (**$join(array, ', ')**) +- [x] Array Splicing - [ ] Maps - [x] For Loops - [ ] Foreach Loops @@ -191,16 +191,38 @@ echo @braced_array echo @{braced_array} ``` -Arrays may also be spliced when an index or index range is supplied: +Arrays may also be sliced when an index or index range is supplied: + +#### Slice by Index + +Slicing by an index will take a string from an array: ```ion -# Slicing not yet implemented +let array = [ 1 2 3 ] echo @array[0] -echo @array[0..3] +echo @array[1] +echo @array[2] + +echo [ 1 2 3 ][0] +echo [ 1 2 3 ][1] +echo [ 1 2 3 ][2] + +echo @[echo 1 2 3][0] +echo @[echo 1 2 3][1] +echo @[echo 1 2 3][2] +``` + +#### Slice by Range -let i = 1 -echo @array[$i] -echo @array[$i+1] +Slicing by range will take a subsection of an array as a new array: + +```ion +let array = [ 1 2 3 4 5 ] +echo @array[0..1] +echo @array[0...1] +echo @array[..3] +echo @array[3..] +echo @array[..] ``` ### Commands diff --git a/src/parser/shell_expand/words.rs b/src/parser/shell_expand/words.rs index a8d0d9d84f83958d81fbcc3ab706301de385f7a1..191038e7ae188bd09048c4de7b6acb766c78289b 100644 --- a/src/parser/shell_expand/words.rs +++ b/src/parser/shell_expand/words.rs @@ -16,7 +16,6 @@ const DQUOTE: u8 = 4; #[derive(Debug, PartialEq, Copy, Clone)] pub enum Index { - // TODO: Ranged and ID All, None, ID(usize),