summary refs log tree commit diff stats
path: root/src/parser.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/parser.rs')
-rw-r--r--src/parser.rs19
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();