Переглянути джерело

Removed the need for () after rnd

Chimrod 5 місяців тому
батько
коміт
976f80ed22

+ 1 - 1
lib/qparser/idents.ml

@@ -127,7 +127,7 @@ let _ =
       ("REPLACE", FUNCTION T.Replace);
       ("$REPLACE", FUNCTION T.Replace');
       ("RGB", FUNCTION T.Rgb);
-      ("RND", FUNCTION T.Rnd);
+      ("RND", FUNCTION_NOARGS T.Rnd);
       ("SAVEGAME", KEYWORD T.SaveGame);
       ("SELACT", FUNCTION T.Selact);
       ("$SELACT", IDENT "$SELACT");

+ 4 - 0
lib/qparser/qsp_expression.mly

@@ -44,6 +44,10 @@
     {
         (Analyzer.Expression.function_ $loc k arg)
     }
+    | k = FUNCTION_NOARGS
+    {
+        (Analyzer.Expression.function_ $loc k [])
+    }
 literal:
     | v = LITERAL { Qsp_syntax.T.Text v }
     | e = delimited(ENTER_EMBED, expression, LEAVE_EMBED) 

+ 1 - 0
lib/qparser/tokens.mly

@@ -40,6 +40,7 @@
 %token NO
 %token <Qsp_syntax.T.keywords>KEYWORD
 %token <Qsp_syntax.T.function_>FUNCTION
+%token <Qsp_syntax.T.function_>FUNCTION_NOARGS
 
 (* 
 (b) if the token was declared left-associative, then the conflict is resolved

+ 3 - 4
test/dup_cases.ml

@@ -20,11 +20,10 @@ end
 |} []
 
 (** The rnd function can generate different result, this is not a warning *)
-let ok_rnd () =
-  _test_instruction {|
-if rnd(): 
+let ok_rnd () = _test_instruction {|
+if rnd: 
     0
-elseif rnd():
+elseif rnd:
     0
 end
 |} []

+ 6 - 0
test/syntax.ml

@@ -707,6 +707,11 @@ let test_function2 () =
                [ Integer (_position, "0"); Integer (_position, "1") ] )));
     ]
 
+(** The RND function does not have parens after the name *)
+let test_rnd () =
+  _test_instruction "rnd"
+    [ Tree.Ast.Expression (Tree.Ast.Function (_position, T.Rnd, [])) ]
+
 let test_precedence4 () =
   _test_instruction "trim()" Ast.[ Expression (Function (_position, Trim, [])) ]
 
@@ -934,6 +939,7 @@ let test =
       Alcotest.test_case "Call nl" `Quick test_nl;
       Alcotest.test_case "Function iif" `Quick test_function;
       Alcotest.test_case "Function rand" `Quick test_function2;
+      Alcotest.test_case "Function rnd" `Quick test_rnd;
       Alcotest.test_case "Precedence4" `Quick test_precedence4;
       Alcotest.test_case "Precedence5" `Quick test_precedence5;
       Alcotest.test_case "Precedence6" `Quick test_precedence6;