* camlp4: Understanding class_declaration
@ 2007-10-04 16:40 Joel Reymont
2007-10-06 7:35 ` [Caml-list] " Nicolas Pouillard
0 siblings, 1 reply; 2+ messages in thread
From: Joel Reymont @ 2007-10-04 16:40 UTC (permalink / raw)
To: Caml List
Would someone kindly explain LEFTA, SELF, ANTIQUOT and QUOTATION below?
class_declaration:
[ LEFTA
[ c1 = SELF; "and"; c2 = SELF ->
<:class_expr< $c1$ and $c2$ >>
| `ANTIQUOT (""|"cdcl"|"anti"|"list" as n) s ->
<:class_expr< $anti:mk_anti ~c:"class_expr" n s$ >>
| `QUOTATION x -> Quotation.expand _loc x
Quotation.DynAst.class_expr_tag
| ci = class_info_for_class_expr; ce = class_fun_binding ->
<:class_expr< $ci$ = $ce$ >>
] ]
It seems they are variants but that's about as much as I understand.
What are the "cdcl", "anti" or "list", for example? Why are they
strings?
And why is `QUOTATION x expanded into Quotation.expand _loc x
Quotation.DynAst.class_expr_tag?
Thanks in advance, Joel
--
http://wagerlabs.com
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Caml-list] camlp4: Understanding class_declaration
2007-10-04 16:40 camlp4: Understanding class_declaration Joel Reymont
@ 2007-10-06 7:35 ` Nicolas Pouillard
0 siblings, 0 replies; 2+ messages in thread
From: Nicolas Pouillard @ 2007-10-06 7:35 UTC (permalink / raw)
To: joelr1; +Cc: caml-list
Excerpts from joelr1's message of Thu Oct 04 18:40:58 +0200 2007:
> Would someone kindly explain LEFTA, SELF, ANTIQUOT and QUOTATION below?
The main page about camlp4 extensible grammars/parsers is:
http://brion.inria.fr/gallium/index.php/Extensible_Parser
The syntax of grammars is given in:
http://brion.inria.fr/gallium/index.php/EXTEND
* LEFTA is left associative (its the default).
* SELF refers to the current rule (class_declaration here), in most common
cases SELF does what you want.
ANTIQUOT and QUOTATION are token types like STRING, INT... The backquote
syntax mark the begining of an OCaml pattern. So ANTIQUOT is a constructor
(the token type [1]). The lexical syntax of an antiquotation is "$name:...$"
or "$...$", it use in order to treat quotations [2] such as
<:class_expr< myclass = object method m = $e$ end >>
where `e' should better be an expression (Ast.expr).
[1]: http://brion.inria.fr/gallium/index.php/Generic_Token_Type
[2]: http://brion.inria.fr/gallium/index.php/Quotation
>
> class_declaration:
> [ LEFTA
> [ c1 = SELF; "and"; c2 = SELF ->
> <:class_expr< $c1$ and $c2$ >>
> | `ANTIQUOT (""|"cdcl"|"anti"|"list" as n) s ->
> <:class_expr< $anti:mk_anti ~c:"class_expr" n s$ >>
> | `QUOTATION x -> Quotation.expand _loc x
> Quotation.DynAst.class_expr_tag
> | ci = class_info_for_class_expr; ce = class_fun_binding ->
> <:class_expr< $ci$ = $ce$ >>
> ] ]
>
> It seems they are variants but that's about as much as I understand.
> What are the "cdcl", "anti" or "list", for example? Why are they
> strings?
They are antiquotations names so you can write (don't pay attention to
"anti") <:class_expr< $cdcl:x$ and $list:xs$ >>.
> And why is `QUOTATION x expanded into Quotation.expand _loc x
> Quotation.DynAst.class_expr_tag?
When you see <:class_expr<...>> you give "..." to the quotation expander
manager that will call the registered expanding function (the class_expr_tag
is too indicate the requested type).
Best regards,
--
Nicolas Pouillard aka Ertai
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2007-10-06 7:35 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-10-04 16:40 camlp4: Understanding class_declaration Joel Reymont
2007-10-06 7:35 ` [Caml-list] " Nicolas Pouillard
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox