Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] [camlp4] compatibility of pa_extend with other extensions
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-12-14 (18:06)
From: Stefano Zacchiroli <zack@b...>
Subject: [Caml-list] [camlp4] compatibility of pa_extend with other extensions
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:

    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
  File "", 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 ...


^Stefano Zacchiroli -- Master in Computer Science @ Uni. Bologna, Italy$
^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 Archives:
Bug reports: FAQ:
Beginner's list: