Skip to content

Handle advanced formatter specs in template parser#67

Merged
RAprogramm merged 1 commit intonew_versionfrom
codex/update-parser-for-formatter-traits
Sep 19, 2025
Merged

Handle advanced formatter specs in template parser#67
RAprogramm merged 1 commit intonew_versionfrom
codex/update-parser-for-formatter-traits

Conversation

@RAprogramm
Copy link
Owner

Summary

  • enhance the template parser to detect formatter traits after arbitrary alignment, sign and width flags while rejecting duplicate # markers
  • centralise specifier parsing through a shared helper and expand parser unit tests to cover complex cases and malformed specs
  • bump the workspace to v0.5.10 (template crate v0.1.4) with matching README and changelog updates

Testing

  • cargo +nightly fmt --
  • cargo +1.90.0 clippy -- -D warnings
  • cargo +1.90.0 test --all
  • cargo +1.90.0 doc --no-deps
  • cargo deny check
  • cargo audit

https://chatgpt.com/codex/tasks/task_e_68cd02940704832ba97e2169e4f49a66

@RAprogramm RAprogramm merged commit bd6108b into new_version Sep 19, 2025
1 of 2 checks passed
@RAprogramm RAprogramm deleted the codex/update-parser-for-formatter-traits branch September 19, 2025 07:38
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

Codex Review: Here are some suggestions.

Reply with @codex fix comments to fix any unresolved comments.

About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you open a pull request for review, mark a draft as ready, or comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex fix this CI failure" or "@codex address that feedback".

Comment on lines +201 to +219
loop {
let mut chars = rest.chars();
let Some(ch) = chars.next() else {
return Some(false);
};

match ch {
'+' | '-' | ' ' => {
rest = &rest[ch.len_utf8()..];
}
'#' => {
rest = &rest[ch.len_utf8()..];
if rest.chars().any(|value| value == '#') {
return None;
}
return Some(true);
}
_ => return Some(false)
}

Choose a reason for hiding this comment

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

[P1] Reject # flag that appears after width or zero padding

The new alternate-flag detector returns Some(false) as soon as it encounters any character other than +, - or space and never inspects the remainder of the prefix. As a result, format strings such as {value:0#x} or {value:>8#x}—which the Rust formatter rejects because the # flag must precede 0/width—are now parsed as valid hex formatters with alternate: false. Earlier versions correctly produced TemplateError::InvalidFormatter. This regression means invalid templates are accepted by the macro while the subsequent format! invocation will still fail to compile. The function should scan the whole prefix and return None if a # appears after width or padding characters.

Useful? React with 👍 / 👎.

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.

1 participant