File tree Expand file tree Collapse file tree 6 files changed +29
-4
lines changed
Expand file tree Collapse file tree 6 files changed +29
-4
lines changed Original file line number Diff line number Diff line change @@ -237,7 +237,7 @@ class Parser {
237237 }
238238
239239 Expr _unary () {
240- if (_match (TokenType .minus)) {
240+ if (_match (TokenType .minus) || _match ( TokenType .bang) ) {
241241 var op = _previous;
242242 return UnaryExpr (op, _unary ());
243243 }
Original file line number Diff line number Diff line change @@ -224,12 +224,20 @@ class Renderer
224224 Future <Object ?> visitUnaryExpr (UnaryExpr expr) async {
225225 var operand = await expr.expression.accept (this );
226226 switch ((expr.op.type, operand)) {
227+ case (TokenType .bang, bool operand):
228+ return ! operand;
229+
230+ case (TokenType .bang, _):
231+ _reporter.report (expr.op.span,
232+ 'Operand to "!" must be a Boolean but was ${operand .runtimeType }.' );
233+ return null ;
234+
227235 case (TokenType .minus, num operand):
228236 return - operand;
229237
230238 case (TokenType .minus, _):
231239 _reporter.report (expr.op.span,
232- 'Cannot negate a value of type ${operand .runtimeType }.' );
240+ 'Operand to "-" must be a number but was ${operand .runtimeType }.' );
233241 return null ;
234242
235243 default :
Original file line number Diff line number Diff line change @@ -52,7 +52,6 @@ enum TokenType {
5252 comma,
5353 dot,
5454 equal,
55- // TODO: Implement.
5655 bang,
5756 minus,
5857 plus,
Original file line number Diff line number Diff line change 11{{ -"wat" }}
22--- runtime errors
3- line 1, column 4 of test: Cannot negate a value of type String.
3+ line 1, column 4 of test: Operand to "-" must be a number but was String.
44 ╷
551 │ {{ -"wat" }}
66 │ ^
Original file line number Diff line number Diff line change 1+ {{ !yes }}
2+ {{ !no }}
3+ {{ !!yes }}
4+ {{ !!!no }}
5+ --- output
6+ false
7+ true
8+ true
9+ true
10+ --- data
11+ {"yes": true, "no": false}
Original file line number Diff line number Diff line change 1+ {{ !"wat" }}
2+ --- runtime errors
3+ line 1, column 4 of test: Operand to "!" must be a Boolean but was String.
4+ ╷
5+ 1 │ {{ !"wat" }}
6+ │ ^
7+ ╵
You can’t perform that action at this time.
0 commit comments