diff options
author | Chimrod <> | 2024-12-23 16:39:22 +0100 |
---|---|---|
committer | Chimrod <> | 2024-12-25 21:42:18 +0100 |
commit | 706e2132e443ed422912264f0401ee607d1d2ef5 (patch) | |
tree | e638f578c2e733f7e77b7fb119d2a549c4dbdfb0 | |
parent | cd25e70d1623ac5bd50be1ca2b30db793063c1cc (diff) |
Found a bug in the string interpretation
-rw-r--r-- | lib/qparser/lex_state.ml | 12 | ||||
-rw-r--r-- | lib/qparser/lexer.ml | 4 | ||||
-rw-r--r-- | test/literals.ml | 18 |
3 files changed, 26 insertions, 8 deletions
diff --git a/lib/qparser/lex_state.ml b/lib/qparser/lex_state.ml index 4b102b8..2ec1857 100644 --- a/lib/qparser/lex_state.ml +++ b/lib/qparser/lex_state.ml @@ -1,6 +1,4 @@ -(** This module provide functions used to parse the strings. - - *) +(** This module provide functions used to parse the strings. *) exception Out_of_context @@ -111,8 +109,12 @@ and dQuotedStringWraper : Lexbuf.stringWraper = let lexbuf = Lexbuf.buffer buffer in match%sedlex lexbuf with | single_quote -> - Buffer.add_char buf '\''; - wrap ~nested:true f buf buffer + if nested then ( + Buffer.add_char buf '\''; + wrap ~nested:false f buf buffer) + else ( + Buffer.add_char buf '\''; + wrap ~nested:true f buf buffer) | double_quote, double_quote -> Buffer.add_char buf '"'; wrap f buf buffer diff --git a/lib/qparser/lexer.ml b/lib/qparser/lexer.ml index 42f3c1c..814c97f 100644 --- a/lib/qparser/lexer.ml +++ b/lib/qparser/lexer.ml @@ -147,10 +147,10 @@ let rec read_quoted_string : Lexbuf.stringWraper -> Lexbuf.buffer_builder = result) else ( Buffer.add_string buf (Lexbuf.content buffer); - (f.wrap (read_quoted_string f)) buf buffer) + (f.wrap ~nested (read_quoted_string f)) buf buffer) | eol | any -> Buffer.add_string buf (Lexbuf.content buffer); - (f.wrap (read_quoted_string f)) buf buffer + (f.wrap ~nested (read_quoted_string f)) buf buffer | _ -> raise Not_found (** Track the kind of nested string inside a multiline string inside a diff --git a/test/literals.ml b/test/literals.ml index 90741ff..f98fa8f 100644 --- a/test/literals.ml +++ b/test/literals.ml @@ -47,7 +47,7 @@ let comment2 () = _test_instruction {|!'text <<expr>>'|} [ Tree.Ast.Comment _position ] (** A single quote inside a string does not mean we are starting nested string - *) +*) let direct_text () = _test_instruction {|"don't"|} [ Tree.Ast.Expression (Tree.Ast.Literal (_position, [ T.Text "don't" ])) ]; @@ -92,6 +92,21 @@ let expression () = ] )); ] +let multiple_expression () = + _test_instruction {|"'<<expr1>>'<<$expr2>>"|} + [ + Tree.Ast.Expression + (Tree.Ast.Literal + ( _position, + [ + T.Text "'<<expr1>>'"; + T.Expression + (Tree.Ast.Ident + { Tree.Ast.pos = _position; name = "$EXPR2"; index = None }); + T.Text ""; + ] )); + ] + let test = ( "Literals", [ @@ -111,4 +126,5 @@ let test = Alcotest.test_case "Quote in string" `Quick direct_text; Alcotest.test_case "elements_sequence" `Quick elements_sequence; Alcotest.test_case "expression" `Quick expression; + Alcotest.test_case "multiple_expression" `Quick multiple_expression; ] ) |