Using menhir with celex

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

When i started

 menhir --infer parser.mly 

The generated program has lines with Lexing... I can change it manually, but there has to be another way, no?

+7
parsing ocaml menhir lexer
source share
1 answer

EDIT: The generated parser.ml must have links to Lexing. Sedlexing is used to create the lexbuf that you send to the parser, but the parser does not care if this lexbuf was created by Lexing or Sedlexing if it can use features 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 through calls to Parser.


For completeness, ocamlbuild's command is:

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

See the 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, for example a or รŸ but not aa ).

+2
source share

All Articles