caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* More problems with simple quotation parser
@ 2008-09-21 18:47 Harrison, John R
  2008-10-09 18:41 ` [Caml-list] " Nicolas Pouillard
  0 siblings, 1 reply; 2+ messages in thread
From: Harrison, John R @ 2008-09-21 18:47 UTC (permalink / raw)
  To: OCaml; +Cc: Harrison, John R

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.


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

* Re: [Caml-list] More problems with simple quotation parser
  2008-09-21 18:47 More problems with simple quotation parser Harrison, John R
@ 2008-10-09 18:41 ` Nicolas Pouillard
  0 siblings, 0 replies; 2+ messages in thread
From: Nicolas Pouillard @ 2008-10-09 18:41 UTC (permalink / raw)
  To: John Harrison; +Cc: Caml_mailing list

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

Excerpts from John Harrison's message of Sun Sep 21 20:47:15 +0200 2008:
> 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":

[...]

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

The camlp4 lexer allow much longer bracketing tokens like
  [<, >], [%, {#, ... )
so when using extensions of OCaml (since this lexer extension does
not break any OCaml code in original syntax) one have to put more
spaces to make separate tokens.

-- 
Nicolas Pouillard aka Ertai

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

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

end of thread, other threads:[~2008-10-09 18:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-09-21 18:47 More problems with simple quotation parser Harrison, John R
2008-10-09 18:41 ` [Caml-list] " Nicolas Pouillard

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