On Tue, 10 Apr 2007, Hugo Ferreira wrote: > So far so good, but my problem is how do I convert "l" in the "$list:l$" > so that I can manipulate the "px = ex" assignments and only do this > when "ex" is "HEAP"? > > I finally came up with this by (over) "simplifying" Hendrik Tews code: > > GLOBAL: Pcaml.expr Pcaml.str_item ; > > Pcaml.expr: LEVEL "expr1" [ > [ > "let"; o = OPT "rec"; > l = LIST1 my_let_binding SEP "and"; "in"; > x = Pcaml.expr LEVEL "top" > -> <:expr< let $opt:o2b o$ $list:l$ in > $x$ >> > > .... > > > my_let_binding: > [ > [ > p = "_" ; "=" ; "HEAP" -> <:patt< s >>, <:expr<Logic.new_heap ()>> > | p = LIDENT ; "=" ; "HEAP" -> <:patt< $lid:p$ >>, > <:expr<Logic.new_heap ()>> > ] > ] ; > > As you can see I use my own "let_binding" that only succeeds with the > "HEAP" keyword. If this fails, camlp4 should fall back on the default or > predefined rule and compile as usual. > > This seems to work ok and is what I was looking for. > > Comments?
If everything works, that's good for you, but I wouldn't do this until I know it is guaranteed to work. If it doesn't work in a future version of camlp4, you can update your program (syntax extension) but you don't want to be forced to change your syntax because of the programs that use the syntax extension. Other than that, I understand that in the new camlp4 you will be able to implement this by defining a filter, i.e. without changing the parsing rules at all... which is absolutely great (if it works as I imagine). Martin -- Martin Jambon http://martin.jambon.free.fr --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "ocaml-developer" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/ocaml-developer?hl=en For other OCaml forums, see http://caml.inria.fr/resources/forums.en.html -~----------~----~----~----~------~----~------~--~---
