Skip to content

Parse CMake generator expressions to a tree, evaluate it separately - #368

Merged
lefticus merged 1 commit into
cpp-best-practices:mainfrom
leftibot:genex-tree
Nov 23, 2026
Merged

lefticus merged 1 commit into
cpp-best-practices:mainfrom
leftibot:genex-tree

Conversation

@leftibot

Copy link
Copy Markdown
Collaborator

Part of #300 (principle 1: parse to a tree, evaluate separately; the last reader that evaluated as it read)

Generator expressions were evaluated as they were read: the text was split at colons and commas on the way to a value. They're now parsed and evaluated in two layers, as #300's step 6 did for GitHub expressions and CMake if().

  • Syntax (cmake/generator_syntax.py): text becomes a Template of literal parts and Expressions. Each expression has its name, the rest after its first colon outside nested expressions, its text as written, and where it is in the text.
    • The rest is not split: what a comma means is the expression's to decide. $<IF:c,a,b> takes three arguments, while $<1:a,b> is the value a,b. The evaluator splits it.
    • An unclosed $< is text to the end, as before.
  • Evaluation (cmake/generator_expressions.py): walks that tree. Its public functions (generated, test) and their tests are unchanged.

Verified:

  • All local gates pass.
  • New syntax tests, written first, cover names and rests, nesting, unclosed expressions, positions and splitting.
  • Corpus: 0 of 235 projects differ.

🤖 Generated with Claude Code

https://claude.ai/code/session_01ByTXNqDWdM7HzezrFtEvQt

Generator expressions were evaluated as they were read: the text was split at colons and commas on the way to a
value. `cmake/generator_syntax.py` parses text to a `Template` of literal parts and `Expression`s, each with its
name and the rest after its first colon, as written and where it is; `generator_expressions` evaluates that tree.
The rest is not split by the parser: what a comma means is the expression's (`$<IF:c,a,b>` takes three arguments,
`$<1:a,b>` the value `a,b`), so its evaluation splits it.

The evaluation's tests are unchanged, and pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ByTXNqDWdM7HzezrFtEvQt
@lefticus
lefticus merged commit 8d90b79 into cpp-best-practices:main Nov 23, 2026
24 checks passed
@lefticus
lefticus deleted the genex-tree branch November 23, 2026 23:27
@codecov

codecov Bot commented Nov 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.68%. Comparing base (116970c) to head (511bd69).
⚠️ Report is 25 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #368   +/-   ##
=======================================
  Coverage   99.68%   99.68%           
=======================================
  Files         311      312    +1     
  Lines       19734    19768   +34     
  Branches     2303     2307    +4     
=======================================
+ Hits        19672    19706   +34     
  Misses         62       62           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

2 participants