Accept bare IDENT in kind-qualified brackets (#119)#143
Merged
Conversation
This was referenced Apr 24, 2026
- Parser accepts affinity[netmhcpan] in addition to affinity['netmhcpan']; both forms produce the same AST. Non-IDENT values (e.g. "4.1b") still require quotes. - New Tokenizer.expect_string_or_ident helper drives the four bracket-arg sites in _postfix and _kind_accessor. - to_expr_string keeps emitting the canonical single-quoted form so round-trips stay deterministic. - Grammar comment updated.
2e9716e to
0166dc4
Compare
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
Closes #119 (step 1 only — step 2 labels deferred until there's real demand).
The string DSL now accepts bare identifiers inside kind-qualified brackets in addition to the quoted form:
```
affinity[netmhcpan] <= 500 # new
affinity[netmhcpan, "4.1b"] <= 500 # version keeps quotes (not an IDENT)
affinity['netmhcpan'] <= 500 # still parses
affinity['netmhcpan', '4.1b'].rank <= 2.0 # still parses
```
Motivated by YAML-embedded configs (e.g. vaxrank scoring YAML), where `"affinity[netmhcpan] <= 500"` is much easier to read than `"affinity['netmhcpan'] <= 500"` with nested quote escaping.
Changes
Back-compat
Fully additive. Every previously-valid expression still parses. Error surface for genuinely invalid bracket args is clearer: `parse("affinity[netmhcpan, 4]")` → `ValueError("Expected STRING or IDENT ...")` instead of the old `Expected STRING ...`.
Deferred (Step 2 of the issue)
Prometheus-style labels (`affinity[predictor=netmhcpan, version="4.1b"]`) are left out of this PR. They're the right escape hatch if positional order starts tripping users up, but Step 1 solves the immediate YAML ergonomics pain.
Test plan