Syntax tree quotations in user syntax

The quotation kit "q_ast.cmo" allows to use syntax tree quotations in user syntax. It fully works only in "strict" mode. In "transitional" mode, there is no way to use antiquotations, which restricts its utility.

If this kit is loaded, when a quotation of syntax tree is found, the current OCaml language parser is called. Then, the resulting tree is reified (except the antiquotations) to represent the syntax tree of the syntax tree.

Antiquotations

The OCaml langage parser used, and its possible extensions, must have been built to allow the places of the antiquotations. The symbols enclosed by the meta-symbol "V" (see the chapter about extensible grammars, section "symbols"), define where antiquotations can take place.

There is no need to specify antiquotations for the main types defined in the AST tree module ("MLast"): "expr", "patt", "expr", "str_item", "sig_item", and so on. All syntax parts of these types are automatically antiquotable.

For example, in Camlp5 sources, the grammar rule defining the "let..in" statement is:

   "let"; r = V (FLAG "rec") "flag" "opt";
    l = V (LIST1 let_binding SEP "and"); "in"; x = expr

All symbols of these rules, except the keywords, are antiquotable:

In that example, the variable "r" is of type "Ploc.vala bool", the variable "r" of type "Ploc.vala (list (patt * expr))" and the variable "x" of type "MLast.expr".

... to be completed ...


Copyright 2007-2014 Daniel de Rauglaudre (INRIA)

Valid XHTML 1.1