From 5de6854200e3ab8851c04c4273e2a7c0fec59759 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ulysse=20G=C3=A9rard?= Date: Mon, 13 May 2024 17:12:10 +0200 Subject: [PATCH] [B] Merge pull request #1754 from voodoos/test-issue-1753 Test and fix wrong error with string literal in comment --- CHANGES.md | 3 +- src/ocaml/preprocess/lexer_raw.mll | 4 +- tests/test-dirs/errors/issue1753.t | 91 ++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+), 4 deletions(-) create mode 100644 tests/test-dirs/errors/issue1753.t diff --git a/CHANGES.md b/CHANGES.md index 475d73380d..756ae25497 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -3,9 +3,10 @@ merlin NEXT_VERSION + merlin binary - destruct: Removal of residual patterns (#1737, fixes #1560) - - Do not erase fields' names when destructing punned record fields (#1734, + - Do not erase fields' names when destructing punned record fields (#1734, fixes #1661) - Ignore SIGPIPE in the Merlin server process (#1746) + - Fix lexing of quoted strings in comments (#1754, fixes #1753) merlin 4.14 =========== diff --git a/src/ocaml/preprocess/lexer_raw.mll b/src/ocaml/preprocess/lexer_raw.mll index 947f110c7b..3fce4ec5c4 100644 --- a/src/ocaml/preprocess/lexer_raw.mll +++ b/src/ocaml/preprocess/lexer_raw.mll @@ -656,10 +656,8 @@ and comment state = parse state.buffer <- buffer; Buffer.add_char state.buffer '\"'; comment state lexbuf } - | "{" ('%' '%'? extattrident blank*)? lowercase* "|" + | "{" ('%' '%'? extattrident blank*)? (lowercase* as delim) "|" { - let delim = Lexing.lexeme lexbuf in - let delim = String.sub delim ~pos:1 ~len:(String.length delim - 2) in state.string_start_loc <- Location.curr lexbuf; Buffer.add_string state.buffer (Lexing.lexeme lexbuf); (catch (quoted_string delim state lexbuf) (fun e l -> match e with diff --git a/tests/test-dirs/errors/issue1753.t b/tests/test-dirs/errors/issue1753.t new file mode 100644 index 0000000000..426a1d948d --- /dev/null +++ b/tests/test-dirs/errors/issue1753.t @@ -0,0 +1,91 @@ +should be accepted + $ $MERLIN single errors -filename main.ml <<'EOF' | \ + > jq '.value[0]' + > (* {%ext|babar|} *) + > EOF + null + +should fail + $ $MERLIN single errors -filename main.ml <<'EOF' | \ + > jq '.value[0]' + > (* {%ext id|babar|} *) + > EOF + { + "start": { + "line": 1, + "col": 0 + }, + "end": { + "line": 1, + "col": 2 + }, + "type": "typer", + "sub": [ + { + "start": { + "line": 1, + "col": 0 + }, + "end": { + "line": 1, + "col": 2 + }, + "message": "String literal begins here" + } + ], + "valid": true, + "message": "This comment contains an unterminated string literal" + } + +should accept + $ $MERLIN single errors -filename main.ml <<'EOF' | \ + > jq '.value[0]' + > (* {%ext id|babar|id} *) + > EOF + null + +should accept + $ $MERLIN single errors -filename main.ml <<'EOF' | \ + > jq '.value[0]' + > (* {id|babar|id} *) + > EOF + null + +should accept + $ $MERLIN single errors -filename main.ml <<'EOF' | \ + > jq '.value[0]' + > (* {|babar|} *) + > EOF + null + +should fail + $ $MERLIN single errors -filename main.ml <<'EOF' | \ + > jq '.value[0]' + > (* {id|babar|} *) + > EOF + { + "start": { + "line": 1, + "col": 0 + }, + "end": { + "line": 1, + "col": 2 + }, + "type": "typer", + "sub": [ + { + "start": { + "line": 1, + "col": 0 + }, + "end": { + "line": 1, + "col": 2 + }, + "message": "String literal begins here" + } + ], + "valid": true, + "message": "This comment contains an unterminated string literal" + }