From 8a02bbbd2bf42e2152faca16b95152744ef416d0 Mon Sep 17 00:00:00 2001 From: Chimrod <> Date: Sat, 20 Jan 2024 21:59:10 +0100 Subject: Reject a syntax which was incorrectly accepted --- lib/qparser/expression_parser.messages | 8 ++++++++ lib/qparser/parser.mly | 2 +- test/syntax.ml | 22 ---------------------- test/syntax_error.ml | 21 +++++++++++++++++++++ 4 files changed, 30 insertions(+), 23 deletions(-) diff --git a/lib/qparser/expression_parser.messages b/lib/qparser/expression_parser.messages index 5345ebf..707597b 100644 --- a/lib/qparser/expression_parser.messages +++ b/lib/qparser/expression_parser.messages @@ -95,3 +95,11 @@ main: LOCATION_START EOL IDENT GT EQUAL STAR main: LOCATION_START EOL IDENT LT EQUAL STAR Missing boolean after operator + +main: LOCATION_START EOL IF IDENT COLUMN EOL END TEXT_MARKER + + Unexpected instruction after `IF` `END` block. + +main: LOCATION_START EOL ACT IDENT COLUMN EOL END TEXT_MARKER + + Unexpected instruction after `ACT` `END` block. diff --git a/lib/qparser/parser.mly b/lib/qparser/parser.mly index 6fc9b8f..861d8b9 100644 --- a/lib/qparser/parser.mly +++ b/lib/qparser/parser.mly @@ -78,7 +78,7 @@ line_statement: COLUMN EOL+ s = line_statement* b = BODY - END TOKEN? + END line_sep { let expression = Analyzer.Expression.v e in diff --git a/test/syntax.ml b/test/syntax.ml index 3b7c2f9..47f1a25 100644 --- a/test/syntax.ml +++ b/test/syntax.ml @@ -444,27 +444,6 @@ end |} }; ] -let test_if2 () = - let index = Some Ast.(Integer (_position, "0")) in - let args = Ast.(Ident { pos = _position; name = "$ARGS"; index }) - and expr1 = Ast.(Literal (_position, [ T.Text "blockA" ])) - and expr2 = - Ast.(Expression (Literal (_position, [ T.Text "You are in block A" ]))) - in - _test_instruction {| if $ARGS[0] = 'blockA': - 'You are in block A' -end if|} - Ast. - [ - If - { - loc = _position; - then_ = (_position, BinaryOp (_position, Eq, args, expr1), [ expr2 ]); - elifs = []; - else_ = []; - }; - ] - let test_if_chained () = let value_0 = Ast.Integer (_position, "0") in _test_instruction {| if 0: @@ -937,7 +916,6 @@ let test = Alcotest.test_case "Comment6" `Quick test_comment6; Alcotest.test_case "Multiline Comment" `Quick test_long_comment; Alcotest.test_case "If" `Quick test_if; - Alcotest.test_case "If - end if" `Quick test_if2; Alcotest.test_case "If_chained" `Quick test_if_chained; Alcotest.test_case "If_equality" `Quick test_if_equality; Alcotest.test_case "If inline" `Quick test_if_inline; diff --git a/test/syntax_error.ml b/test/syntax_error.ml index 04b91ad..490ec96 100644 --- a/test/syntax_error.ml +++ b/test/syntax_error.ml @@ -206,6 +206,26 @@ let location_change () = check' ~msg:"The location name is not valid" string ~actual ~expected:"Location")) +let misplaced_if () = + _test_instruction {| +if $ARGS[0] = 'arg': + 0 +end if|} + { + level = Error; + loc = _position; + message = "Unexpected instruction after `IF` `END` block."; + }; + _test_instruction {| +act 'arg': + 0 +end if|} + { + level = Error; + loc = _position; + message = "Unexpected instruction after `ACT` `END` block."; + } + (* The location name *) let test = @@ -225,4 +245,5 @@ let test = Alcotest.test_case "Unclosed block" `Quick comment_as_operator; Alcotest.test_case "Missing comparable" `Quick missing_comparable; Alcotest.test_case "Location change" `Quick location_change; + Alcotest.test_case "Misplaced if" `Quick misplaced_if; ] ) -- cgit v1.2.3