caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Aaron Bohannon <bohannon@cis.upenn.edu>
To: blue storm <bluestorm.dylc@gmail.com>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] camlp5/revised syntax questions
Date: Thu, 8 Oct 2009 10:39:51 -0400	[thread overview]
Message-ID: <c413fcb70910080739t7266467clf946d4d7be0c759a@mail.gmail.com> (raw)
In-Reply-To: <527cf6bc0910071316y233ecd35va02bfca2aa17d9c9@mail.gmail.com>

Thanks for your detailed reply.  I had a suspicion I would have to
read the source code to get the all of the necessary documentation.
However, I'm still missing some basic point here.

On Wed, Oct 7, 2009 at 4:16 PM, blue storm <bluestorm.dylc@gmail.com> wrote:
> The different "level names" are not absolute among all camlp4 grammars
> : they're a property of each grammar rule of each grammar. If you want
> to "modify" a specific grammar (that is, EXTEND it), you must check
> the different levels available in the definition.

Yes, I understand that.  But how do you specify which grammar your
file is extending?  My file is structured like this:

#load "pa_extend.cmo";
#load "q_MLast.cmo";
open Pcaml;

EXTEND
  GLOBAL: expr;
  ...
END;

So where did I specify whether I was extending the original syntax or
the revised syntax (or some other grammar entirely)?  I suppose I must
have implicitly chosen the original syntax because my code works fine
on that.

> While concrete syntaxes for revised and classical syntax are
> different, the abstract syntax tree is the same. Camlp4 quotations
> works by replacing (using camlp4) the quotation you wrote by the
> concrete ocaml AST representation.

Yes, this point is crystal clear, and I have no problem writing the
quotations in the revised syntax.

> In your specific case, you can parse whatever syntax you want using
> the "<-" operator, then output the corresponding AST using a quotation
> in the revised syntax, that is <:expr< a := b >> (instead of "a <-
> b"). For a reference, see the related rules in etc/pa_o.ml :
>
>  | ":=" NONA
>    [ e1 = SELF; ":="; e2 = expr LEVEL "expr1" ->
>      <:expr< $e1$.val := $e2$ >>
>    | e1 = SELF; "<-"; e2 = expr LEVEL "expr1" ->
>      <:expr< $e1$ := $e2$ >> ]

Thanks, I found this piece of code.  Now on a more specific point, I
am confused about the parsing of record access and update:

1) In the parsing rule for the simple dot noation...

      | e1 = SELF; "."; e2 = SELF -> <:expr< $e1$ . $e2$ >> ]

...why is the field label an "expr"?  This does not agree with the
OCaml manual, which has a separate syntactic category for "field"
(http://caml.inria.fr/pub/docs/manual-ocaml/expr.html), nor with my
intuition about the meaning of the code.

2) Furthermore, as one can see from the ":=" entry above, the entire
left side of a record update is parsed as its own subexpression.  So
this means, that in the context of a record update, that subexpression
has to be interpreted as a reference, but in other contexts, the very
same expression must be interpreted as a value.  I don't necessarily
care what kind of magic makes this possible on the back end, but I am
wondering whether this has any implications for modifying the record
syntax.

 - Aaron


  reply	other threads:[~2009-10-08 14:39 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-07 16:20 Aaron Bohannon
2009-10-07 20:16 ` [Caml-list] " blue storm
2009-10-08 14:39   ` Aaron Bohannon [this message]
2009-10-10 12:31     ` blue storm
2009-10-14  2:04       ` Aaron Bohannon

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=c413fcb70910080739t7266467clf946d4d7be0c759a@mail.gmail.com \
    --to=bohannon@cis.upenn.edu \
    --cc=bluestorm.dylc@gmail.com \
    --cc=caml-list@yquem.inria.fr \
    /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).