Questions tagged [camlp4]

CamlP4 is a parsing and pretty-printing framework for Objective Caml, often used as a preprocessor to extend OCaml syntax.

Camlp4 is a set of Objective Caml () libraries and tools for writing parsers and pretty-printers. Its most important use is to write extensions to the OCaml syntax.

The Objective Caml distribution includes CamlP4 since version 3.10.

There is also a separately-distributed CamlP5, which was called CamlP4 up to version 3.09.

65 questions
14
votes
1 answer

OCaml toplevel with syntax extensions

I don't know how to accomplish this in general, but I'll ask about one instance in particular for clarity: Sexplib looks interesting to me. I want to play around with it. I've downloaded it, installed it just fine (I'm pretty sure, anyway), etc. I…
koschei
  • 819
  • 6
  • 13
11
votes
2 answers

What's the "revised syntax" in OCaml?

When people refer to the "revised syntax" in OCaml, do they mean that this will become a new syntax for the language, or is it just an alternative syntax created in CamlP4? If it's the former, then when does the "revised syntax" become the…
aneccodeal
  • 8,531
  • 7
  • 45
  • 74
9
votes
1 answer

Writing a parser for a DSL in OCaml using ppx and extension point

Recently, it was announced in OCaml official github that Camlp4 is replaced by ppx rewriters and extension points (https://github.com/ocaml/camlp4): Camlp4 was part of the official OCaml distribution until its version 4.01.0. Since then it has…
Trung Ta
  • 1,582
  • 1
  • 16
  • 25
9
votes
4 answers

What does `[< >]` mean in OCaml?

I have seen some source code having let rec parse_document = parser | [< len = parse_int32; st; >] -> parse_list [] (ES.take_int32 len st) | [< >] -> malformed "parse_document" Can I know what is [< >] inside? it is too hard to…
Jackson Tale
  • 25,428
  • 34
  • 149
  • 271
7
votes
1 answer

What's the state of -ppx syntax extensions for OCaml?

There was a proposal from Alain Frisch of Lexifi over a year ago for an alternative to camlp4 for writing sytnax extensions making use of the -ppx flag added in OCaml 4.00. At that time he mentioned that there was still some work to be done…
aneccodeal
  • 8,531
  • 7
  • 45
  • 74
7
votes
0 answers

OCaml parser and structure of the grammar

I have been developing a parser for a tiny language whose syntax is the following P::= 1 | 0 | P+P | P and P | P wait(d) P Here is the code that i have written in Ocaml camlp4 action: [ ["act"; a = LIDENT -> Act(a)] | ["coact"; a…
David Link
  • 71
  • 1
6
votes
4 answers

Is it possible the get the AST for an OCaml program?

I'd like to be able to get the AST for a given OCaml program (I'd like to walk the AST and generate an instrumented version of the code or do some kind of transformation, for example). Do any of the OCaml tools support this functionality?
aneccodeal
  • 8,531
  • 7
  • 45
  • 74
6
votes
2 answers

Parsing an OCaml file with OCaml

I want to analysis OCaml files (.ml) using OCaml. I want to break the files into Abstract Syntax Trees for analysis. I have attempted to use camlp4 but have had no luck. Has anyone else successfully done this before? Is this the best way to parse an…
cmanning
  • 225
  • 3
  • 11
6
votes
1 answer

Why does annotating a type with sexp return cause Unbound value int_of_sexp?

Using the sexplib syntax extension to automatically generate serialization code for a type, as shown in many simple examples online: open Sexplib type t = { foo : int; bar : string; } with sexp let v = { foo = 3; bar = "baz"; } in sexp_of_t v Fails…
jrk
  • 2,896
  • 1
  • 22
  • 35
5
votes
1 answer

OCaml and preprocessor have incompatible versions error when installing tcoq

I was trying to install tcoq and I had the following error: "/Users/pinocchio/.opam/4.05.0/bin/ocamlfind" ocamlc -rectypes -w -3-52-56 -c grammar/compat5.ml OCAMLC -c -pp grammar/gramCompat.mlp >> Fatal error: OCaml and preprocessor have…
Charlie Parker
  • 5,884
  • 57
  • 198
  • 323
5
votes
1 answer

Printing OCaml AST as OCaml Code

I have this piece of code that contains a camlp4 quotation. let f_name = "my_func" <:str_item< value $lid:f_name$ a = a * 2 >> After running this through camlp4of, it produces this: Ast.StExp (_loc, (Ast.ExApp (_loc, (Ast.ExApp (_loc,…
Jason Yeo
  • 3,602
  • 3
  • 30
  • 38
5
votes
2 answers

OCamlbuild and camlp4 options

I'm using camlp4.macro to enable conditional compilation. I'm having problems informing OCamlbuild that certain files tagged with "use_jscore" must be preprocessed with a given camlp4 option. Here's what I have currently: let _ = dispatch begin…
Jon Smark
  • 2,528
  • 24
  • 31
4
votes
1 answer

camlp4 : there is no quotation expander available

The file test.ml contains only one line: let foo = <:expr< foo >> I then apply camlp4 to that file with this command line: camlp4o pa_extend.cmo test.ml The output is: File "test.ml", line 1, characters 12-24: While finding quotation "expr" in a…
Victor Nicollet
  • 24,361
  • 4
  • 58
  • 89
4
votes
2 answers

Annotations in OCaml

the title could be somewhat misleading so let me explain what I'm trying to achieve. I'm writing a programming language that has a plethora of operators which can work on multiple types with different behaviour. The implementation is evolving and…
Jack
  • 131,802
  • 30
  • 241
  • 343
4
votes
1 answer

Make compatible ocaml, camlp4, ppx, node, js_of_ocaml, ocamlbuild

After installing npm and node, compiling OCaml files with js_of_ocaml gave errors, thus I did opam switch reinstall system: :testweb $ opam switch reinstall system Your system compiler has been changed. Do you want to upgrade your OPAM installation…
SoftTimur
  • 5,630
  • 38
  • 140
  • 292
1
2 3 4 5