AngularDart directive expression grammar for mustache and other directives AngularDart directive expression grammar for mustache and other directives dart dart

AngularDart directive expression grammar for mustache and other directives


Here is an EBNF grammar for AngularDart expressions, in the same notation used in the Dart Programming Language Specification. These expressions can appear as arguments to Angular directives. While the grammar allows, e.g., a semicolon-separated list of expressions, assignments and conditionals, these will not be accepted by all directives---e.g., ng-click supports multiple expressions possibly with assignments, whereas the mustache directive {{...}} expects a single expression.

expressions: expression (';' expressions)?expression:    literal  | id args?                        # variable or function  | expression '.' id args?         # member  | expression '|' id filterArg*    # filter  | expression '[' expression ']'  | preOp expression  | expression binOp expression  | expression '?' expression ':' expression  | expression '=' expression           # assignmentargs: '(' expressionList? ')'filterArg: ':' expressionexpressionList: expression (',' expression)?literal:    'null'  | stringLiteral  | numberLiteral  | boolLiteral  | '[' expressionList? ']'  | '{' (keyValuePair (',' keyValuePair)? )? '}'keyValuePair:  expression ':' expression

The preOp and binOp are mainly those supported by Dart (though I will have to crosscheck that). There is a more nicely formatted version of the above here (I could not get the MD to cooperate).