Next: , Previous: token Decl, Up: Declarations


2.3.6 type Decl

— %-Decl: %type <type-name> [property1 value1 ...]

Explicitly declare a lexical type, and optionally give it properties.

type-name
Is a symbol that identifies the type.
property
Is a property name, a valid Emacs Lisp symbol.
value
Is a property value, a valid Emacs Lisp constant expression.

Even if %token, %keyword, and precedence declarations can implicitly declare types, an explicit declaration is required for every type:

Please note:
Because the grammar framework is implemented in Emacs Lisp, which is a dynamically typed language, the meaning of type is notably different between semantic and Bison. In Bison grammars, type means data type, and associates an internal representation to lexical tokens. In semantic grammars, type specifies how lexical analysis will scan tokens of this type.

In the generated library, lexical type declarations are defined in the constant library-name--token-table. The table value is an Emacs Lisp obarray, available at run time in the parsed buffer, in the buffer local variable semantic-lex-types-obarray.

However you shouldn't use that variable directly. semantic provides the following API to use with lexical types at run time.

— Function: semantic-lex-type-symbol type

Return symbol with TYPE or nil if not found.

— Function: semantic-lex-type-p type

Return non-nil if a symbol with TYPE name exists.

— Function: semantic-lex-type-set type value

Set value of symbol with TYPE name to VALUE and return VALUE.

— Function: semantic-lex-type-value type &optional noerror

Return value of symbol with TYPE name. If optional argument NOERROR is non-nil return nil if a symbol with TYPE name does not exist. Otherwise signal an error.

— Function: semantic-lex-type-put type property value &optional add

For symbol with TYPE name, set its PROPERTY to VALUE. If optional argument ADD is non-nil, create a new symbol with TYPE name if it does not already exist. Otherwise signal an error.

— Function: semantic-lex-type-get type property &optional noerror

For symbol with TYPE name, return its PROPERTY value. If optional argument NOERROR is non-nil return nil if a symbol with TYPE name does not exist. Otherwise signal an error.

— Function: semantic-lex-map-types fun &optional property

Call function FUN on every lexical type. If optional PROPERTY is non-nil, call FUN only on every type symbol which as a PROPERTY value. FUN receives a type symbol as argument.

— Function: semantic-lex-types &optional property

Return a list of lexical type symbols. If optional PROPERTY is non-nil, return only type symbols which have PROPERTY set.