From 3b26bb0847ff3e9720a357e9c3d25736a46d4ce0 Mon Sep 17 00:00:00 2001 From: Michael Aaron Murphy <mmstickman@gmail.com> Date: Sat, 1 Apr 2017 02:43:51 -0400 Subject: [PATCH] Update README --- README.md | 40 +++++++++++++++++++++++++------- src/parser/shell_expand/words.rs | 1 - 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index eada5d7a..009d3f16 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 a8d0d9d8..191038e7 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), -- GitLab