Anglr language Attributes
Introduction
Attributes appear at different places in anglr files. They are not tied to a single part of anglr file, so it is appropriate to describe them separately before we become familiar with the other parts of the anglr file. They are used for a variety of purposes. Some of them are mandatory, others can be defined by any user at their discretion. Mandatory attributes are associated with anglr compiler. User defined attributes are for information purposes only. User defined attributes can have any content, only care should be taken to make their names different from the names of the mandatory attributes.
Syntax
The following is a list of syntax rules needed to compose attributes:
RULE A-1
<attribute list> : <attribute> + ;
RULE A-2
<attribute> : '[' <identifier> <name value list> ? ']' ;
RULE A-3
<name value list> : <name value pair> + ;
RULE A-4
<name value pair> : <identifier> '=' <cstring> ;
Discussion
RULE A-1 - Attribute List
Rule RULE A-1 defines the syntax of the attribute list. The attribute list is a sequence of attributes without specific separators. The only characters that may be between them are spaces and new line characters. Here is an example of attribute list:
[ Description Text='Parser for anglr file' Hover='true' ] [ Lexer Id='anglrLexer' Hover='true' ] [ Declarations Id='anglrDecls' Hover='true' ] [ CompilationInfo ClassName='AnglrParser' NameSpace='Anglr.Parser' Access='public' Hover='true' ]
It contains four attributes:
- Description
- Lexer
- Declarations
- CompilationInfo
RULE A-2 - Structure of Attribute
Rule RULE A-2 defines attribute structure:
- The content of the attribute is specified between the characters [ and ].
- Character [ is followed by the attribute name
- Then follows the list of named values, which may also be empty.
Let's take the following attribute definition for an example:
[ CompilationInfo ClassName='AnglrParser' NameSpace='Anglr.Parser' Access='public' Hover='true' ]
- its content is specified btween characters [ and ]
- its name is CompilationInfo
- it has the following list of named values ClassName='AnglrParser' NameSpace='Anglr.Parser' Access='public' Hover='true'
RULE A-3 - List of Named Values
Rule RULE A-3 defines list of named values. It is nothing but a string of named values listed one after another without any separators between them. In the example above, list of named values of attribute CompilationInfo defined above, contains the following named values:
- ClassName='AnglrParser'
- NameSpace='Anglr.Parser'
- Access='public'
- Hover='true'
RULE A-4 - Structure of Named Value
Rule RULE A-4 defines structure of named value:
- first the name of value must be stated
- Then comes the equality character sign =
- the value of named attribute value comes last. It is a character string with an arbitrary content
If we once again take a look at example above, we can observe that the structure of named value ClassName, for example, follows this structure:
- its name is ClassName
- name is followed by equality sign =
- and finally its value is specified: 'AnglrParser'
Examples
Example 1
[ Description Text='Declarations' Hover='true' ] [ CompilationInfo ClassName='AnglrDeclarations' NameSpace='Anglr.Declarations' Access='public' Hover='true' ]
Above example defines list of two attributes:
-
Description: it is user defined attribute with no special meaning for any application. As its name and named values suggest, it is used to describe something in anglr file.
It has two named values:
- Text with value 'Declarations' and
- Hover with value 'true'
-
CompilationInfo with four named values:
- ClassName with value 'AnglrDeclarations'
- NameSpace with value 'Anglr.Declarations'
- Access with value 'public'
- Hover with value 'true'
Example 2
[ Start ]
Above example defines an attribute without named values. It is perfectly legal to define an attribute without values. Attribute Start is used by anglr compiler to identify starting rule of the language defined in anglr file.