Skip to content

Commit 4ede924

Browse files
authoredApr 30, 2024··
Merge pull request #1754 from voodoos/test-issue-1753
Test and fix wrong error with string literal in comment
2 parents 23e9de3 + eba2699 commit 4ede924

File tree

3 files changed

+94
-4
lines changed

3 files changed

+94
-4
lines changed
 

‎CHANGES.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ merlin NEXT_VERSION
33

44
+ merlin binary
55
- destruct: Removal of residual patterns (#1737, fixes #1560)
6-
- Do not erase fields' names when destructing punned record fields (#1734,
6+
- Do not erase fields' names when destructing punned record fields (#1734,
77
fixes #1661)
88
- Ignore SIGPIPE in the Merlin server process (#1746)
9+
- Fix lexing of quoted strings in comments (#1754, fixes #1753)
910

1011
merlin 4.14
1112
===========

‎src/ocaml/preprocess/lexer_raw.mll

+1-3
Original file line numberDiff line numberDiff line change
@@ -658,10 +658,8 @@ and comment state = parse
658658
state.buffer <- buffer;
659659
Buffer.add_char state.buffer '\"';
660660
comment state lexbuf }
661-
| "{" ('%' '%'? extattrident blank*)? lowercase* "|"
661+
| "{" ('%' '%'? extattrident blank*)? (lowercase* as delim) "|"
662662
{
663-
let delim = Lexing.lexeme lexbuf in
664-
let delim = String.sub delim ~pos:1 ~len:(String.length delim - 2) in
665663
state.string_start_loc <- Location.curr lexbuf;
666664
Buffer.add_string state.buffer (Lexing.lexeme lexbuf);
667665
(catch (quoted_string delim state lexbuf) (fun e l -> match e with

‎tests/test-dirs/errors/issue1753.t

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
should be accepted
2+
$ $MERLIN single errors -filename main.ml <<'EOF' | \
3+
> jq '.value[0]'
4+
> (* {%ext|babar|} *)
5+
> EOF
6+
null
7+
8+
should fail
9+
$ $MERLIN single errors -filename main.ml <<'EOF' | \
10+
> jq '.value[0]'
11+
> (* {%ext id|babar|} *)
12+
> EOF
13+
{
14+
"start": {
15+
"line": 1,
16+
"col": 0
17+
},
18+
"end": {
19+
"line": 1,
20+
"col": 2
21+
},
22+
"type": "typer",
23+
"sub": [
24+
{
25+
"start": {
26+
"line": 1,
27+
"col": 0
28+
},
29+
"end": {
30+
"line": 1,
31+
"col": 2
32+
},
33+
"message": "String literal begins here"
34+
}
35+
],
36+
"valid": true,
37+
"message": "This comment contains an unterminated string literal"
38+
}
39+
40+
should accept
41+
$ $MERLIN single errors -filename main.ml <<'EOF' | \
42+
> jq '.value[0]'
43+
> (* {%ext id|babar|id} *)
44+
> EOF
45+
null
46+
47+
should accept
48+
$ $MERLIN single errors -filename main.ml <<'EOF' | \
49+
> jq '.value[0]'
50+
> (* {id|babar|id} *)
51+
> EOF
52+
null
53+
54+
should accept
55+
$ $MERLIN single errors -filename main.ml <<'EOF' | \
56+
> jq '.value[0]'
57+
> (* {|babar|} *)
58+
> EOF
59+
null
60+
61+
should fail
62+
$ $MERLIN single errors -filename main.ml <<'EOF' | \
63+
> jq '.value[0]'
64+
> (* {id|babar|} *)
65+
> EOF
66+
{
67+
"start": {
68+
"line": 1,
69+
"col": 0
70+
},
71+
"end": {
72+
"line": 1,
73+
"col": 2
74+
},
75+
"type": "typer",
76+
"sub": [
77+
{
78+
"start": {
79+
"line": 1,
80+
"col": 0
81+
},
82+
"end": {
83+
"line": 1,
84+
"col": 2
85+
},
86+
"message": "String literal begins here"
87+
}
88+
],
89+
"valid": true,
90+
"message": "This comment contains an unterminated string literal"
91+
}

0 commit comments

Comments
 (0)
Please sign in to comment.