使用mendir与sedlex

Oll*_*edt 8 parsing ocaml lexer menhir

无论出于何种原因,我都需要使用mendir和sedlex(utf-8),但是不知道如何使生成的解析器依赖Sedlexing而不是Lexing.有小费吗?

我跑的时候

menhir --infer parser.mly
Run Code Online (Sandbox Code Playgroud)

生成的程序有行Lexing....我可以手动更改它,但必须有另一种方式,不是吗?

unh*_*mer 2

编辑:生成的 parser.ml应该引用 Lexing。Sedlexing 用于创建lexbuf发送到解析器的 lexbuf,但解析器并不关心 lexbuf 是由 Lexing 还是 Sedlexing 创建的,只要它可以使用类似 和 的函数Lexing.lex_start_p即可Lexing.lex_curr_p

\n\n
\n\n

我用过类似的东西

\n\n
ocamlbuild -use-menhir -tag thread -use-ocamlfind -quiet -pkg menhirLib \\\n  -pkg sedlex test.native\n
Run Code Online (Sandbox Code Playgroud)\n\n

其中 test.ml 通过调用 Parser 使用 parser.mly。

\n\n
\n\n

为了完整起见,ocamlbuild 运行的命令是:

\n\n
menhir --ocamlc \'ocamlfind ocamlc -thread -package sedlex -package menhirLib\' \\\n  --explain --infer parser.mly\n
Run Code Online (Sandbox Code Playgroud)\n\n

请参阅https://github.com/unhammer/ocaml_cg_streamparse \n(分支https://github.com/unhammer/ocaml_cg_streamparse/tree/match-singlechar-example显示匹配单个代码点的规则,例如a\xc3\x9f但不是aa)。

\n