Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: "Harrison, John R" <john.r.harrison@intel.com>
To: OCaml <caml-list@yquem.inria.fr>
Cc: "Harrison, John R" <john.r.harrison@intel.com>
Subject: More problems with simple quotation parser
Date: Sun, 21 Sep 2008 11:47:15 -0700	[thread overview]
Message-ID: <BC67582D4FC8ED45BAABE48343BF571102FD6A9BA2@azsmsx501.amr.corp.intel.com> (raw)

I've hit another problem with the simple string transformation
quotation parser (see my previous message). For the sake of this
example, here is a somewhat simplified variant, which I turn
into "Quotexpander.cma":

  open Camlp4.PreCast;;

  module Caml =
    Camlp4OCamlParser.Make
      (Camlp4OCamlRevisedParser.Make
        (Camlp4.OCamlInitSyntax.Make(Ast)(Gram)(Quotation)));;

  let quotexpander s = "\"" ^ String.escaped s ^ "\"";;

  let patt_quotexpander loc _loc_name_opt str =
    Gram.parse_string Caml.patt loc (quotexpander str);;

  let expr_quotexpander loc _loc_name_opt str =
    Gram.parse_string Caml.expr loc (quotexpander str);;

  let str_item_quotexpander loc loc_name_opt str =
    <:str_item@loc< $exp: expr_quotexpander loc loc_name_opt str$ >>;;

  let () =
    Syntax.Quotation.add "" Syntax.Quotation.DynAst.expr_tag expr_quotexpander;
    Syntax.Quotation.add "" Syntax.Quotation.DynAst.str_item_tag
  str_item_quotexpander;
    Syntax.Quotation.add "" Syntax.Quotation.DynAst.patt_tag patt_quotexpander;;

This doesn't always seem to work properly when quotations are
subexpressions of larger expressions. Some of the issues seem to
be lexical:

          Objective Caml version 3.10.0

  # #load "camlp4o.cma";;
          Camlp4 Parsing version 3.10.0

  # #load "Quotexpander.cma";;
  # <<ok>>;;
  - : string = "ok"
  # (<<ok>>);;
  - : string = "ok"
  # [<<not ok>>];;
  Parse error: illegal begin of top_phrase
  # [ <<not ok>> ];;
  - : string list = ["not ok"]

Others I'm not so sure about:

  # <<not>> ^ <<ok>>;;
  # Parse error: illegal begin of top_phrase
  # (<<not>>) ^ (<<ok>>);;
  - : string = "notok"

Any idea what's going on? Do I need to put some kind of wrapping
round the transformed phrase?

John.


             reply	other threads:[~2008-09-21 18:47 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-21 18:47 Harrison, John R [this message]
2008-10-09 18:41 ` [Caml-list] " Nicolas Pouillard

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=BC67582D4FC8ED45BAABE48343BF571102FD6A9BA2@azsmsx501.amr.corp.intel.com \
    --to=john.r.harrison@intel.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