I wonder if anyone has any example code using compiler-libs Lexer module, eg. just to read in an OCaml *.ml file.
What I’m actually trying to do is lex some OCaml source files, to discover “long” multi-line strings that might be converted into quoted literals (ie. {|…|}) . So I want something that does the lexing step (but not parsing) and then lets me call my own function on each string that is found so I can decide if I want to convert it or not.
(Something like this commit but more automatically and across several large code bases, and yes I did try to write an OCaml lexer in Perl first, but that didn’t exactly go well!).
It is spinning because the OCaml lexer returns a dummy EOF token on end-of-file. You should end your recursive loop when you come across it. Otherwise, code looks OK to me.