Some ternaries weren't parsed correctly. Root cause was: When processing a ternary, the parser splits it into its components and hands off the components to be parsed in their turn. At this point, the bad code tried to make sure – in an incorrect way – that there weren't any symbols trailing one of the components. But this very check was superfluous in the first place.
Background: When the parser arrives at an expression in the source code, it isolates the whole expression and then processes exactly it, by splitting it apart and processing the respective parts. From that point onwards, it is the responsibility of each function that receives a (sub-) expression as a parameter to check that there aren't any symbols trailing after it, e.g., flag something like (5 + 6) % as an error where % is a trailing symbol. The caller of such a function must trust that the called function does the necessary tests: It must not try to repeat these tests (separation of concerns principle).
Clarify in header file comments which functions check for trailing symbols in their expression parameter.
Rewrite and reorder the ‘trailing symbol’ checks so that the functions strictly only check what they are responsible for.
Fix a bug in the code that strips the outermost parentheses in an expression.
Enforce that all functions that take an expression as a parameter, don't alter that parameter.
Fix a bug in three places where a function had referenced _src instead of its parameter expression.
Eliminate the expression parameter in three functions that don't actually need it.
Reinstate a googletest that had been partially commented out for unrelated reasons.
Relocate AGS::Parser::StripOutermostParens() in code.
Fixes #2069
Some ternaries weren't parsed correctly. Root cause was: When processing a ternary, the parser splits it into its components and hands off the components to be parsed in their turn. At this point, the bad code tried to make sure – in an incorrect way – that there weren't any symbols trailing one of the components. But this very check was superfluous in the first place.
Background: When the parser arrives at an expression in the source code, it isolates the whole expression and then processes exactly it, by splitting it apart and processing the respective parts. From that point onwards, it is the responsibility of each function that receives a (sub-) expression as a parameter to check that there aren't any symbols trailing after it, e.g., flag something like
(5 + 6) %
as an error where%
is a trailing symbol. The caller of such a function must trust that the called function does the necessary tests: It must not try to repeat these tests (separation of concerns principle).Clarify in header file comments which functions check for trailing symbols in their
expression
parameter.Rewrite and reorder the ‘trailing symbol’ checks so that the functions strictly only check what they are responsible for.
Fix a bug in the code that strips the outermost parentheses in an expression.
Enforce that all functions that take an expression as a parameter, don't alter that parameter.
Fix a bug in three places where a function had referenced
_src
instead of its parameterexpression
.Eliminate the
expression
parameter in three functions that don't actually need it.Reinstate a googletest that had been partially commented out for unrelated reasons.
Relocate
AGS::Parser::StripOutermostParens()
in code.