Expand description
Semantic-level normalisation (strip comments, line endings,
keyword casing) used by --verify and the idempotency tests.
Semantic-level normalisation for parsed CMake.
Helpers that strip away parts of the AST that don’t affect CMake semantics — comments, line endings, keyword casing — so two files can be compared “would they behave identically?” without worrying about cosmetic-only differences.
Used by:
cmakefmt --verifyandcmakefmt --in-place(inmain.rs) to confirm formatted output preserves CMake semantics.tests/idempotency.rsto assert formatter idempotency on the real-world corpus.
Previously these helpers were duplicated between main.rs and the
integration test, with a hand-coded “keep in sync” comment that
Phase 47g’s deduplication audit flagged. They now live here as the
single source of truth.
All helpers walk a fully-parsed CommandInvocation in place. The
public surface is normalize_command_literals (strip cosmetic
differences from a single command) and normalize_keyword_args
(uppercase known keyword tokens for case-insensitive comparison).
Internal helpers stay private to the module.
Functions§
- normalize_
command_ literals - Strip comment and line-ending differences from a parsed
CommandInvocationso two semantically-equivalent commands compare equal regardless of cosmetic formatting. - normalize_
keyword_ args - Uppercase any unquoted argument that matches a known keyword for
the command’s spec. CMake keywords are case-insensitive at the
language level, so two files that differ only in the casing of
PUBLICvspublicare semantically equivalent. - normalize_
line_ endings - Strip Windows-style
\r\nline endings to plain\nin place. - normalize_
semantics - Reduce a parsed file to its semantic skeleton: drop standalone comments and blank lines, zero out spans, lowercase command names, and normalise each command’s literals and keyword casing. Two files that behave identically in CMake produce equal skeletons.
- semantic_
equivalent - Return
trueifleftandrightare the same CMake program once cosmetic-only differences (comments, blank lines, whitespace, line endings, command-name and keyword casing) are stripped.