Special syntax when the payload of attribute/extension is a single type expression: [@id : T], [%id : T]. Represented internally as (() : T).

git-svn-id: http://caml.inria.fr/svn/ocaml/branches/extension_points@13918 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
master
Alain Frisch 2013-07-22 14:04:28 +00:00
parent 525ef9d703
commit 8df2057b46
2 changed files with 22 additions and 9 deletions

View File

@ -4,16 +4,26 @@ This file describes the changes on the extension_points branch.
=== Attributes
Attributes are "decorations" of the syntax tree which are ignored by
the type-checker. An attribute is made of an identifier (written id)
and a argument, which is an OCaml structure (i.e. a list of structure
items), written s below.
the type-checker. An attribute is made of an identifier (written id below)
and a payload (written s below).
The identifier can be a lowercase or uppercase identifier (including
OCaml keywords) or a sequence of such atomic identifiers separated with
a dots (whitespaces are allowed around the dots). In the Parsetree,
the identifier is represented as a single string (without spaces).
* The identifier 'id' can be a lowercase or uppercase identifier
(including OCaml keywords) or a sequence of such atomic identifiers
separated with a dots (whitespaces are allowed around the dots).
In the Parsetree, the identifier is represented as a single string
(without spaces).
* The payload 's' is an OCaml structure (i.e. a list of structure items).
Note that a payload can be empty or reduced to a single expression
(both cases are valid structures). To support attributes whose
payload needs to be a type expression, the special syntax:
: T
(where T is a type expression) is also accepted as a valid payload,
and is interpreted internally as the structure made of the single
expression (() : T).
Note: a structure can be empty, or reduced to a single expression.
Attributes on expressions, type expressions, module expressions, module type expressions,
patterns, class expressions, class type expressions:

View File

@ -2003,6 +2003,9 @@ item_extension:
LBRACKETPERCENTPERCENT attr_id ext_arg RBRACKET { ($2, $3) }
;
ext_arg:
structure { $1 }
structure { $1 }
| COLON core_type {
[ mkstrexp (ghexp (Pexp_constraint (ghunit (), $2))) [] ]
}
;
%%