smolkaj / nice-parser Goto Github PK
View Code? Open in Web Editor NEWNice parsers in OCaml without the boilerplate
Home Page: https://smolkaj.github.io/nice-parser/nice_parser/
License: MIT License
Nice parsers in OCaml without the boilerplate
Home Page: https://smolkaj.github.io/nice-parser/nice_parser/
License: MIT License
Hello, I found this project very helpful as I tried to figure out how to use sedlex.
I think people might benefit from seeing an example in dune, especially since RWO is using it now.
(Related: #2; is this the described “hack?”)
So, I'm relatively new to OCaml (hence using this project to try and understand parsing in OCaml! 🤣); but I don't understand why CPP-style source-transformation is necessary to reach Menhir's generated “token definitions”:
#include "Tokens.ml"
[@@deriving show, enumerate]
module Sedlexing = LexBuffer
open LexBuffer
(* ... so on, so forth ... *)
Can't we use some sort of built-in language mechanic to include the symbols from the generated Tokens
module into both Lexer.mli
and the (eventual) Lexer.ml
?
This has been a show-stopper for me; as a newbie, I still really depend on Merlin to understand what's going on and write code — and the CPPO invocation at the top of these files completely breaks Merlin, right now. But if there's no other way to do this … )'=
(It looks like somebody's trying to build support for it, ocaml/merlin#548, but that may be a long way off? I'm kinda an outsider, so I'm not sure. See also: let-def/merlin-extend#7.)
Hi,
i get Error: Uninterpreted extension 'sedlex.regexp' as seen below. menhir is version 20180703.
Any idea how to fix this?
Thanks,
Lacramioara
====
isar:07:06:16:~/ocaml-parsing$ make
time -p jbuilder build @install
ocamlopt src/.ocaml_parsing.objs/ocaml_parsing__Lexer.{cmx,o} (exit 2)
(cd _build/default && /home/eugen/.opam/4.06.0/bin/ocamlopt.opt -w -40 -g -I src/.ocaml_parsing.objs -I /home/eugen/.opam/4.06.0/lib/base -I /home/eugen/.opam/4.06.0/lib/base/caml -I /home/eugen/.opam/4.06.0/lib/base/shadow_stdlib -I /home/eugen/.opam/4.06.0/lib/bytes -I /home/eugen/.opam/4.06.0/lib/gen -I /home/eugen/.opam/4.06.0/lib/menhirLib -I /home/eugen/.opam/4.06.0/lib/ocaml/compiler-libs -I /home/eugen/.opam/4.06.0/lib/ppx_deriving -I /home/eugen/.opam/4.06.0/lib/result -I /home/eugen/.opam/4.06.0/lib/sedlex -I /home/eugen/.opam/4.06.0/lib/sexplib0 -I /home/eugen/.opam/4.06.0/lib/stdio -intf-suffix .ml -no-alias-deps -open Ocaml_parsing -o src/.ocaml_parsing.objs/ocaml_parsing__Lexer.cmx -c -impl src/Lexer.pp.ml)
File "src/Lexer.ml", line 42, characters 15-28:
Error: Uninterpreted extension 'sedlex.regexp'.
Howdy! I'm having some trouble building. Perhaps it is just a question of not having the right packages installed via OPAM.
First of all, the build begins with this:
oasis setup-clean
oasis setup
W: Cannot find source file matching module 'My_Tokens' in library parser.
W: Use InterfacePatterns or ImplementationPatterns to define this file with feature "source_patterns".
Second, at the end, I get this, which seems to be the bad part:
- /Users/perry/.opam/4.05.0/bin/ocamlfind ocamldep -package sedlex -package ppx_import -package core -package compiler-libs.common -package MenhirLib -package ppx_deriving,ppx_deriving.eq,ppx_deriving.enum,ppx_deriving.show,ppx_jane -modules src/My_Lexer.mli > src/My_Lexer.mli.depends
File "src/My_Lexer.mli", line 1, characters 58-67:
Error: Cannot locate deriver enumerate
Command exited with code 2.
Compilation unsuccessful after building 1 target (0 cached) in 00:00:00.
E: Failure("Command ''/Users/perry/.opam/4.05.0/bin/ocamlbuild' src/parser.cma test.byte -use-ocamlfind -use-menhir -cflags -w,@5+8@11@12-40,-short-paths -package ppx_deriving,ppx_deriving.eq,ppx_deriving.enum,ppx_deriving.show,ppx_jane -tag debug -tag tests' terminated with error code 10")
make[1]: *** [all] Error 1
make: *** [default] Error 2
Is it possible co compile to js_of_ocaml with this setup?
I know Core is incompatible with jsoo, but I tried just replacing it with Core_kernel and it seems to compile without problems (to native). Though I can't figure out how to compile to jsoo.
Here is my fork with Core_kernel: https://github.com/loxs/ocaml-parsing
Recommend changing (libraries (core ocaml_parsing))
to (libraries (base stdio ocaml_parsing))
.
So this section of the jbuild
seems to imply that it's temporary:
;; generate lexer -- temporary hack while ppx_sedlex and ppx_import are incompatible with jbuilder!!
(rule
((targets (Lexer.sedlex.ml))
(deps (Lexer.cppo.sedlex.ml Tokens.ml))
(action (run ${bin:cppo} ${<} -n -o ${@}))))
(rule
((targets (Lexer.mli))
(deps (Lexer.cppo.mli Tokens.ml))
(action (run ${bin:cppo} ${<} -n -o ${@}))))
(rule
((targets (Lexer.ml))
(deps (Lexer.sedlex.ml))
(action (run ${ocaml_where}/../sedlex/ppx_sedlex ${<} -o ${@}))))
What part of that is the "temporary hack"; and how, specifically, is dune/jbuilder incompatible with Sedlex? Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.