more segmentation
authorBen Pfaff <blp@cs.stanford.edu>
Mon, 8 Jul 2024 01:03:45 +0000 (18:03 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Mon, 8 Jul 2024 01:03:45 +0000 (18:03 -0700)
rust/src/lex/segment.rs

index d52dd888fc48ad97f0e5ac40aea9ddeb69946e85..ccede6c47306de61dcb37c038347cdfbd7d204d6 100644 (file)
@@ -707,13 +707,17 @@ impl Segmenter {
                 }
             } else if id_match("BEGIN", identifier) {
                 let (next_id, rest2) = self.next_id_in_command(rest, eof)?;
+                println!("next_id={next_id:?}");
                 if id_match("DATA", next_id) {
+                    println!("{}:{}", file!(), line!());
                     let rest2 = skip_spaces_and_comments(rest2, eof)?;
+                    println!("{}:{} {rest2:?}", file!(), line!());
                     let rest2 = if let Some(s) = rest2.strip_prefix('.') {
-                        skip_spaces(s, eof)?
+                        skip_spaces_and_comments(s, eof)?
                     } else {
                         rest2
                     };
+                    println!("{}:{}", file!(), line!());
                     if is_end_of_line(rest2, eof)? {
                         let s = &input[..input.len() - rest2.len()];
                         self.state = (
@@ -724,8 +728,10 @@ impl Segmenter {
                             },
                             Substate::empty(),
                         );
+                        println!("{}:{}", file!(), line!());
                         return Ok((rest, Type::Identifier));
                     }
+                    println!("{}:{}", file!(), line!());
                 }
             }
         }
@@ -1506,9 +1512,10 @@ FILE /*
         );
     }
 
-        #[test]
+    #[test]
     fn test_begin_data() {
-        print_segmentation(r#"begin data.
+        print_segmentation(
+            r#"begin data.
 end data.
 
 begin data. /*
@@ -1532,6 +1539,25 @@ begin data "xxx".
 begin data 123.
 not data
 
+"#,
+        );
+    }
+
+        #[test]
+    fn test_do_repeat() {
+        print_segmentation(r#"do repeat x=a b c
+          y=d e f.
+  do repeat a=1 thru 5.
+another command.
+second command
++ third command.
+end /* x */ /* y */ repeat print.
+end
+ repeat.
+do
+  repeat #a=1.
+  inner command.
+end repeat.
 "#);
     }