Skip to content

Match symbols as whole names and validate block structure - #13

Merged
cssho merged 3 commits into
masterfrom
strict-conditions
Oct 26, 2026
Merged

cssho merged 3 commits into
masterfrom
strict-conditions

Conversation

@cssho

@cssho cssho commented Oct 26, 2026 •

Copy link
Copy Markdown
Owner

Closes #7

Summary

User-visible behavior changes — release as 0.2.0.

Case Before (0.1.x) After
symbol: DEBUG, #if DEBUG_X / #if MY_DEBUG true (substring regex) false (exact name)
symbol: THAT, #if THIS | THAT | OTHER / #if THIS|THAT|OTHER (#7) true (substring, by accident) true — | is now an official name separator, alongside whitespace
symbol: C++ re.error crash works
no symbol configured every #if true every #if false
unclosed #if, extra #endif AssertionError (skipped under python -O) ConditionSyntaxError with line number, always
nested #if, #else outside a block, duplicate #else silently mis-rendered / passed through ConditionSyntaxError
  • ConditionSyntaxError subclasses both ValueError and AssertionError, so existing except AssertionError callers keep working
  • Exported from md_condition; README gains a "Rules" section; CLAUDE.md updated

Test plan

  • uv run pytest — 23 passed (new: whole-name matching incl. regex metachars and empty symbol, | separators with/without spaces and at the edges, each malformed-block case with line number, AssertionError compatibility)
  • Error raised under python -O
  • ruff check / format clean
  • CI green

🤖 Generated with Claude Code

https://claude.ai/code/session_012pKTVb5TrGn27R29rHHNck

cssho and others added 3 commits October 26, 2026 21:22
Behavior changes:
- #if names are compared exactly instead of via an unescaped substring
  regex: DEBUG no longer matches DEBUG_X, symbols with regex
  metacharacters (e.g. C++) work, and an empty symbol matches nothing
  (previously it matched every #if)
- Malformed blocks raise ConditionSyntaxError with the line number,
  also under python -O. Nesting, stray #else/#endif, and duplicate
  #else are now detected instead of silently mis-rendering.
  ConditionSyntaxError subclasses AssertionError for compatibility.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012pKTVb5TrGn27R29rHHNck
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012pKTVb5TrGn27R29rHHNck
Base automatically changed from modernize to master October 26, 2026 12:30
@cssho
cssho merged commit b8694d5 into master Oct 26, 2026
8 checks passed
@cssho
cssho deleted the strict-conditions branch October 26, 2026 12:39
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.

Partial match (search) vice full match

1 participant