On 07/28/2014 09:32 PM, Brian Schott wrote:
On Monday, 28 July 2014 at 19:12:49 UTC, Timon Gehr wrote:
I'd suggest to just special case the general thing, or not add any
special cases at all.
catch(Type)
^~~~~~
I.e. use lookahead to determine whether something that looks like a
type follows a '(' token and is itself followed by a ')' token.
This doesn't help.
...
Depends on what outcome one is after.
catch (Type).functionName() is valid both as
LastCatch
PostfixExpression
PostfixExpression
PostfixExpression
PrimaryExpression
'(' Type ')'
'.' identifier
'(' ')'
And as
Catch
'(' Type ')'
PrimaryExpression
'.'
PostfixExpression
PrimaryExpression
'functionName'
'(' ')'
Obviously, hence the alternative suggestion to not add any special cases
(and then the most sensible way out seems to be to just retire the
catch-all syntax).
(But as you're likely to know, there are some of those cases already (if
less severe):
foreach(i;0..n){
// ...
}
(&x).foo();
The above is grammatically ambiguous, but DMD parses it as two distinct
statements using an ad-hoc disambiguation rule.
try{
// ...
}catch(Exception e){
return e;
}
(new Exception("hi")).msg.writeln;
Similarly. In contrast to above, the alternative parsing might actually
pass the type checker.)