Structure initializer VS lambda function

realhet real_het at hotmail.com
Mon Dec 12 08:54:33 UTC 2022


Hi,

I'm writing a DLang parser and got confused of this.
What is a good way to distinguish lambda functions and structure 
initialization blocks.

Both of them are {} blocks.

I'm thinking of something like this:

1. checking inside (on the first hierarchy level inside {})
    ,   => must be a struct initializer
    ;   => must be a lambda
    no , and no ;  => check it from the outside


2. checking outside (on the same hierarchy level as the {}):
    () before {}   ->  lambda
    => before {}   ->  lambda
    () after {}    ->  lambda  //this check feels wrong to me.
    otherwise      ->  struct initializer

But I think it's logically loose.
I have only the syntax tree, I have no access to semantics. I 
don't know if an identifier is a struct for example.

Is there a better way to do this?

Thank You in advance!


More information about the Digitalmars-d-learn mailing list