caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] [camlp4] compatibility of pa_extend with other extensions
@ 2003-12-14 18:06 Stefano Zacchiroli
  0 siblings, 0 replies; only message in thread
From: Stefano Zacchiroli @ 2003-12-14 18:06 UTC (permalink / raw)
  To: Inria Ocaml Mailing List

I'm writing a parser using camlp4 whose lexer can return tokens
representing arbitrary unicode symbols. Those particular tokens have the
form ("SYMBOL", "<utf8_string>").

My parser uses the usual pa_extend.cmo syntax extension and an excerpt
looks like:

  EXTEND:
    GLOBAL: ...
    ...
    binder: [
      [ SYMBOL "..(1).." -> `Lambda
      | SYMBOL "..(2).." -> `Pi
      ...
      ]
    ...
    ];

Where ..(1).. and ..(2).. are UTF8 encoded strings representing lambda
and pi unicode symbols. In this way the parser works properly.

My problem is that I don't want to have UTF8 strings hard coded in the
parser. I would rather want to write something like:

  [ SYMBOL <:unicode< lambda >> -> `Lambda
  | SYMBOL <:unicode< pi >> -> `Pi

thus I've written a camlp4 syntax extension which implements the above
quotation. It works properly and I can write something like:

  let lambda = <:unicode< lambda >> in
  print_endline lambda

_but_ it doesn't work inside a camlp4 grammar entry as above:

  ocamlfind ocamlc -package "ulex camlp4 pxp" -predicates "" -pp "camlp4o -I /usr/lib/ocaml/3.07/ulex pa_extend.cmo" -pp "camlp4o ./macro.cmo ./pa_unicode_macro.cmo pa_extend.cmo" -c parser.ml
  File "parser.ml", line 25, characters 13-31:
  Parse error: '|' or ']' expected (in [rule_list])
  Preprocessor error
  make: *** [parser.cmo] Error 2

the error point is exactly where my quotation begins.

I assumed that camlp4 will execute my quotation expansion before using
the pa_extend syntax extension, but I was aparently wrong. Any
suggestion about how to solve this issue?

More generally I'm failing to understand how multiple camlp4 extensions
interact and how quotations can be shared between them ...

TIA,
Cheers.

-- 
^Stefano Zacchiroli -- Master in Computer Science @ Uni. Bologna, Italy$
^zack@{cs.unibo.it,debian.org,bononia.it} -- http://www.bononia.it/zack$
^Frequentando il mio maestro mi ero reso conto [.] che la logica poteva$
^servire a molto a condizione di entrarci dentro e poi di uscirne -Adso$

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2003-12-14 18:06 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-12-14 18:06 [Caml-list] [camlp4] compatibility of pa_extend with other extensions Stefano Zacchiroli

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