The except-else accepts a StatementList. The if-then-else does not. In order to tell the two apart the except-else should have a different nodetype, just like the case-else.
Here's the fix:
procedure TPasSyntaxTreeBuilder.ExceptionBlockElseBranch;
begin
FStack.Push(ntExceptElse);
try
inherited;
finally
FStack.Pop;
end;
end;
This allows a DelphiAST user to see the difference between a normal else statement and an except-else.
The first needs a begin-end pair to accept more than one statement, the second does not.
This will also make the except-else consistent with the case-else.
We can now easily check the parent of a ntStatements node.
If it is in the list [ntExcept, ntRepeat, ..., ntCaseElse, ntExceptElse] then we know there was no begin-end pair in the original source code.
Currently the except-else is the only case where we cannot tell the difference between a StatementList node and Statements node.
In addition consider the following code:
try
Something;
except on E:EAccessViolation do
if a>10 then Other else Same;
MoreOfTheSame;
end;
vs
try
Something
except on E:EAccessViolation do
if a > 10 then Other;
else
Same;
MoreOfTheSame;
end;
Clearly the two else statements perform very different actions and should not be confused.
The except-else accepts a StatementList. The if-then-else does not. In order to tell the two apart the except-else should have a different nodetype, just like the case-else.
Here's the fix:
This allows a DelphiAST user to see the difference between a normal else statement and an except-else. The first needs a begin-end pair to accept more than one statement, the second does not.
This will also make the except-else consistent with the case-else.
We can now easily check the parent of a
ntStatements
node. If it is in the list [ntExcept, ntRepeat, ..., ntCaseElse, ntExceptElse] then we know there was no begin-end pair in the original source code.Currently the except-else is the only case where we cannot tell the difference between a
StatementList
node andStatements
node.In addition consider the following code:
Clearly the two else statements perform very different actions and should not be confused.