ocamllex

OCaml warning 31, compiler-libs, and ppx

纵然是瞬间 提交于 2020-01-13 19:47:31
问题 I'm porting my application from OCaml 4.02.3 to 4.03.0. Say you have the following in lexer.ml : type t = T [@@deriving sexp] let () = sexp_of_t |> ignore; print_endline "hai" I'm trying to run it as following: ocamlbuild -use-ocamlfind -pkg ppx_sexp_conv -cflags '-w @a-4-31' lexer.byte -- But I'm getting the following error: Warning 31: files lexer.cmo and /Users/vladimir/.opam/4.03.0+flambda/lib/ocaml/compiler-libs/ocamlcommon.cma(Lexer) both define a module named Lexer File "_none_", line

ocamllex regex syntax error

荒凉一梦 提交于 2019-12-12 00:54:32
问题 I have some basic ocamllex code, which was written by my professor, and seems to be fine: { type token = EOF | Word of string } rule token = parse | eof { EOF } | [’a’-’z’ ’A’-’Z’]+ as word { Word(word) } | _ { token lexbuf } { (*module StringMap = BatMap.Make(String) in *) let lexbuf = Lexing.from_channel stdin in let wordlist = let rec next l = match token lexbuf with EOF -> l | Word(s) -> next (s :: l) in next [] in List.iter print_endline wordlist } However, running ocamllex wordcount.mll

Is it possible to let several lexers share same ident definitions?

谁说胖子不能爱 提交于 2019-12-11 23:25:42
问题 I have several lexers: lexer_1.mll , lexer_2.mll , ... Some definitions of ident ( let ident = regexp ) are common and repeated in these files. For instance, the definition of INTEGER , FLOAT , ... Does anyone know if it is possible to define them the once for all somewhere, and let the .mll files call it? 回答1: I'm afraid there's no "pure OCaml" solution, as ident seems to be systematically inlined by ocamllex . You can still put your regexp definition in a file, and use cpp (or any other C

Make a table containing tokens visible for both .mly an .mll

纵然是瞬间 提交于 2019-12-11 19:05:57
问题 I would like to define a keyword_table which maps some strings to some tokens, and I would like to make this table visible for both parser.mly and lexer.mll . It seems that the table has to be defined in parser.mly , %{ open Utility (* where hash_table is defined to make a table from a list *) let keyword_table = hash_table [ "Call", CALL; "Case", CASE; "Close", CLOSE; "Const", CONST; "Declare", DECLARE; "DefBool", DEFBOOL; "DefByte", DEFBYTE ] %} However, I could NOT use it in lexer.mll ,

multiple error reporting with menhir: which token?

ぃ、小莉子 提交于 2019-12-10 14:05:21
问题 I am writing a small parser with Menhir + Ocamllex and I have two requirements I cannot seem to meet at the same time I would like to keep parsing after an error (to report more errors). I would like to print the token at which the error ocurred. I can do only 1) easily, by using the error token. I can also do only 2) easily, using the approach suggested for this question. However, I don't know of an easy way to achieve both. The way I handle errors right now goes something like this: pair: |

OCaml warning 31, compiler-libs, and ppx

不打扰是莪最后的温柔 提交于 2019-12-06 07:18:58
I'm porting my application from OCaml 4.02.3 to 4.03.0. Say you have the following in lexer.ml : type t = T [@@deriving sexp] let () = sexp_of_t |> ignore; print_endline "hai" I'm trying to run it as following: ocamlbuild -use-ocamlfind -pkg ppx_sexp_conv -cflags '-w @a-4-31' lexer.byte -- But I'm getting the following error: Warning 31: files lexer.cmo and /Users/vladimir/.opam/4.03.0+flambda/lib/ocaml/compiler-libs/ocamlcommon.cma(Lexer) both define a module named Lexer File "_none_", line 1: Error: Some fatal warnings were triggered (1 occurrences) I understand that compiler-libs has a