* passing argument in campl4 ?
@ 2005-03-24 5:29 Pietro Abate
2005-03-30 9:37 ` [Caml-list] " Hendrik Tews
0 siblings, 1 reply; 2+ messages in thread
From: Pietro Abate @ 2005-03-24 5:29 UTC (permalink / raw)
To: ocaml ml
Hi all,
I've this small example below that I'd like to modify to
pass information top-down, from aa to bb (this is definitely
possible using parser and streams).
I see bb as a function but as it is translated (below below)
is not entirely clear to me how I can pass a value from
aa: [[ "AA"; c = bb "val" -> "aa"^c ]];
to
bb arg: [[ a = INT; "BB" -> a ]];
I don't think this is directly possible (using the pseudo
syntax above), but I was wonder if you have a trick to
achieve something similar...
p
---------------- -------------------
(*pp camlp4o -I . pa_extend.cmo q_MLast.cmo *)
open Pcaml
let aa = Grammar.Entry.create gram "aa"
let bb = Grammar.Entry.create gram "bb"
EXTEND
aa: [[ "AA"; c = bb -> "aa"^c ]];
bb: [[ a = INT; "BB" -> a ]];
END
------------------dump ------------------------
(*pp camlp4o -I . pa_extend.cmo q_MLast.cmo *)
open Pcaml
let aa = Grammar.Entry.create gram "aa"
let bb = Grammar.Entry.create gram "bb"
let _ =
Grammar.extend
[Grammar.Entry.obj (aa : 'aa Grammar.Entry.e), None,
[None, None,
[[Gramext.Stoken ("", "AA");
Gramext.Snterm (Grammar.Entry.obj (bb : 'bb Grammar.Entry.e))],
Gramext.action
(fun (c : 'bb) _ (loc : Lexing.position * Lexing.position) ->
("aa" ^ c : 'aa))]];
Grammar.Entry.obj (bb : 'bb Grammar.Entry.e), None,
[None, None,
[[Gramext.Stoken ("INT", ""); Gramext.Stoken ("", "BB")],
Gramext.action
(fun _ (a : string) (loc : Lexing.position * Lexing.position) ->
(a : 'bb))]]]
--
++ WebBlog/Diary: http://blog.rsise.anu.edu.au/?q=pietro
++
++ "All great truths begin as blasphemies." -George Bernard Shaw
++ Please avoid sending me Word or PowerPoint attachments.
See http://www.fsf.org/philosophy/no-word-attachments.html
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Caml-list] passing argument in campl4 ?
2005-03-24 5:29 passing argument in campl4 ? Pietro Abate
@ 2005-03-30 9:37 ` Hendrik Tews
0 siblings, 0 replies; 2+ messages in thread
From: Hendrik Tews @ 2005-03-30 9:37 UTC (permalink / raw)
To: caml-list
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2005-03-30 9:37 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-03-24 5:29 passing argument in campl4 ? Pietro Abate
2005-03-30 9:37 ` [Caml-list] " Hendrik Tews
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox