Next: , Previous: Declaring types, Up: %typedef and %type

10.2 Types and fields

Fields can be declared to have a given type by using the %type special field in a record descriptor. The synopsis is:

     %type: field_list type_name_or_description

Where field_list is a list of field names separated by commas. type_name_or_description can be either a type name declared with %typedef, or a type description. Type names are useful when several fields are declared to be of the same type:

     %typedef: Id_t    int
     %type:    Id      Id_t
     %type:    Product Id_t

Anonymous types can be used by writing a type description instead of a type name. They help to avoid superfluous type declarations. A record containing a single Id field, for example, can be defined without having to use a %typedef in the following way:

     %rec: Task
     %type: Id int