caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Gabriel Kerneis <kerneis@enst.fr>
To: caml-list@yquem.inria.fr
Cc: Nicolas.Pouillard@inria.fr
Subject: [Camlp4] Antiquotation and unescaped strings
Date: Mon, 18 Feb 2008 15:34:12 +0100	[thread overview]
Message-ID: <20080218143412.GA4411@kerneis.info> (raw)

[-- Attachment #1: Type: text/plain, Size: 1993 bytes --]

Hi,

I've got a problem with antiquotations and strings in camlp4. I've got a
parser (xmlp4, used in Ocsigen) written with camlp4 which has to deal
with strings. 
This parser provides a quotation mechanism to let the user input XML in
a natural way within an Ocaml program.

Basically, the problem is the following expression (in the parser's
code):

  | PCData(s) -> [ <:expr< XHTML.EncodedPCData $str:s$ >> ]

where s is a (potentially unescaped) string. Here is a typical output:

  [XML.EncodedPCDATA " "bar \" ]

corresponding to the following input file:

  <:xml< "bar\ >>

(assuming that this quotation is parsed as PCData of course)

As you can see, it's weird and it took me some time to find out what was
happening (real-life examples being much more intricate).

Of course, I would like to get:

  [XML.EncodedPCDATA "\"bar \\" ]

instead, and of course, I could obtain it through:

  | PCData(s) -> [<:expr< XHTML.EncodedPCData $str:String.escaped s$ >>]

But I wonder whether this should be considered as a camlp4 bug (or
possible enhancement). When I write << EncodedPCData $str:s$ >>, I 
expect to get something consistent, not some kind of "let's evaluate s
and copy/paste it blindly there".

Shall I submit a bug report? Or is there something I got wrong in my
code (which is very likely)?

Anyway, if this is an intended behavior, the explanation should be put 
in BIG BOLD RED letters on the camlp4 wiki, on the quotation page. This
would help a lot (plus I would like to understand what is exactly going 
on there).

NB: I simplified the examples for the shake of clarity. You can find the
relevant code here:
http://ocsigen.org/trac/browser/xmlp4/newocaml/xhtmlparser.ml
You may also want to have a look at:
http://ocsigen.org/trac/browser/xmlp4/newocaml/xmllexer.mll and
http://ocsigen.org/trac/browser/xmlp4/newocaml/xhtmlsyntax.ml
I'd welcome any remark regarding this code.

Kind regards,
-- 
Gabriel Kerneis

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

             reply	other threads:[~2008-02-18 14:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-18 14:34 Gabriel Kerneis [this message]
2008-02-18 23:01 ` Nicolas Pouillard
2008-02-19  6:53   ` Gabriel Kerneis

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=20080218143412.GA4411@kerneis.info \
    --to=kerneis@enst.fr \
    --cc=Nicolas.Pouillard@inria.fr \
    --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).