* Quotations and the functorial camlp4 interface
@ 2010-08-06 21:25 Hendrik Tews
2010-08-30 14:18 ` [Caml-list] " Hendrik Tews
2010-09-02 8:56 ` Hendrik Tews
0 siblings, 2 replies; 4+ messages in thread
From: Hendrik Tews @ 2010-08-06 21:25 UTC (permalink / raw)
To: caml-list
Hi,
Camlp4 parsers have a functorial interface (eg.
Camlp4OCamlParser.Make), which makes it possible to build two
camlp4 syntax modules in one application that parse different
syntaxes.
How can I add quotation support to such camlp4 parsing modules?
[Unfortunately, there is no functor
Camlp4OCamlRevisedQuotationExpander.Make.]
More in detail: Assume I obtained two camlp4 syntax modules SO
and SR, such that SO parses the orginal syntax and SR parses the
revised syntax. I now want to add quotation support to both SO
and SR. Following Camlp4OCamlRevisedQuotationExpander I do
module PreCast = Camlp4.PreCast
module type Camlp4Syntax = Camlp4.Sig.Camlp4Syntax
with module Loc = PreCast.Loc
and module Ast = PreCast.Ast
module Make
(HostSyntax : Camlp4Syntax)
(MakeQuotationSyntax : functor(EmptySyntax : Camlp4Syntax) -> Camlp4Syntax)
=
struct
module Gram = PreCast.MakeGram(PreCast.Lexer)
module EmptySyntax =
Camlp4.OCamlInitSyntax.Make(PreCast.Ast)(Gram)(HostSyntax.Quotation)
module QuotationSyntax = MakeQuotationSyntax(EmptySyntax)
module X =
Camlp4QuotationCommon.Make(QuotationSyntax)(HostSyntax.AntiquotSyntax)
end
now I can add the quotation support to SO and SR with
let module M = Make(SO)(Camlp4OCamlRevisedParser.Make) in
let module M = Make(SR)(Camlp4OCamlRevisedParser.Make) in
()
Could anybody comment on this?
The solution above is based on the following observations:
1. Camlp4QuotationCommon.Make(QuotationSyntax)(..) installs the
parser in QuotationSyntax as (various) quotation expander(s)
in QS.Quotation. This has only an effect on HostSyntax if the
references that Camlp4QuotationCommon.Make mutates are
actually identical in QuotationSyntax and HostSyntax.
2. The two MakeQuotationSyntax candidates
Camlp4OCamlRevisedParser.Make and Camlp4OCamlParser.Make do
only mutate the grammar entries in their argument modules.
Therefore one always has to create new EmptySyntax'es but can
reuse all the rest (especially Lexer, Ast and Loc) from
Camlp4.PreCast.
3. The functor Camlp4QuotationExpander.Make cannot be used
instead of Make above, because it creates reflective grammers
(where the host syntax and the quotation syntax are
identical).
Are these observations right?
Finally I have the following question:
4. Why does Camlp4OCamlRevisedQuotationExpander generate a new
grammar module Gram and does not reuse Camlp4.PreCast.Gram?
Can the latter be changed by some syntax extension?
[This post actually belongs to the thread
http://caml.inria.fr/pub/ml-archives/caml-list/2008/04/9d32f304eec6328db7ce857673842760.en.html,
which discusses how to make those functors SO and SR.]
Bye,
Hendrik Tews
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] Quotations and the functorial camlp4 interface
2010-08-06 21:25 Quotations and the functorial camlp4 interface Hendrik Tews
@ 2010-08-30 14:18 ` Hendrik Tews
2010-09-03 7:17 ` Hendrik Tews
2010-09-02 8:56 ` Hendrik Tews
1 sibling, 1 reply; 4+ messages in thread
From: Hendrik Tews @ 2010-08-30 14:18 UTC (permalink / raw)
To: caml-list
I wrote:
More in detail: Assume I obtained two camlp4 syntax modules SO
and SR, such that SO parses the orginal syntax and SR parses the
revised syntax. I now want to add quotation support to both SO
and SR. Following Camlp4OCamlRevisedQuotationExpander I do
There is one point that I found out myself in the meantime:
quotations are installed by mutating something inside the
Quotation submodule of a Camlp4Syntax. Further, the functor that
creates emoty syntaxes, OCamlInitSyntax, uses its Quotation
argument literally as Quotation submodule in its output.
Therefore, when creating the modules SO and SR it is important to
do so with freshly generated quotations modules (by
Camlp4.Struct.Quotation.Make).
How about the Loc submodule of Ast that is passed into
OCamlInitSyntax? There is the mutable Loc.name, which contains
the default location variable. If I reuse the Ast argument of
OCamlInitSyntax, will the mutable Loc.name be shared between the
outputs? Are there syntax extensions in the camlp4 distribution
that mutate Loc.name?
Bye,
Hendrik
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] Quotations and the functorial camlp4 interface
2010-08-06 21:25 Quotations and the functorial camlp4 interface Hendrik Tews
2010-08-30 14:18 ` [Caml-list] " Hendrik Tews
@ 2010-09-02 8:56 ` Hendrik Tews
1 sibling, 0 replies; 4+ messages in thread
From: Hendrik Tews @ 2010-09-02 8:56 UTC (permalink / raw)
To: caml-list
Hi,
I have another comment in this speek-to-myself-thread:
I wrote:
2. The two MakeQuotationSyntax candidates
Camlp4OCamlRevisedParser.Make and Camlp4OCamlParser.Make do
only mutate the grammar entries in their argument modules.
This is wrong: When they extend the syntax they register
keywords, which are apparently stored in a hash table in the
grammar module. Therefore they mutate the grammar module.
Therefore one always has to create new EmptySyntax'es but can
reuse all the rest (especially Lexer, Ast and Loc) from
Camlp4.PreCast.
At least the grammar argument to OCamlInitSyntax should always be
freshly generated by
Camlp4.Struct.Grammar.Static.Make(Camlp4.PreCast.Lexer) to start
with a fresh keyword hash.
4. Why does Camlp4OCamlRevisedQuotationExpander generate a new
grammar module Gram and does not reuse Camlp4.PreCast.Gram?
Can the latter be changed by some syntax extension?
This is answered now.
Bye,
Hendrik
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] Quotations and the functorial camlp4 interface
2010-08-30 14:18 ` [Caml-list] " Hendrik Tews
@ 2010-09-03 7:17 ` Hendrik Tews
0 siblings, 0 replies; 4+ messages in thread
From: Hendrik Tews @ 2010-09-03 7:17 UTC (permalink / raw)
To: caml-list
I wrote:
How about the Loc submodule of Ast that is passed into
OCamlInitSyntax? There is the mutable Loc.name, which contains
the default location variable. If I reuse the Ast argument of
OCamlInitSyntax, will the mutable Loc.name be shared between the
outputs?
Yes, it will, changing Loc.name has a global effect.
What's more problematic is that the Loc sources are not
functorized, that is, there is only one instance
(Camlp4.Struct.Loc) that one can use. Consequently, Loc.name is a
kind of global Camlp4 reference, similar to
Camlp4_config.quotation and Camlp4_config.antiquotations.
Are there syntax extensions in the camlp4 distribution
that mutate Loc.name?
A grep for Loc.name yields only one place that changes Loc.name:
the option -loc in Camlp4Bin.ml. So the answer is probably no.
Bye,
Hendrik
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-09-03 7:17 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-06 21:25 Quotations and the functorial camlp4 interface Hendrik Tews
2010-08-30 14:18 ` [Caml-list] " Hendrik Tews
2010-09-03 7:17 ` Hendrik Tews
2010-09-02 8:56 ` Hendrik Tews
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox