Alan Grammars
How to read grammars
The documentation for the Alan languages describes the syntax of those languages in the form of an Alan grammar, often accompanied by a description and/or examples. An Alan grammar describes what you can write in an Alan file: the keywords to use, values to provide, and options to choose from.
Keywords
The orange literals between square brackets indicate required keywords. A comma indicates if keywords go before or after a property value. For example:
'name' [ & ] text // means: & before a text value: &"Alice"
'name' [ & , * ] text // means: & before and * after a text value: &"Alice"*
'name' [ , * ] text // means: * after a text value: "Alice"*
Properties
textproperties require a double quoted string:"Alice"referenceproperties require a single quoted string:'reference to Bob'numberproperties require a number value:10stategroupproperties indicate a choice between different states, such as allowing or disallowinganonymoususersdictionaryproperties require key-value pairs, where keys are single-quoted strings ('Alice' 'Bob').componentproperties reference a rule in the grammar, to be instantiated at that point:component 'abc'references rule'abc'groupproperties just group properties that belong together
For example, take the following extract from the grammar of the application language:
'node' { [ { , } ] // curly braces wrap a node type
'attributes' dictionary { // an attribute starts with a key, followed by
'type': [ : ] stategroup ( // a chosen type, preceded by keyword :
'text' { [ text ] } // 'text' requires keyword text
'number' { [ number ] } // 'number' requires keyword number
)
}
}
then a valid model is:
// application.alan (your model file)
{
'A': text
'B': number
}
Note that properties with an =-sign like stategroup = do not require your input, as the compiler derives them for you.
Typical quirks of the Alan compiler
- Keywords should be separated by whitespace, so
()doesn’t work but( )does. - Quotes are recognized as something special, so you can write
'type':and?'state group'|'state'. - Only tabs are accepted for indentation.