Browse Source

Handle syntax error in string escape mecamism

Chimrod 1 month ago
parent
commit
b7cc3a4f42
2 changed files with 15 additions and 3 deletions
  1. 6 2
      lib/qparser/analyzer.ml
  2. 9 1
      test/syntax_error.ml

+ 6 - 2
lib/qparser/analyzer.ml

@@ -34,11 +34,15 @@ let rec parse :
               { code = Interpreter.Custom message; start_pos; end_pos }
           in
           Error err
-      | Lexer.UnclosedQuote ->
+      | Lexer.UnclosedQuote | Lex_state.Out_of_context ->
           let start_pos, end_pos = Lexbuf.positions l in
           let err =
             IncrementalParser.
-              { code = Interpreter.Custom "Unclosed text"; start_pos; end_pos }
+              {
+                code = Interpreter.Custom "Unclosed string";
+                start_pos;
+                end_pos;
+              }
           in
           Error err
     in

+ 9 - 1
test/syntax_error.ml

@@ -92,7 +92,7 @@ let missing_ampersand () =
 
 let unclose_comment () =
   _test_instruction {| ! that's it|}
-    { level = Error; loc = _position; message = "Unclosed text" }
+    { level = Error; loc = _position; message = "Unclosed string" }
 
 let syntax_error () =
   _test_instruction {|*clr $ cla|}
@@ -259,6 +259,13 @@ let unknown_operator () =
       message = "Unknown operator. Did you write '+ =' instead of '+=' ?";
     }
 
+let nested_string_mess () =
+  _test_instruction
+    {|
+    '<<func('…', '…')>>'
+|}
+    { level = Error; loc = _position; message = "Unclosed string" }
+
 let test =
   ( "Syntax Errors",
     [
@@ -280,4 +287,5 @@ let test =
       Alcotest.test_case "(()" `Quick unclosed_paren2;
       Alcotest.test_case "act: else" `Quick unclosed_act;
       Alcotest.test_case "+ =" `Quick unknown_operator;
+      Alcotest.test_case "'<<''>>'" `Quick nested_string_mess;
     ] )