* [Caml-list] p4 (newbie) question @ 2002-01-21 18:22 Ian Zimmerman 2002-01-22 8:47 ` Daniel de Rauglaudre 0 siblings, 1 reply; 4+ messages in thread From: Ian Zimmerman @ 2002-01-21 18:22 UTC (permalink / raw) To: OCAML Looking at the documentation for the MLast quotations in camlp4 reference manual, the very first node is <:expr< $e1$ . $e2$ >> : access in records an in modules Now I understand that camlp4 is all syntax, but even so, aren't these two fundamentally different things? In other words, shouldn't there be 2 distinct nodes like this <:expr< $e1$ . $e2$ >> : access in records <:expr< $me1$ . $e2$ >> : access in modules This is a practical issue when constructing my grammar --- I have rules that derive module_expr, so how do I put them together with the core expr rules to derive possibly qualified identifiers? -- Ian Zimmerman, Oakland, California, U.S.A. GPG: 433BA087 9C0F 194F 203A 63F7 B1B8 6E5A 8CA3 27DB 433B A087 In his own soul a man bears the source from which he draws all his sorrows and his joys. Sophocles. ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] p4 (newbie) question 2002-01-21 18:22 [Caml-list] p4 (newbie) question Ian Zimmerman @ 2002-01-22 8:47 ` Daniel de Rauglaudre 2002-01-22 14:46 ` Ian Zimmerman 0 siblings, 1 reply; 4+ messages in thread From: Daniel de Rauglaudre @ 2002-01-22 8:47 UTC (permalink / raw) To: OCAML Hi, On Mon, Jan 21, 2002 at 10:22:23AM -0800, Ian Zimmerman wrote: > shouldn't there be 2 distinct nodes like this > > <:expr< $e1$ . $e2$ >> : access in records > <:expr< $me1$ . $e2$ >> : access in modules No: in these two quotations, e1, e2, me1, e2 are not some kind of "keywords" like you seem to believe, but variables. These quotations are (resp.) equivalent to: MLast.ExAcc (loc, e1, e2) MLast.ExAcc (loc, me1, e2) which cannot discriminate according to the cases record/modules as you see. The difference is done by the first parameter when it represents (or not) an uppercase identifier: MLast.ExAcc (loc, MLast.ExUid loc s, e2) which can be written with quotations as: <:expr< $uid:s$ . $e2$ >> That is (above) the code of contructing a module access if s is a string holding the module name and e2 is an expression. If you already know the name of your module, and if it is e.g. Foo, you can write it: <:expr< Foo . $e2$ >> which is equivalent to: MLast.ExAcc (loc, MLast.ExUid loc "Foo", e2) Note that you don't need to know the form with MLast.ExAcc, MLast.ExUid and so on, but it is just to explain you what the quotations represent. -- Daniel de RAUGLAUDRE daniel.de_rauglaudre@inria.fr http://cristal.inria.fr/~ddr/ ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] p4 (newbie) question 2002-01-22 8:47 ` Daniel de Rauglaudre @ 2002-01-22 14:46 ` Ian Zimmerman 2002-01-22 15:05 ` Daniel de Rauglaudre 0 siblings, 1 reply; 4+ messages in thread From: Ian Zimmerman @ 2002-01-22 14:46 UTC (permalink / raw) To: OCAML itz> shouldn't there be 2 distinct nodes like this itz> itz> <:expr< $e1$ . $e2$ >> : access in records itz> <:expr< $me1$ . $e2$ >> : access in modules Daniel> No: in these two quotations, e1, e2, me1, e2 are not some kind Daniel> of "keywords" like you seem to believe, but variables. These Daniel> quotations are (resp.) equivalent to: Daniel> MLast.ExAcc (loc, e1, e2) Daniel> MLast.ExAcc (loc, me1, e2) Daniel> which cannot discriminate according to the cases Daniel> record/modules as you see. Well, I guess I can rephrase my question then: shouldn't there be both MLast.ExRecAcc (loc, e1, e2) and MLast.ExModAcc (loc, me1, e2) ? After all, doesn't p4 have to pass distinct trees to the compiler proper in these two cases? Daniel> The difference is done by the first parameter when it Daniel> represents (or not) an uppercase identifier: Daniel> MLast.ExAcc (loc, MLast.ExUid loc s, e2) Daniel> which can be written with quotations as: Daniel> <:expr< $uid:s$ . $e2$ >> Daniel> That is (above) the code of contructing a module access if s Daniel> is a string holding the module name and e2 is an Daniel> expression. If you already know the name of your module, and Daniel> if it is e.g. Foo, you can write it: Daniel> <:expr< Foo . $e2$ >> But I don't know the name like that, it is not fixed; I am trying to parse that as well. So my me1 can be any module access path in general (OK, no functor applications for now, but arbitrary depth). It would be a different story if the dot were right-associative; then, indeed, I could write something like let barexp = <:expr< Bar . $exp$ >> in <:expr< Foo . $barexp$ >> But this is ungrammatical; normal ocaml grammar says that Foo.Bar.exp is to be parsed as (Foo.Bar).exp Antoher question, and one I am afraid I know the answer to: where/what is the quotation for applicative record update {foo with bar = expr} ? -- Ian Zimmerman, Oakland, California, U.S.A. GPG: 433BA087 9C0F 194F 203A 63F7 B1B8 6E5A 8CA3 27DB 433B A087 In his own soul a man bears the source from which he draws all his sorrows and his joys. Sophocles. ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] p4 (newbie) question 2002-01-22 14:46 ` Ian Zimmerman @ 2002-01-22 15:05 ` Daniel de Rauglaudre 0 siblings, 0 replies; 4+ messages in thread From: Daniel de Rauglaudre @ 2002-01-22 15:05 UTC (permalink / raw) To: OCAML Hi, On Tue, Jan 22, 2002 at 06:46:32AM -0800, Ian Zimmerman wrote: > Well, I guess I can rephrase my question then: shouldn't there be both > MLast.ExRecAcc (loc, e1, e2) and > MLast.ExModAcc (loc, me1, e2) I prefer being far from semantics. I just consider syntax as syntax. Same thing for "types" and "types declarations" which are different in OCaml syntax tree, but not in Camlp4 syntax tree where there are only "types". > So my me1 can be any module access path in general (OK, no functor > applications for now, but arbitrary depth). Then use <:expr< $uid:s$ . $...$ >> in an iterator to create your Camlp4 syntax tree. > Antoher question, and one I am afraid I know the answer to: > where/what is the quotation for applicative record update > {foo with bar = expr} ? <:expr< {(foo) with bar = expr} >> -- Daniel de RAUGLAUDRE daniel.de_rauglaudre@inria.fr http://cristal.inria.fr/~ddr/ ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2002-01-22 15:05 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2002-01-21 18:22 [Caml-list] p4 (newbie) question Ian Zimmerman 2002-01-22 8:47 ` Daniel de Rauglaudre 2002-01-22 14:46 ` Ian Zimmerman 2002-01-22 15:05 ` 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