Using menhir with sedlex
Asked Answered
M

1

9

I need to use menhir with sedlex for whatever reason (utf-8), but don't know how to make the generated parser depend on Sedlexing instead of Lexing. Any tips?

When I run

menhir --infer parser.mly

the generated program has lines with Lexing.... I could change it manually, but there must be another way, no?

Malevolent answered 15/6, 2015 at 19:9 Comment(0)
D
2

EDIT: The parser.ml that is generated should have references to Lexing. Sedlexing is used to create the lexbuf that you send in to the parser, but the parser doesn't care if that lexbuf was created by Lexing or Sedlexing, as long as it can use functions like Lexing.lex_start_p and Lexing.lex_curr_p on it.


I used something like

ocamlbuild -use-menhir -tag thread -use-ocamlfind -quiet -pkg menhirLib \
  -pkg sedlex test.native

where test.ml uses parser.mly via calls to Parser.


For completeness, the command that's run by ocamlbuild is:

menhir --ocamlc 'ocamlfind ocamlc -thread -package sedlex -package menhirLib' \
  --explain --infer parser.mly

See a full example at https://github.com/unhammer/ocaml_cg_streamparse (branch https://github.com/unhammer/ocaml_cg_streamparse/tree/match-singlechar-example shows a rule that matches a single code point like a or ß but not aa).

Dira answered 16/6, 2015 at 6:56 Comment(1)
Tried running your last command (I don't use ocamlbuild), but the resulting parser.ml still depends on Lexing...Cachucha

© 2022 - 2024 — McMap. All rights reserved.