caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Camlp4] Antiquotation and unescaped strings
@ 2008-02-18 14:34 Gabriel Kerneis
  2008-02-18 23:01 ` Nicolas Pouillard
  0 siblings, 1 reply; 3+ messages in thread
From: Gabriel Kerneis @ 2008-02-18 14:34 UTC (permalink / raw)
  To: caml-list; +Cc: Nicolas.Pouillard

[-- 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 --]

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

end of thread, other threads:[~2008-02-19  6:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-18 14:34 [Camlp4] Antiquotation and unescaped strings Gabriel Kerneis
2008-02-18 23:01 ` Nicolas Pouillard
2008-02-19  6:53   ` Gabriel Kerneis

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).