Skip to content

RFC 0021: Percent String Array Literal with Interpolation - #21

Merged
straight-shoota merged 14 commits into
masterfrom
rfc/percent-array-literal-interpolation
Jul 15, 2026
Merged

straight-shoota merged 14 commits into
masterfrom
rfc/percent-array-literal-interpolation

Conversation

@straight-shoota

@straight-shoota straight-shoota commented Feb 25, 2026

Copy link
Copy Markdown
Member

Comment thread text/0021-percent-array-literal-interpolation.md Outdated
Co-authored-by: Julien Portalier <julien@portalier.com>
@straight-shoota
straight-shoota changed the base branch from main to master February 27, 2026 18:14
@straight-shoota
straight-shoota marked this pull request as ready for review February 28, 2026 20:40
@straight-shoota straight-shoota changed the title Percent String Array Literal with Interpolation RFC 0021: Percent String Array Literal with Interpolation Mar 3, 2026
%W[foo #{"bar"}baz#{"bab"} qux] # => ["foo", "barbazbab", "qux"]
%W[foo _#{"bar"}_ baz] # => ["foo", "_bar_", "baz"]
%W[foo #{"bar baz"} qux] # => ["foo", "bar baz", "qux"]
```

@HertzDevil HertzDevil Mar 3, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO this should show the immediate transformations performed by the compiler, more specifically the parser, rather than the final results of the expressions. If I have to guess, this would mean:

["foo", "#{1 + 1}", "baz"] of ::String
["foo", "#{"bar"}baz#{"bab"}", "qux"] of ::String

and also splat elements would be retained verbatim, without introducing another StringInterpolation node:

["foo", *%w[bar baz], "qux"] of ::String

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. The reference-level explanation is actually just an extended guide-level and does not explain the technical details. I'll expand on that 👍

Comment thread text/0021-percent-array-literal-interpolation.md Outdated
Comment thread text/0021-percent-array-literal-interpolation.md
straight-shoota added a commit to crystal-lang/crystal that referenced this pull request Mar 4, 2026
This is a bit of code cleanup, avoiding unnecessary intermediaries and removing duplication.

It's in preparation for implementing `%W` string array literals (crystal-lang/rfcs#21).

@ysbaddaden ysbaddaden left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This RFC is ready for implementation 👍

@crysbot

crysbot commented Mar 10, 2026

Copy link
Copy Markdown

This pull request has been mentioned on Crystal Forum. There might be relevant details there:

https://forum.crystal-lang.org/t/rfc-0021-percent-string-array-literal-with-interpolation/8772/1

straight-shoota added a commit to crystal-lang/crystal that referenced this pull request Mar 17, 2026
This is a plain refactoring to extract behaviour into helper methods. It helps structure the code and prepares for reusing these helpers to implement interpolation for string array literals ([RFC 0021](crystal-lang/rfcs#21)).
straight-shoota added a commit to crystal-lang/crystal that referenced this pull request Mar 19, 2026
…16747)

Continuation of #16720, but extracted into a separate commit for a cleaner diff because of overlap.

This is a plain refactoring to extract behaviour into helper methods. It helps structure the code and prepares for reusing these helpers to implement interpolation for string array literals ([RFC 0021](crystal-lang/rfcs#21)).
straight-shoota added a commit to crystal-lang/crystal that referenced this pull request May 4, 2026
Previously, string array literal parsing used a custom implementation, combined with a custom lexer mode (`next_string_array_token`).

This patch changes that to reuse the same parser and lexer features as other string literals. This standardization removes an extra concept and thus reduces code surface area. In return, we're adding some conditionals for this specific literal type into the standard implementations. This increases complexity a little bit, but it's still fairly easy to reason about and a common pattern in the parser.
Combining the parsing of all string-related literals clearly shows their differences (in the form of such conditionals) and ensures consistent behaviour.

In particular, this change establishes standard behaviour for escape characters, and thus fixes #12277
However, it's unclear whether we accept this behaviour change (see #12277 (comment)). If not, we need to implement a non-standard escape algorithm to ensure backwards-compatibility.

The main motivation for this refactor is that it opens the path for implementing string literals with interpolation ([RFC 0021](crystal-lang/rfcs#21)).

Co-authored-by: Julien Portalier <julien@portalier.com>
straight-shoota added a commit to crystal-lang/crystal that referenced this pull request Jun 3, 2026
@straight-shoota
straight-shoota merged commit 268b5a1 into master Jul 15, 2026
2 checks passed
@straight-shoota
straight-shoota deleted the rfc/percent-array-literal-interpolation branch July 15, 2026 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants