* [Caml-list] Caml4p... help @ 2002-10-09 1:50 Pietro Abate 2002-10-09 3:35 ` jehenrik 2002-10-09 11:53 ` Daniel de Rauglaudre 0 siblings, 2 replies; 4+ messages in thread From: Pietro Abate @ 2002-10-09 1:50 UTC (permalink / raw) To: Ocaml hi everybody, I've just started playing with Caml4p today and I'm already at a dead end. My goal is to transform this syntax str pc : [a;b;c] into a declaration like that. let pc_str = `Forall [| `Rule a; `Rule b; `Rule c |] extending (and in the future restricting) the caml syntax. I wrote this but I've problems compiling it. It says: ocamlc -c -pp "camlp4o pa_extend.cmo q_MLast.cmo" -I /usr/lib/ocaml/camlp4 str.ml File "str.ml", line 18, characters 2-10: This expression has type unit but is here used with type MLast.expr make: *** [str.cmi] Error 2 of course the problem in about the "str" type. But I haven't still figured out why... Je vous remercie d'avance. p ----------------------- str.ml ------------------------ (*pp camlp4o pa_extend.cmo q_MLast.cmo *) open Pcaml;; type kind = [ |`Rule of string |`First of kind array |`Forall of kind array ] let str = Grammar.Entry.create gram "str";; EXTEND expr: AFTER "top" [[ "str"; n = LINDENT; ":"; s = str -> <:expr< let $lid:n$ = $s$ in $lid:n$ >> ]]; str: [[ | n = LINDENT -> <:expr<`Rule $str:n$>> | "["; s = LIST1 str SEP ";"; "]" -> <:expr<`Forall [|$list:s$|] >> | "{"; s = LIST1 str SEP ";"; "}" -> <:expr<`First [|$list:s$|] >> ]]; END;; -- pgp key: 1024D/8A091922 2000-10-18 Pietro Abate <abate@arp.anu.edu.au> Key fingerprint = 5111 D91B 5E0C 5CE6 FDA3 5EF4 6120 E18E 8A09 1922 public key avalaible via public key server at wwwkeys.eu.pgp.net ------------------- 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] 4+ messages in thread
* Re: [Caml-list] Caml4p... help 2002-10-09 1:50 [Caml-list] Caml4p... help Pietro Abate @ 2002-10-09 3:35 ` jehenrik 2002-10-09 5:46 ` Pietro Abate 2002-10-09 11:53 ` Daniel de Rauglaudre 1 sibling, 1 reply; 4+ messages in thread From: jehenrik @ 2002-10-09 3:35 UTC (permalink / raw) To: Pietro Abate; +Cc: caml-list > I've just started playing with Caml4p today and I'm already at a dead > end. My goal is to transform this syntax > > str pc : [a;b;c] > > into a declaration like that. > let pc_str = `Forall [| `Rule a; `Rule b; `Rule c |] Your implementation is basically right, but it has a couple of small errors. Superficially, LINDENT should be LIDENT. Change both of those. You have an extraneous "|" symbol after str: [[. Fix that. The harder to see mistake is that you accidentally name your entry "str" while simultaneously redefining it to be a keyword. This is bad. So change the name of your entry, for example. Say "strentry" instead of str. Then it works: (this has some modifications to run in the toplevel) #load "camlp4o.cma";; #load "q_MLast.cmo";; #load "pa_extend.cmo";; open Pcaml;; type kind = [ | `Rule of string | `First of kind array | `Forall of kind array ] ;; let strentry = Grammar.Entry.create gram "str" ;; EXTEND expr: AFTER "top" [[ "str"; n = LIDENT; ":"; s = strentry -> <:expr< let $lid:n$ = $s$ in $lid:n$ >> ]]; strentry: [[ n = LIDENT -> <:expr<`Rule $str:n$>> | "["; s = LIST1 strentry SEP ";"; "]" -> <:expr<`Forall [|$list:s$|] >> | "{"; s = LIST1 strentry SEP ";"; "}" -> <:expr<`First [|$list:s$|] >> ]]; END;; str pc : [a;b;c];; # - : _[> `Forall of _[> `Rule of string] array] = `Forall [|`Rule "a"; `Rule "b"; `Rule "c"|] Good luck with your project and welcome to the world of camlp4! Jeff Henrikson On Tuesday, October 8, 2002, at 09:50 PM, Pietro Abate wrote: > (*pp camlp4o pa_extend.cmo q_MLast.cmo *) > open Pcaml;; > > type kind = [ > |`Rule of string > |`First of kind array > |`Forall of kind array > ] > > let str = Grammar.Entry.create gram "str";; > > EXTEND > expr: AFTER "top" > [[ "str"; n = LINDENT; ":"; s = str -> > <:expr< let $lid:n$ = $s$ in $lid:n$ >> ]]; > > str: [[ > | n = LINDENT -> <:expr<`Rule $str:n$>> > | "["; s = LIST1 str SEP ";"; "]" -> <:expr<`Forall [|$list:s$|] >> > | "{"; s = LIST1 str SEP ";"; "}" -> <:expr<`First > [|$list:s$|] >> ]]; > > END;; ------------------- 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] 4+ messages in thread
* Re: [Caml-list] Caml4p... help 2002-10-09 3:35 ` jehenrik @ 2002-10-09 5:46 ` Pietro Abate 0 siblings, 0 replies; 4+ messages in thread From: Pietro Abate @ 2002-10-09 5:46 UTC (permalink / raw) To: caml-list thank you for you help... but I'm still missing something. I want to produce a let statement. However my code produces something like that: let _ = let pc = `Forall [|`Rule "a"; `Rule "b"; `Rule "c"|] in pc that is not really helpful. I suppose the problem lays in the level declaration (I used expr : LEVEL "top") or in the quotation iteself (I used <:expr< let $lid:n$ = $s$ in $lid:n$>>). I don't quite understand the quotation syntax. They are written in the revised syntax, so they don't permit to write something like "let a = 10;;", but there are not "value" statement to declare a binding. how can I transform my declaration str pc : [a;b;c];; in something like that let pc = `Forall [|`Rule "a"; `Rule "b"; `Rule "c"|];; ? My final goal is to use camlp4 to simplify and extend the ocaml syntax to write simple programs that I'll use to feed a virtual machine... thanks, p On Tue, Oct 08, 2002 at 11:35:08PM -0400, jehenrik wrote: > str pc : [a;b;c];; > # - : _[> `Forall of _[> `Rule of string] array] = > `Forall [|`Rule "a"; `Rule "b"; `Rule "c"|] -- pgp key: 1024D/8A091922 2000-10-18 Pietro Abate <abate@arp.anu.edu.au> Key fingerprint = 5111 D91B 5E0C 5CE6 FDA3 5EF4 6120 E18E 8A09 1922 public key avalaible via public key server at wwwkeys.eu.pgp.net ------------------- 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] 4+ messages in thread
* Re: [Caml-list] Caml4p... help 2002-10-09 1:50 [Caml-list] Caml4p... help Pietro Abate 2002-10-09 3:35 ` jehenrik @ 2002-10-09 11:53 ` Daniel de Rauglaudre 1 sibling, 0 replies; 4+ messages in thread From: Daniel de Rauglaudre @ 2002-10-09 11:53 UTC (permalink / raw) To: caml-list Hi, On Wed, Oct 09, 2002 at 11:50:23AM +1000, Pietro Abate wrote: > My goal is to transform this syntax > str pc : [a;b;c] > into a declaration like that. > let pc_str = `Forall [| `Rule a; `Rule b; `Rule c |] According to your 2nd message, you need a "let" at toplevel, not a "let..in". In this case, it is not "expr" that you must extend but "str_item": indeed, the "let" at toplevel is a structure item, not an expression. > ocamlc -c -pp "camlp4o pa_extend.cmo q_MLast.cmo" -I /usr/lib/ocaml/camlp4 str.ml > File "str.ml", line 18, characters 2-10: > This expression has type unit but is here used with type MLast.expr Like Jeff Henrikson said, it is due to the extraneous "|" in the first rule of "str": you must not put one. It is interpreted as an empty rule, returning "()". I recognize that it is a pitfall of the syntax of EXTEND. A remark: the definition of your type "kind" is unuseful in this file. It will be useful only in the files using this syntax extension. For the LINDENT, instead of LIDENT, this is not detected at compile time, but when you use your syntax expander by "camlp4o ./str.cmo" it displays: Lexer initialization error: - the constructor "LINDENT" is not recognized by Plexer Uncaught exception: Failure("Grammar.extend") In Jeff's answer the #load "camlp4o.cma";; at the beginning of the file is unuseful: Camlp4 knows that it is camlp4. On the other hand, the other loads "q_MLast.cmo" and "pa_extend.cmo" are good and useful, since they allow you to compile your file just with "-pp camlp4o". Here is my version of your file (tested): ---------------------------------------- #load "pa_extend.cmo";; #load "q_MLast.cmo";; open Pcaml;; let str = Grammar.Entry.create gram "str";; EXTEND str_item: [ [ "str"; n = LIDENT; ":"; s = str -> <:str_item< value $lid:n$ = $s$ >> ] ]; str: [ [ n = LIDENT -> <:expr<`Rule $str:n$>> | "["; s = LIST1 str SEP ";"; "]" -> <:expr<`Forall [|$list:s$|] >> | "{"; s = LIST1 str SEP ";"; "}" -> <:expr<`First [|$list:s$|] >> ] ]; END;; ---------------------------------------- -- Daniel de RAUGLAUDRE daniel.de_rauglaudre@inria.fr http://cristal.inria.fr/~ddr/ ------------------- 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] 4+ messages in thread
end of thread, other threads:[~2002-10-09 11:53 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2002-10-09 1:50 [Caml-list] Caml4p... help Pietro Abate 2002-10-09 3:35 ` jehenrik 2002-10-09 5:46 ` Pietro Abate 2002-10-09 11:53 ` Daniel de Rauglaudre
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox