Skip to content

parser, ast, fmt: convert "hello".str => c"hello" (fix #24635)#24652

Merged
spytheman merged 20 commits into
vlang:masterfrom
StunxFS:transformer/inline-str-access
Jun 8, 2025
Merged

parser, ast, fmt: convert "hello".str => c"hello" (fix #24635)#24652
spytheman merged 20 commits into
vlang:masterfrom
StunxFS:transformer/inline-str-access

Conversation

@StunxFS

@StunxFS StunxFS commented Jun 4, 2025

Copy link
Copy Markdown
Contributor

The compiler will now treat "hello".str as if it were written c"hello" (or js"hello"), which avoids creating an unnecessary string object. The formatter will also correct that piece of code by adding the necessary prefix.

In addition to that, this PR depends on another PR (#24653) that will implement JS string literals (I thought V already supported them), now it will be possible to create native JS strings using a simple prefix (just like you would do with C).
The JS backend is ignored.

Fix #24635.

@huly-for-github

Copy link
Copy Markdown

Connected to Huly®: V_0.6-23011

@StunxFS StunxFS changed the title parser, ast, fmt, gen, transformer: support js"string literal" + convert "hello".str => c"hello" parser, ast, fmt, transformer: convert "hello".str => c"hello" (fix #24635) Jun 4, 2025
Comment thread vlib/v/fmt/fmt.v Outdated
Comment thread vlib/v/transformer/transformer.v Outdated
@StunxFS StunxFS changed the title parser, ast, fmt, transformer: convert "hello".str => c"hello" (fix #24635) parser, ast, fmt: convert "hello".str => c"hello" (fix #24635) Jun 6, 2025
Comment thread vlib/v/fmt/fmt.v
Comment thread vlib/v/transformer/transformer.v Outdated
@StunxFS StunxFS marked this pull request as ready for review June 6, 2025 17:46
@StunxFS StunxFS requested a review from spytheman June 6, 2025 17:47

@spytheman spytheman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Excellent work.

@spytheman spytheman merged commit a5f400e into vlang:master Jun 8, 2025
74 checks passed
@StunxFS StunxFS deleted the transformer/inline-str-access branch June 8, 2025 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vfmt: format "c string literal".str to c"c string literal"

4 participants