diff options
-rw-r--r-- | lib/qparser/expression_parser.messages | 10 | ||||
-rw-r--r-- | lib/qparser/parser.mly | 2 | ||||
-rw-r--r-- | test/syntax_error.ml | 26 |
3 files changed, 26 insertions, 12 deletions
diff --git a/lib/qparser/expression_parser.messages b/lib/qparser/expression_parser.messages index b708d36..2ba26fc 100644 --- a/lib/qparser/expression_parser.messages +++ b/lib/qparser/expression_parser.messages @@ -1,3 +1,4 @@ +main: LOCATION_START EOL INTEGER SET main: LOCATION_START EOL IDENT SET Unexpected expression here. @@ -45,10 +46,6 @@ main: STAR Missing location name -main: LOCATION_START EOL INTEGER SET - - Unexpected expression here. - main: LOCATION_START EOL IF IDENT COLUMN EOL ELIF INTEGER SET The `ELIF` expression does not end properly. A `:` is expected before any instruction. @@ -114,3 +111,8 @@ main: LOCATION_START EOL IDENT STAR STAR main: LOCATION_START EOL IDENT MINUS STAR Unknown operator. Did you write '+ =' instead of '+=' ? + +dynamics: IDENT R_PAREN +dynamics: TEXT_MARKER ENTER_EMBED FUNCTION_NOARGS TEXT_MARKER + + Unbalanced paren diff --git a/lib/qparser/parser.mly b/lib/qparser/parser.mly index 469cf79..2fadccf 100644 --- a/lib/qparser/parser.mly +++ b/lib/qparser/parser.mly @@ -21,7 +21,7 @@ %start <(Analyzer.context -> Analyzer.Location.t)>main %start<(Analyzer.context -> Analyzer.Location.t)>dynamics -%on_error_reduce expression instruction unary_operator assignation_operator +%on_error_reduce instruction unary_operator assignation_operator %% diff --git a/test/syntax_error.ml b/test/syntax_error.ml index b92cf28..318cb2c 100644 --- a/test/syntax_error.ml +++ b/test/syntax_error.ml @@ -57,14 +57,15 @@ let elseif_no_column () = } let unclosed_paren () = - _test_instruction - {|(1 - |} + let expected = { level = Error; loc = _position; message = "Unexpected '('. Did you forgot a function before ?"; } + in + _test_instruction "(1" expected; + _test_instruction "'<<(1>>'" expected let act_no_column () = _test_instruction @@ -113,8 +114,11 @@ let missing_operand () = () let unknow_function () = - _test_instruction "a = ran(1, 2)" + let expected = { level = Error; loc = _position; message = "Unexpected expression here." } + in + _test_instruction "a = ran(1, 2)" expected; + _test_instruction "rand(1,2))" expected let inline_elif () = _test_instruction {| @@ -194,9 +198,8 @@ let missing_comparable () = _test_instruction "1 <= or 0" result; _test_instruction "1 = or 0" result -(** This code looks like a new location, but is actualy invalid. - The application should report the old location. - *) +(** This code looks like a new location, but is actualy invalid. The application + should report the old location. *) let location_change () = let result = { @@ -272,6 +275,14 @@ let nested_string_mess () = |} { level = Error; loc = _position; message = "Unclosed string" } +let unexpected_bracket () = + let expected = + { level = Error; loc = _position; message = "Unbalanced paren" } + in + _test_instruction {|a[]]|} expected; + _test_instruction {|"<<a[]]>>"|} expected; + _test_instruction "'<<rand(1,2))>>'" expected + let test = ( "Syntax Errors", [ @@ -295,4 +306,5 @@ let test = Alcotest.test_case "act: else" `Quick unclosed_act; Alcotest.test_case "+ =" `Quick unknown_operator; Alcotest.test_case "'<<''>>'" `Quick nested_string_mess; + Alcotest.test_case "a[]]" `Quick unexpected_bracket; ] ) |