convert python % string formatting to v interpolation#41
Merged
medvednikov merged 1 commit intovlang:masterfrom Feb 20, 2026
Merged
convert python % string formatting to v interpolation#41medvednikov merged 1 commit intovlang:masterfrom
medvednikov merged 1 commit intovlang:masterfrom
Conversation
add convert_percent_format() in helpers.v that parses Python % format specifiers and emits V string interpolation with correct format specs. handles %s, %d/%i, %f/%F, %e/%E, %g/%G, %x/%X, %o, and %% (literal). preserves Python default precision (6 decimal places for bare %f/%e). left-align flag overrides zero-pad (%-05d -> :-5, not :0-5). bare dot precision means 0 (%.f -> :.0f, not default 6). integer modulo (int % int) passes through correctly. in transpiler.v, visit_binop detects Mod with string Constant on the left side and routes to convert_percent_format instead of raw %. 109 pass, 0 fail, 0 skip (v 0.5.0 a9423b5)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Converts Python
%string formatting expressions to V string interpolationwith correct format specifiers.
Changes
convert_percent_format()inhelpers.v: parses Python%formatspecifiers (
%s,%d,%f,%e,%g,%x,%o,%%) and emits Vinterpolation with correct format specs
%f/%e)%-05d->:-5)%.f->:.0f)visit_binop()intranspiler.v: detectsModwith stringConstanton left side and routes to format conversion instead of raw
%10 % 3) passes through correctlyTest plan
string_format_percentcovers:%s,%d,%.2f,%05d,%x, multi-value tuple,%%, default%f,%.f,%-05d, integer modulo