caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Some simple(?) questions about camlp4 <:quotations< ... >>
@ 2011-12-28 16:25 Richard W.M. Jones
  2011-12-28 17:23 ` Gabriel Scherer
  0 siblings, 1 reply; 2+ messages in thread
From: Richard W.M. Jones @ 2011-12-28 16:25 UTC (permalink / raw)
  To: caml-list


I'm writing a mini-DSL that'll use camlp4 quotations.  In general
http://brion.inria.fr/gallium/index.php/Quotation has been very
helpful, but I still have a few questions:

(1) Is any other syntax available for quotations apart from
<:foo< ... >> and the default quotation expander << ... >>?

(2) Is there any way to escape >> inside a quotation.  In particular
some of my quotations will contain C code, and >> is a C operator
(right shift).  This is not a show-stopper, but it'd be nice to be
able to offer a way for C code to contain right shifts, in a way that
is easily comprehensible to C programmers.

(3) In a custom-defined quotation expander, does the antiquotation
syntax $bar$ have any special meaning?  I want to use $variable
substitutions, so if $ is being treated specially this might cause
problems.

Rich.

-- 
Richard Jones
Red Hat

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Caml-list] Some simple(?) questions about camlp4 <:quotations< ... >>
  2011-12-28 16:25 [Caml-list] Some simple(?) questions about camlp4 <:quotations< ... >> Richard W.M. Jones
@ 2011-12-28 17:23 ` Gabriel Scherer
  0 siblings, 0 replies; 2+ messages in thread
From: Gabriel Scherer @ 2011-12-28 17:23 UTC (permalink / raw)
  To: Richard W.M. Jones; +Cc: caml-list

> (1) Is any other syntax available for quotations apart from
> <:foo< ... >> and the default quotation expander << ... >>?

No. That said, you could implement your own quotations mechanism as a
Camlp4 extension (changing the grammar of the language). The benefit
of the "official" quotations is that you don't touch the existing
OCaml grammar (... of Camlp4).

> (2) Is there any way to escape >> inside a quotation.

Camlp4 doesn't touch the content of quotations... except that the
lexer needs to know when they stop. ">>" is always interpreted as the
quotation delimiter, and this is hardcoded in the lexer, so you can't
change that. For example escaping with "\>>" would not work. Any
non-">>" symbol will be handled by you (that is, the parser you set up
for your quotation) and you can do as you wish. For example you could
specify to your users that you will always interpret ">\>" as if it
was a ">>", providing an escape mechanism.

> (3) In a custom-defined quotation expander, does the antiquotation
> syntax $bar$ have any special meaning?

No, if you have told the lexer that you doesn't want it to lex
antiquotations specially. This can be configured through a Camlp4
option.(Camlp4_config.antiquotations).

That said, I think antiquotations are very convenient for any DSL (as
it allows your users to compose pieces of DSL program using OCaml
constructs such let bindings, etc.). If I were you, I would change the
DSL syntax to free the $...$ for antiquotations.

On Wed, Dec 28, 2011 at 5:25 PM, Richard W.M. Jones <rich@annexia.org> wrote:
>
> I'm writing a mini-DSL that'll use camlp4 quotations.  In general
> http://brion.inria.fr/gallium/index.php/Quotation has been very
> helpful, but I still have a few questions:
>
> (1) Is any other syntax available for quotations apart from
> <:foo< ... >> and the default quotation expander << ... >>?
>
> (2) Is there any way to escape >> inside a quotation.  In particular
> some of my quotations will contain C code, and >> is a C operator
> (right shift).  This is not a show-stopper, but it'd be nice to be
> able to offer a way for C code to contain right shifts, in a way that
> is easily comprehensible to C programmers.
>
> (3) In a custom-defined quotation expander, does the antiquotation
> syntax $bar$ have any special meaning?  I want to use $variable
> substitutions, so if $ is being treated specially this might cause
> problems.
>
> Rich.
>
> --
> Richard Jones
> Red Hat
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa-roc.inria.fr/wws/info/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-12-28 17:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-28 16:25 [Caml-list] Some simple(?) questions about camlp4 <:quotations< ... >> Richard W.M. Jones
2011-12-28 17:23 ` Gabriel Scherer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).