Expressions
This chapter specifies the expression syntax of Dada.
Expr definition
An expression Expr is parsed using precedence climbing.
From lowest to highest precedence:
Expr ::= AssignExpr
AssignExpr definition
The assignment operator = assigns a value to a place expression.
It has the lowest precedence among binary operators:
AssignExpr ::= OrExpr
OrExpr definition
AndExpr definition
The logical AND operator && performs short-circuit boolean logic:
AndExpr ::= CompareExpr
CompareExpr definition
The comparison operators compare two values and produce a boolean result:
CompareExpr ::= AddExpr
CompareOp ::= == | < | > | <= | >=
AddExpr definition
MulExpr definition
UnaryExpr definition
A unary expression applies a prefix operator to a postfix expression:
UnaryExpr ::= UnaryOp* PostfixExpr
UnaryOp ::= ! | -
Newline Sensitivity
A binary operator must appear on the same line as its left operand. An operator on a new line begins a new expression or is interpreted as a prefix operator.
PostfixExpr definition
A postfix expression applies zero or more postfix operators to a primary expression:
PostfixExpr ::= PrimaryExpr PostfixOp*
PostfixOp definition
A postfix operator PostfixOp is one of the following:
PostfixOp ::= FieldAccess
| Call
| Await
| PermissionOp
FieldAccess definition
A field access FieldAccess uses dot notation to access a field or name a method:
FieldAccess ::= . Identifier
Call definition
Await definition
The .await postfix operator awaits the result of a future:
Await ::= . await
PermissionOp definition
A permission operation PermissionOp requests specific permissions on a value:
PermissionOp ::= give
| share
| lease
| ref
PrimaryExpr definition
A primary expression PrimaryExpr is one of the following:
PrimaryExpr ::= Literal
| identifier
| self
| IfExpr
| ReturnExpr
| ConstructorExpr
| paren-expr
| block-expr
IfExpr definition
An if expression may have an else clause.
Multiple conditions may be chained with else if.
ReturnExpr definition
A return expression ReturnExpr exits the enclosing function,
optionally with a value.
The value, if present, must appear on the same line as return:
ReturnExpr ::= return Expr?
ConstructorExpr definition
A constructor expression ConstructorExpr creates a new instance
of a class or struct.
The opening brace must appear on the same line as the type name:
ConstructorExpr ::= Identifier { ConstructorField,* }
ConstructorField ::= Identifier : Expr