[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Hendrik Tews <tews@t...> |
| Subject: | Re: [Caml-list] passing argument in campl4 ? |
Pietro Abate <Pietro.Abate@anu.edu.au> writes:
aa: [[ "AA"; c = bb "val" -> "aa"^c ]];
to
bb arg: [[ a = INT; "BB" -> a ]];
The camlp4 reference manual
(http://caml.inria.fr/pub/docs/manual-camlp4/manual005.html) says
the syntax of a rule is
{ pattern = } symbol ; ... { pattern = } symbol { -> action }
so you can't pass an argument to bb.
I can think two possible solutions:
1. Extend the camlp4 syntax for grammar extentions with a new
metasymbol "bb" that takes one argument, similar to the
metasymbols LIST0 and LIST1
2. Use something like
aa: [[ x = do_the_aa_rule -> ... ]]
with
let do_the_aa_rule = Grammar.Entry.of_parser gram "do_the_aa_rule"
(* a (Token.t Stream.t -> 'a) function,
where 'a is the type of x above *)
The ocaml parser distributed with camlp4 contains examples for
the latter technique, see for instance infixop0 or test_label_eq
in camlp4/etc/pa_o.ml. Further, these sources seem to indicate
that there is no nice solution to your problem: The levels "||"
to "**" of the entry expr could benefit from some more
abstraction.
Bye,
Hendrik