This is briefly annotated version of the grammar used for the proof-of-concept implementation of l20n.
The fileformat to be used for l20n is completely described by the following Localizable Objects List (lol) production. The file consists of optional whitespace and entries.
| lol | : | WS? entry* EOF ; |
An entry is either an entity, a comment or a group. Groups are only included for hierarchical structuring of the source.
| entry | : | (entity | comment | group) WS? |
A entity consists of an ID, a value, which can be a macro definition, and arbitrary amount of key-value pairs. The optional index specifies which value to actually return when askng for the value of this entity, for example, this can specify which plural form to use.
| entity | : | '<' ID WS? ( index WS? )? ':' WS? macro | value WS? ( keyValuePair WS? )* '>' ; |
| ID | : | \w+ ; |
| index | : | '[' WS? expression WS? ( ',' WS? expression WS? )*']' ; |
Expressions are closely modeled after C expressions, merely binary operators and some C-specifics have been removed.
| expression | : | conditional_expression ; |
| conditional_expression | : | or_expression WS? ( '?' WS? expression ':' WS? conditional_expression WS? )? ; |
| or_expression | : | and_expression WS? ( '||' WS? and_expression WS? )* ; |
| and_expression | : | equality_expression WS? ( '&&' WS? equality_expression WS? )* ; |
| equality_expression | : | relational_expression WS? ( ('=='|'!=') WS? relational_expression WS? )* ; |
| relational_expression | : | additive_expression WS? ( ('<'|'>'|'<='|'>=') WS? additive_expression WS? )* ; |
| additive_expression | : | multiplicative_expression WS? ( ('+' | '-') WS? multiplicative_expression WS? )* ; |
| multiplicative_expression | : | unary_expression WS? ( ('*' | '/' | '%') WS? unary_expression WS? )* ; |
| unary_expression | : | ( ('+' | '-' | '!') WS? unary_expression ) | primary_expression ; |
| primary_expression | : | ( '(' WS? expression ')' ) | number | value | idref ( ( '(' WS? ( expression WS? ( ',' WS? expression WS? )* )? ')' ) | index )? ; |
| idref | : | ID ( '.' ID )* ; |
One of the fundamental elements of l20n are values, which can be plain strings, strings with parameters, arrays or hashes. Both arrays and hashes have values as values, that is, they can be hierarchical.
| value | : | string | array | hash ; |
| macro | : | '(' WS? ( ID WS? ( ',' WS? ID WS? )* )? ')' WS? '->' WS? '{' WS? expression WS? '}' ; |
The expander production used inside strings is used to reference expressions to be expanded within a string.
| string | : | '\'' ([^'] | escape | expander )* '\'' ; |
| escape | : | '\' ('\' | '\'' | '"' | '$') ; |
| expander | : | '${' expression '}' ('s' | 'i') ; |
| array | : | '[' WS? value WS? ( ',' WS? value WS? )* ']' ; |
| hash | : | '{' WS? keyValuePair WS? ( ',' WS? keyValuePair WS? )* '}' ; |
| keyValuePair | : | ID WS? ':' WS? value ; |
Comments are following doxygen style. The specified set of @-rules is yet to be determined.
| comment | : | '/' '*' .*? '*' '/' ; |
| group | : | '[%%' WS? entry* '%%]' ; |
| WS | : | \s+ ; |

This work is licensed under a Creative Commons Attribution-Share Alike 2.5 License.