Browse Source

parse comments

Getty Ritter 2 years ago
parent
commit
cc79e91db1
5 changed files with 59 additions and 2 deletions
  1. 2 0
      src/grammar.lalrpop
  2. 1 0
      tests/assn.matzo
  3. 1 0
      tests/atom_lit.matzo
  4. 6 2
      tests/exprs.matzo
  5. 49 0
      tests/exprs.parsed

+ 2 - 0
src/grammar.lalrpop

@@ -22,6 +22,8 @@ match {
     r"[a-z][A-Za-z0-9_-]*",
     r"[A-Z][A-Za-z0-9_-]*",
     r"[0-9]+",
+    r"\s*" => {},
+    r"\(\*([^*]|\*[^)])*\*\)" => {},
 }
 
 use crate::ast::*;

+ 1 - 0
tests/assn.matzo

@@ -1,2 +1,3 @@
+(* testing simple assignment statements *)
 x := 5;
 y := This;

+ 1 - 0
tests/atom_lit.matzo

@@ -1 +1,2 @@
+(* testing atom literals *)
 puts Foo

+ 6 - 2
tests/exprs.matzo

@@ -1,2 +1,6 @@
-puts This That;
-puts This | That;
+(* catenation *)
+puts This That The-Other;
+(* choice *)
+puts This | That | The-Other;
+(* weighted choice *)
+puts 5: This | That;

+ 49 - 0
tests/exprs.parsed

@@ -16,6 +16,11 @@
                                     "That",
                                 ),
                             ),
+                            Lit(
+                                Atom(
+                                    "The-Other",
+                                ),
+                            ),
                         ],
                     ),
                 },
@@ -49,6 +54,50 @@
                         ],
                     ),
                 },
+                Choice {
+                    weight: None,
+                    value: Cat(
+                        [
+                            Lit(
+                                Atom(
+                                    "The-Other",
+                                ),
+                            ),
+                        ],
+                    ),
+                },
+            ],
+        ),
+    ),
+    Puts(
+        Chc(
+            [
+                Choice {
+                    weight: Some(
+                        5,
+                    ),
+                    value: Cat(
+                        [
+                            Lit(
+                                Atom(
+                                    "This",
+                                ),
+                            ),
+                        ],
+                    ),
+                },
+                Choice {
+                    weight: None,
+                    value: Cat(
+                        [
+                            Lit(
+                                Atom(
+                                    "That",
+                                ),
+                            ),
+                        ],
+                    ),
+                },
             ],
         ),
     ),