diff options
Diffstat (limited to 'ocaml-binary-annot/camlp4/test/fixtures/gram-fold.ml')
| -rw-r--r-- | ocaml-binary-annot/camlp4/test/fixtures/gram-fold.ml | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/ocaml-binary-annot/camlp4/test/fixtures/gram-fold.ml b/ocaml-binary-annot/camlp4/test/fixtures/gram-fold.ml new file mode 100644 index 0000000000..5cd53b1793 --- /dev/null +++ b/ocaml-binary-annot/camlp4/test/fixtures/gram-fold.ml @@ -0,0 +1,21 @@ +open Camlp4.PreCast; +module G = MakeGram Lexer; +type t = [ A of t and t | B of string | C ]; +value main = G.Entry.mk "main"; +value rec length x acc = + match x with + [ A x y -> length x (length y acc) + | B _ -> succ acc + | C -> acc ]; +EXTEND G + GLOBAL: main; + main: + [ [ + l = FOLD1 (fun a b -> A (B a) b) (C) ident -> l + ] ]; + ident: + [ [ `LIDENT s -> s ] ]; +END; +let f = Sys.argv.(1) in +Format.printf "%d@." + (length (G.parse main (Loc.mk f) (Stream.of_channel (open_in f))) 0); |
