Explorar el Código

The parser now accept for…end

Chimrod hace 5 meses
padre
commit
9798a11267
Se han modificado 2 ficheros con 31 adiciones y 3 borrados
  1. 1 1
      lib/qparser/parser.mly
  2. 30 2
      test/syntax.ml

+ 1 - 1
lib/qparser/parser.mly

@@ -76,7 +76,7 @@ line_statement:
       step = option(pair(STEP, expression))
       COLUMN EOL+
       s = line_statement*
-      END
+      END EOL+
       {
           let variable = Helper.variable variable in
           let start = Analyzer.Expression.v start in

+ 30 - 2
test/syntax.ml

@@ -882,8 +882,35 @@ let test_stattxt () =
             { Tree.Ast.pos = _position; name = "$STATTXT"; index = None } );
     ]
 
-let test_for_end () = _test_instruction {|for a = 1 to 10:
-end|} []
+let test_for_end () =
+  _test_instruction {|for a = 1 to 10:
+end|}
+    [
+      Tree.Ast.For
+        {
+          loc = _position;
+          variable = { Tree.Ast.pos = _position; name = "A"; index = None };
+          start = Tree.Ast.Integer (_position, "1");
+          to_ = Tree.Ast.Integer (_position, "10");
+          step = None;
+          statements = [];
+        };
+    ]
+
+let test_for_end_with_step () =
+  _test_instruction {|for a = 1 to 10 step rnd:
+end|}
+    [
+      Tree.Ast.For
+        {
+          loc = _position;
+          variable = { Tree.Ast.pos = _position; name = "A"; index = None };
+          start = Tree.Ast.Integer (_position, "1");
+          to_ = Tree.Ast.Integer (_position, "10");
+          step = Some (Tree.Ast.Function (_position, T.Rnd, []));
+          statements = [];
+        };
+    ]
 
 let test =
   ( "Syntax",
@@ -955,4 +982,5 @@ let test =
       Alcotest.test_case "Precedence8" `Quick test_precedence8;
       Alcotest.test_case "stattxt" `Quick test_stattxt;
       Alcotest.test_case "for ... end" `Quick test_for_end;
+      Alcotest.test_case "for step ... end" `Quick test_for_end_with_step;
     ] )