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

* Re: [Camlp4] Antiquotation and unescaped strings
  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
  0 siblings, 1 reply; 3+ messages in thread
From: Nicolas Pouillard @ 2008-02-18 23:01 UTC (permalink / raw)
  To: Gabriel Kerneis; +Cc: caml-list

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

Excerpts from Gabriel Kerneis's message of Mon Feb 18 15:34:12 +0100 2008:
> Hi,
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$ >> ]

the  in  the  antiquotation $str:s$ of <:expr<...>> the 's' string is supposed
to  be  properly  escaped,  that's  not  any OCaml string, that's any litteral
OCaml   string   (some   chars   between   double   quote).   You  should  use
$str:String.escaped s$ or the shortcut for it $`str:s$.

[...]

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

I  think  that's not a camlp4 bug, however that's right that an explanation is
needed to make it crystal clear.

Regards,

-- 
Nicolas Pouillard aka Ertai

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 194 bytes --]

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

* Re: [Camlp4] Antiquotation and unescaped strings
  2008-02-18 23:01 ` Nicolas Pouillard
@ 2008-02-19  6:53   ` Gabriel Kerneis
  0 siblings, 0 replies; 3+ messages in thread
From: Gabriel Kerneis @ 2008-02-19  6:53 UTC (permalink / raw)
  To: Nicolas Pouillard; +Cc: Gabriel Kerneis, caml-list

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

Le Tue, 19 Feb 2008 00:01:40 +0100, "Nicolas Pouillard"
<nicolas.pouillard@gmail.com> a écrit :
> You  should  use $str:String.escaped s$ or the
> shortcut for it $`str:s$.

I knew a shortcut existed but couldn't remember it - thank you very
much. It's not a bug indeed, then.

Regards,
-- 
Gabriel Kerneis

[-- Attachment #2: signature.asc --]
[-- 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).