How does tuareg-mode know when output is complete?

I’ve defined some custom pretty-printers for the OCaml toplevel, and when I use them in a tuareg-mode interactive buffer, it doesn’t seem to detect that the output has ended, and there’s a new prompt. Specifically, this means that when I type in a new phrase and hit RET, it doesn’t do anything; I need to hit SHIFT-RET. Now, this isn’t a big deal, but it’s annoying, so I wondered "how does tuareg-mode figure out when it’s at a new prompt? And looking in the elisp source, I couldn’t figure it out, so I thought I’d ask if anybody knows, or has pointers to where I could start in the elisp.

For concreteness, here’s an example of input&output where tuareg doesn’t seem to understand that it’s at a new prompt:
input:

# let ([], qc') = {|
let q0 = qubit() in
(q0)
|} |> qcircuit_from_string ;;

output:

Line 1, characters 4-13:
1 | let ([], qc') = {|
        ^^^^^^^^^
Warning 8 [partial-match]: this pattern-matching is not exhaustive.
Here is an example of a case that is not matched:
(_::_, _)
val qc' : Qlam_syntax.SYN.qcirc_t = <:circuit< 
let q0 = qubit () in
(q0) >>
# 

After that last #, if I type in (for example) 1 ;; and hit RET, I get a message in the Emacs minbuffer Note: REPL processing requires a terminating ';;' or use S-return.

Any advice appreciated.

tuareg-interactive-send-input checks, before it sends input to the ocaml process, whether you’re currently in a literal or comment (tuareg-in-literal-or-comment-p). My guess is that it’s just getting confused because line 2 of the error message includes an opening delimited string quote {| but there is no corresponding close quote in the buffer. If I’m right, it probably doesn’t have anything to do with pretty-printers, it’s just sort of unlucky that the compiler’s error message includes an unterminated quote.

I suppose a dumb hack might be to type "|}" ;; and then press S-RET?

1 Like

Thank you! Your pointer led me to the solution. Which was … to suppress that particular warning at that particular location, viz:

let [@warning "-8"] ([], qc) = {| let q = qubit() in let q = tg q in (q) |} |> qcircuit_from_string ;;

Voila!

1 Like