ソースを参照

The parser now accept for…end

Chimrod 5 ヶ月 前
コミット
9798a11267
2 ファイル変更31 行追加3 行削除
  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;
     ] )