fmt: support .Nf / :N / :Nd / :<N placeholder specs (#16c)#554
Merged
Conversation
Adds a small printf-style spec layer to fmt so simple numeric / width
formatting doesn't need a fmt2 + padl composition every time.
Supported:
{} bare placeholder (Display)
{.Nf} N decimal places (no colon)
{:.Nf} N decimal places (long form)
{:N} right-align Display to width N (space-pad)
{:Nd} integer right-align to width N (truncate toward zero)
{:<N} left-align Display to width N
Out of scope, still rejected:
{:06d} zero-pad widths (leading-zero width digits)
{:+} sign
{:x} hex
{:.N} precision without the f suffix
Width parsing rejects leading-zero multi-digit widths so {:06d} surfaces
as 'unsupported spec' rather than silently rendering as a 6-wide space
pad. The interpreter is the single source of truth; verify.rs reuses
parse_fmt_spec for static slot counting and unknown-spec rejection so
ILO-T013 and ILO-R009 stay in lockstep.
Cross-engine (tree, VM, Cranelift) regression for every supported spec
plus the rejection paths: zero-pad {:06d} (verify), precision without
f {:.3}, and computed-template runtime spec errors (ILO-R009).
The example file ships the same shapes so tests/examples_engines.rs
exercises them at the harness level too, and so agents loading
'ilo skill get ilo-examples' see the idiomatic forms.
site/text.md already documents the supported specs from a prior docs-only commit; SPEC and ai.txt now match so the four canonical docs (SPEC, ai.txt, skill, site) describe the same surface.
0df9660 to
543f2b5
Compare
❌ 1 Tests Failed:
View the full list of 1 ❄️ flaky test(s)
To view more test analytics, go to the Test Analytics Dashboard |
Collaborator
Author
|
CI status: 3 failing checks (lint, build, coverage), all pre-existing on main:
The only check that ran my changes ( Confirmed by comparing run 26232609248 (this PR) against run 26232029355 (main HEAD a few minutes ago) — same failure signature, same line numbers, both unrelated to the fmt placeholder work. |
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.
Summary
Pending entry #16c from `ilo_assessment_feedback.md`. `fmt` used to support only bare `{}` placeholders, which meant agents reaching for "two decimal places" or "right-align to width 5" had to compose `fmt2` + `padl` by hand:
```
fmt "{}%" (fmt2 (* r 100) 1) -- before
fmt "{.1f}%" (* r 100) -- now
```
Token-wise this is the difference between one builtin call per formatted field and three. The spec is intentionally lean: numeric precision, integer width, and string width are the cases that show up in every persona run, and that's all this adds. Zero-pad, sign-prefix, and hex stay out of scope so the surface doesn't grow into Python's `str.format` over time. Agents wanting those still compose via `padl` / `fmt2`.
Repro before / after
Before (`{:.3f}` rejected at verify-time with ILO-T013):
```
fmt "pi={:.3f}" 3.14159 -- ILO-T013: only supports bare {}
```
After:
```
fmt "pi={:.3f}" 3.14159 -- "pi=3.142"
fmt "{:5d}" 42 -- " 42"
fmt "[{:<5}]" "hi" -- "[hi ]"
fmt "{:06d}" 42 -- still ILO-T013 (zero-pad out of scope)
```
What's in the diff
Test plan
Follow-ups