Question

What is the grammar of expressions that are permitted within AngularDart mustaches {{...}} and other directives?

Was it helpful?

Solution

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           # assignment
args: '(' expressionList? ')'
filterArg: ':' expression
expressionList: 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).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top