---
fp = function int(int a) => a;
---
This code is accepted by DMD but cannot be produced by the grammar:
FunctionLiteral:
function Type(opt) ParameterAttributes(opt) FunctionBody
delegate Type(opt) ParameterAttributes(opt) FunctionBody
ParameterAttributes FunctionBody
FunctionBody
Lambda
ParameterAttributes:
Parameters
Parameters FunctionAttributes
Lambda:
Identifier => AssignExpression
function(opt) ParameterAttributes => AssignExpression
delegate(opt) ParameterAttributes => AssignExpression
Comment #1 by hsteoh — 2014-09-09T23:37:51Z
I had no idea this syntax was supported. Is it intentional, or is it an oversight in the implementation?
(In reply to hsteoh from comment #1)
> I had no idea this syntax was supported. Is it intentional, or is it an
> oversight in the implementation?
It's a hold-over from the other function literal syntax:
auto fp = function int(int a) { return a; };
It's just as useful whether it's using lambdas or the old syntax, so I suggest we reconcile the grammar with DMD in this case.
Comment #4 by k.hara.pg — 2014-09-19T00:26:10Z
(In reply to briancschott from comment #0)
> ---
> fp = function int(int a) => a;
> ---
When I cleaned up parser code for lambdas, the syntax was intentional as that is a combination of:
- the keyword "function" for function literals
- optional return type specification
- parameter list
- lambda style function literal body ("=>" with one AssignExpression)
So, I'd fix the grammar to fit accepted code by dmd, like follows.
Lambda:
function Type(opt) ParameterAttributes => AssignExpression
delegate Type(opt) ParameterAttributes => AssignExpression
ParameterAttributes => AssignExpression
Identifier => AssignExpression