Skip to content

Support elsif when stringifying If nodes#15918

Merged
straight-shoota merged 2 commits intocrystal-lang:masterfrom
HertzDevil:feature/astnode-to_s-elsif
Jun 25, 2025
Merged

Support elsif when stringifying If nodes#15918
straight-shoota merged 2 commits intocrystal-lang:masterfrom
HertzDevil:feature/astnode-to_s-elsif

Conversation

@HertzDevil
Copy link
Contributor

When an If node's else-clause is itself a non-ternary If node, combines the two nodes and emits an elsif, instead of an else plus an indented if. This is done even when the original nodes did not use an elsif, and applies to arbitrarily long If chains.

@straight-shoota
Copy link
Member

I'm not sure if this is okay... IMO stringification should print a representation of the AST node, not implicitly transform it.

If we want such a transformation, perhaps it should better be explicit.

@HertzDevil
Copy link
Contributor Author

There is no AST transformation per se, because there is simply no such thing as an Elsif node right now. The two representations are syntactically equivalent and this only amounts to picking a different canonical string representation.

@straight-shoota straight-shoota added this to the 1.17.0 milestone Jun 23, 2025
@straight-shoota straight-shoota merged commit f66114d into crystal-lang:master Jun 25, 2025
38 checks passed
@HertzDevil HertzDevil deleted the feature/astnode-to_s-elsif branch June 25, 2025 09:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants