caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jake Donham <jake@donham.org>
To: Raphael Proust <raphlalou@gmail.com>
Cc: Nicolas Pouillard <nicolas.pouillard@gmail.com>,
	caml-list@yquem.inria.fr
Subject: Re: [Caml-list] [Camlp4] Quotation expander with OCaml syntax
Date: Mon, 26 Jul 2010 09:30:16 -0700	[thread overview]
Message-ID: <AANLkTimdnN-QBRhKJ2TOr_kb1+_dAsE8Ro7mMhRcdmWd@mail.gmail.com> (raw)
In-Reply-To: <AANLkTimuFz7A=QbNu7jvdvjFxHpY_1W0_tbeVyt-B21Y@mail.gmail.com>

On Mon, Jul 26, 2010 at 8:41 AM, Raphael Proust <raphlalou@gmail.com> wrote:
> What I basically need is to get an AST with antiquotations and quotations being
> special nodes. How is this achievable w/o reimplementing a whole grammar?

There is already a special node for antiquotations, but not
quotations; see below.

> The alternative solution is to use raw strings, to find antiquotation marks, to
> split the string and to reinject it in the different files. Is there a way to
> keep precise _loc information this way?

This is more or less what already happens with quotations /
antiquotations. The lexer reads the whole quotation into a string
(checking that nested antiquotations / quotations are balanced, so it
doesn't stop too soon, but not otherwise processing them). The string
is then expanded (for OCaml AST quotations at least) by parsing it
into an OCaml AST, then lifting the AST (see my previous response),
then filtering the resulting AST to parsed antiquotations and insert
conversions (e.g. $`int:i$ becomes ExInt (_, string_of_int i)). The
nested parsing begins with the current location, so _loc information
is kept precisely. Antiquotations are represented as special nodes in
the OCaml AST containing the string (again, the whole antiquotation,
even if there is further nesting), which are parsed during the AST
filtering phase.

I'm not sure what syntactic problems Nicolas suggests you would run
into by reusing the existing parser and quotation mechanism. But it
might be a bit hairy to implement. One issue is that you can't just
drop antiquotations anywhere; where they can appear (and with what
tag) is given by the parser. If you want to go in this direction, the
place to start would be Camlp4QuotationCommon.ml, which implements
OCaml AST quotations / antiquotations. You can see there that you can
parse starting at arbitrary non-terminals, and you can filter the
OCaml AST without a giant pattern match using the Ast.map object.

Jake


  parent reply	other threads:[~2010-07-26 16:30 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <AANLkTikuoN4H0Hsx74JwW66J9jmtq+usDxtQPpYfSGbd@mail.gmail.com>
2010-07-26 14:41 ` Raphael Proust
2010-07-26 15:13   ` [Caml-list] " Nicolas Pouillard
2010-07-26 15:41     ` Joel Reymont
2010-07-26 16:05       ` Jake Donham
2010-07-26 15:41     ` Raphael Proust
2010-07-26 16:27       ` Nicolas Pouillard
2010-07-26 16:30       ` Jake Donham [this message]
2010-07-27  7:57         ` Raphael Proust
2010-07-26 20:08   ` bluestorm
2010-07-26 20:53     ` Raphael Proust
2010-07-27 13:22   ` Thomas.Gazagnaire
2010-07-27 14:38     ` Raphael Proust
2010-07-27 14:47     ` Vincent Balat

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=AANLkTimdnN-QBRhKJ2TOr_kb1+_dAsE8Ro7mMhRcdmWd@mail.gmail.com \
    --to=jake@donham.org \
    --cc=caml-list@yquem.inria.fr \
    --cc=nicolas.pouillard@gmail.com \
    --cc=raphlalou@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).