diff options
author | SoniEx2 <endermoneymod@gmail.com> | 2022-11-13 12:30:11 -0300 |
---|---|---|
committer | SoniEx2 <endermoneymod@gmail.com> | 2022-11-13 12:30:11 -0300 |
commit | 72397506c3529f4878b5a1cf8205599764ac4088 (patch) | |
tree | f8fe6ece751cff882a3e6f8331206726d3736eea /src/parser.rs | |
parent | 44a6ee680308a3d756ef7c17db2f64518bb2b493 (diff) |
Finish most "core" VM functionality
Still need to do lists
Diffstat (limited to 'src/parser.rs')
-rw-r--r-- | src/parser.rs | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/src/parser.rs b/src/parser.rs index 0698b6b..a11b68c 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -218,12 +218,13 @@ impl_trait! { match self_.root.tokens.drain(self_.len..).as_slice() { &[ PatternToken::Arrow, - PatternToken::KeySubtree(index), + PatternToken::KeySubtree(index, optional), ref name_value @ .., PatternToken::End, ] => { let tag = PatternElement::Tag { - key_subtree: Some(index), + key_subtree: index, + optional, }; self_.root.consts.protos.last_mut().unwrap().push(tag); let value = collect_name_and_value(name_value); @@ -234,9 +235,7 @@ impl_trait! { ref name_value @ .., PatternToken::End, ] => { - let tag = PatternElement::Tag { - key_subtree: None, - }; + let tag = PatternElement::EmptyTag; self_.root.consts.protos.last_mut().unwrap().push(tag); let value = collect_name_and_value(name_value); self_.root.consts.protos.last_mut().unwrap().push(value); @@ -627,7 +626,7 @@ where })) } - /// key_subtree <- sp '[' sp ( matcher / name sp matcher? ) sp subtree sp ( ']' / unexpected_token / unexpected_end ) sp + /// key_subtree <- sp '[' sp ( matcher / name sp matcher? ) sp subtree sp ( ']' / unexpected_token / unexpected_end ) ( '?'? -> MarkSkippable ) sp // ( '?'? -> MarkSkippable ) fn key_subtree(&mut self, s: &mut &'s str) -> Result<bool, PatternError<'s>> { let mut cursor = *s; @@ -657,16 +656,16 @@ where || subtree.unexpected_end(&mut cursor)? ); + let optional = strip_prefix(&mut cursor, "?"); subtree.sp(&mut cursor); - //let skippable = strip_prefix(&mut cursor, "?"); *s = cursor; let id = subtree.commit(); - self.tokens.push(PatternToken::KeySubtree(id)); + self.tokens.push(PatternToken::KeySubtree(id, optional)); true })) } - /// value_subtree <- sp '(' sp subtree sp ( ')' / unexpected_token / unexpected_end ) sp ( '?'? -> MarkSkippable ) + /// value_subtree <- sp '(' sp subtree sp ( ')' / unexpected_token / unexpected_end ) ( '?'? -> MarkSkippable ) sp fn value_subtree(&mut self, s: &mut &'s str) -> Result<bool, PatternError<'s>> { let mut cursor = *s; Ok(lblock!('matches: { @@ -683,8 +682,8 @@ where || subtree.unexpected_end(&mut cursor)? ); - subtree.sp(&mut cursor); let optional = strip_prefix(&mut cursor, "?"); + subtree.sp(&mut cursor); *s = cursor; if !subtree.is_empty() { let id = subtree.commit(); |