Tuareg and ppx with strings like {sql|...|sql}

Hello,

I use tuareg/merlin and some ppx that define syntax like {sql|…|sql} or {html|…|html} and I would like
some support for syntax hilighting and indentation within those string.

Are there some solutions ?

Cheers,
Christophe

I suppose it depends on what editor you are using. If the editor features treesitter integration (neovim, emacs, zed,…), then the way to proceed would be to write a treesitter query to extract the string to be highlighted. Then it depends on your editor.

This video may be helpful.

1 Like

Thanks. What is the “most official” emacs mode based on treesitter. I found at least two git repo and nothing in opam.

I’m using dmitrig/ocaml-ts-mode as the basis for hacking tree-sitter support for OCaml. It only does Syntax highlighting with some missing bits and curiosities like having two major modes (one for .ml files and a second for .mli files that I haven’t quite worked out how to collapse into a single major mode).

Which ppxes? A klaxon went off in my mind pointing to "{c| |c}" does not supported nested use case · Issue #6856 · ocaml/ocaml · GitHub

And since this initial discussion, there is a lighter syntax for this use case

{%sql| |}
1 Like

Both are them are quite incomplete and are not actively developed from what I can tell. The older one has slightly more features and got submitted to MELPA, but these days installing packages straight from Git is trivial in Emacs. The font-locking is the older mode is broken, as the TS grammar has been changed slightly since the mode was originally created, and it’s codebase is quite unconventional by Emacs standards. The newer one is quite simple, but relies on Tuareg mode for the indentation.

I’ve recently started work on a new TreeSitter mode for Emacs that you can find here GitHub - bbatsov/neocaml: A modern, TreeSitter-powered, Emacs major mode for OCaml Right now only the font-locking is ready, but I’m hoping to have some basic indentation in place relatively soon. I didn’t name it ocaml-mode as I’m not sure how much effort I’ll be willing to commit here, and I didn’t name it ocaml-ts-mode, as more of those would be quite confusing. So far, things are going pretty well and I’m optimistic that I’ll manage to deliver a better Emacs experience for all OCamlers.