Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

string litteral with an extension node is wrongly marked as being unterminated #1753

Closed
EmileTrotignon opened this issue Apr 23, 2024 · 3 comments · Fixed by #1754, ocaml/opam-repository#25902 or ocaml/opam-repository#26002

Comments

@EmileTrotignon
Copy link

The following code :

(* {%ext|babar|} *)

results in a syntax error displayed by lsp, even if the compiler is happy with it :
image
This was reproduced on emacs without lsp, so it is likely from the merlin parser.

@voodoos
Copy link
Collaborator

voodoos commented Apr 24, 2024

Thanks for the report @EmileTrotignon, I was able to reproduce the behavior you observe.

For reference, the manual says:

Furthermore, quoted strings {|...|} can be combined with extension nodes to embed foreign syntax fragments. Those fragments can be interpreted by a preprocessor and turned into OCaml code without requiring escaping quotes. A syntax shortcut is available for them:

{%%foo|...|}               === [%%foo{|...|}]
let x = {%foo|...|}        === let x = [%foo{|...|}]
let y = {%foo bar|...|bar} === let y = [%foo{bar|...|bar}]

For instance, you can use {%sql|...|} to represent arbitrary SQL statements – assuming you have a ppx-rewriter that recognizes the %sql extension.

It looks like Merlin lexer has diverged quite a bit from upstream for these cases.

@EmileTrotignon
Copy link
Author

Hi @voodoos
This syntax is not illegal, it is an extension node.

{%ext|abc|}

is a shortcut for

[%ext {|abc|} ]

I guess it must be documented in "language extension" : https://v2.ocaml.org/manual/extensionnodes.html#ss%3Abuiltin-extension-nodes
It should be rejected by the type checker as an uninterpreted extension if you do not have a ppx that handles it, but any parser should accept it.

@voodoos
Copy link
Collaborator

voodoos commented Apr 24, 2024

Yes my bad, I was editing my comment but you were too fast :-)

@voodoos voodoos linked a pull request Apr 25, 2024 that will close this issue
voodoos added a commit to voodoos/opam-repository that referenced this issue May 17, 2024
CHANGES:

Fri May 17 19:59:42 CET 2024

  + merlin binary
    - Support for OCaml 5.2 (ocaml/merlin#1757)
    - destruct: Removal of residual patterns (ocaml/merlin#1737, fixes ocaml/merlin#1560)
    - Do not erase fields' names when destructing punned record fields (ocaml/merlin#1734,
      fixes ocaml/merlin#1661)
    - Ignore SIGPIPE in the Merlin server process (ocaml/merlin#1746)
    - Fix lexing of quoted strings in comments (ocaml/merlin#1754, fixes ocaml/merlin#1753)
    - Improve cursor position detection in longidents (ocaml/merlin#1756)
    - Addition of a `merlin-lib.commands` library which disassociates the
      execution of commands from the `new_protocol`, from the binary, allowing
      it to be invoked from other projects (ocaml/merlin#1758)
    - New occurrences backend: Don't index occurrences when `merlin.hide`
      attribute is present. (ocaml/merlin#1768)
    - Use the new `uid_to_decl` table in 5.2's cmt files to get documentation.
      (ocaml/merlin#1773)
voodoos added a commit to voodoos/opam-repository that referenced this issue May 31, 2024
CHANGES:

May May 31 14:02:42 CET 2024

  + merlin binary
    - destruct: Removal of residual patterns (ocaml/merlin#1737, fixes ocaml/merlin#1560)
    - Do not erase fields' names when destructing punned record fields (ocaml/merlin#1734,
      fixes ocaml/merlin#1661)
    - Ignore SIGPIPE in the Merlin server process (ocaml/merlin#1746)
    - Fix lexing of quoted strings in comments (ocaml/merlin#1754, fixes ocaml/merlin#1753)
    - Improve cursor position detection in longidents (ocaml/merlin#1756)
voodoos added a commit to voodoos/opam-repository that referenced this issue May 31, 2024
CHANGES:

Fri May 31 14:02:42 CEST 2024

  + merlin binary
    - destruct: Removal of residual patterns (ocaml/merlin#1737, fixes ocaml/merlin#1560)
    - Do not erase fields' names when destructing punned record fields (ocaml/merlin#1734,
      fixes ocaml/merlin#1661)
    - Ignore SIGPIPE in the Merlin server process (ocaml/merlin#1746)
    - Fix lexing of quoted strings in comments (ocaml/merlin#1754, fixes ocaml/merlin#1753)
    - Improve cursor position detection in longidents (ocaml/merlin#1756)
voodoos added a commit to voodoos/opam-repository that referenced this issue May 31, 2024
CHANGES:

Fri May 31 14:02:42 CEST 2024

  + merlin binary
    - destruct: Removal of residual patterns (ocaml/merlin#1737, fixes ocaml/merlin#1560)
    - Do not erase fields' names when destructing punned record fields (ocaml/merlin#1734,
      fixes ocaml/merlin#1661)
    - Ignore SIGPIPE in the Merlin server process (ocaml/merlin#1746)
    - Fix lexing of quoted strings in comments (ocaml/merlin#1754, fixes ocaml/merlin#1753)
    - Improve cursor position detection in longidents (ocaml/merlin#1756)
voodoos added a commit to voodoos/opam-repository that referenced this issue May 31, 2024
CHANGES:

Fri May 31 14:02:42 CEST 2024

  + merlin binary
    - destruct: Removal of residual patterns (ocaml/merlin#1737, fixes ocaml/merlin#1560)
    - Do not erase fields' names when destructing punned record fields (ocaml/merlin#1734,
      fixes ocaml/merlin#1661)
    - Ignore SIGPIPE in the Merlin server process (ocaml/merlin#1746)
    - Fix lexing of quoted strings in comments (ocaml/merlin#1754, fixes ocaml/merlin#1753)
    - Improve cursor position detection in longidents (ocaml/merlin#1756)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants