fix(pict): spec-conformance fixes + comment classification - #51
Merged
Conversation
Three deviations from Microsoft PICT's documented model syntax
(pict/doc/pict.md), fixed in both the TypeScript and Python ports:
1. Numeric IN sets rejected. `IN {512, 1024}` — the value form used in
PICT's own documentation — threw "Unexpected token in array" because
the set parser only accepted string tokens. Now numeric elements are
accepted (TS + Python).
2. LIKE treated regex metacharacters as special (TS only). `LIKE "4.8*"`
matched "4x8.1" because `.` was passed through to the regex verbatim.
All metacharacters are now escaped, then only `*` and `?` are restored
as wildcards. (Python already used re.escape and was correct.)
3. Sub-model order was mandatory. `{ A, B }` without `@ N` was rejected
and treated as a constraint. Per spec the order is optional and, when
omitted, defaults to the global order (/o). The order is now optional
and resolved to the global strength at generation time.
Tests updated/added on both sides. Full suites green
(TS: 179 passing, Python: 68 passing).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #51 +/- ##
==========================================
+ Coverage 80.74% 81.74% +1.00%
==========================================
Files 35 35
Lines 3142 3178 +36
Branches 416 425 +9
==========================================
+ Hits 2537 2598 +61
+ Misses 592 567 -25
Partials 13 13
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Adds comment classification to the PICT parser. Each maximal run of `#` lines becomes a CommentBlock, classified as either a field description (attached to the parameter directly below it, no blank line between) or freestanding documentation (separated by a blank line, or sitting above a constraint / non-parameter line). - `classifyComments()` in parse.ts is the single source of truth, reused for prompt assembly and editor syntax highlighting. - `CommentBlock` type and `classifyComments` are exported from the package. - `PictModel.comments` exposes the classified blocks. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…antics
Adds regression tests on both ports for the spec-conformance fixes:
- numeric and float IN sets (`IN {512, 1024}`, `IN {2.5, 3}`)
- LIKE treats non-wildcard chars (e.g. `.`) as literals
- LIKE `?`/`*` wildcard matching
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- IN accepts numeric sets (e.g. IN {512, 1024}), not just strings
- Sub-model `@ N` order is optional and defaults to the global order
- Clarify LIKE treats non-wildcard characters as literals
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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
Changes to the PICT model parser (TypeScript + Python):
pict/doc/pict.md).#comments into structured, per-field descriptions (TS only).1. Spec-conformance fixes
INsets rejected —IN {512, 1024}threwUnexpected token in array(this is the value form used in PICT's own docs)LIKEtreated regex metacharacters as special —LIKE "4.8*"matched4x8.1because.leaked into the regexre.escape){ A, B }without@ Nwas rejected; per spec the order is optional and defaults to the global order (/o)NUMBERtokens (integers/floats), not just quoted strings.*→.*and?→.as wildcards, matching PICT semantics where all other characters are literal.SubModelType.strengthis optional and resolved to the global order at generation time (sub.strength ?? this.strength). A malformed order such as{ A, B } @ xstill produces an error.2. Comment classification
Each maximal run of
#lines becomes aCommentBlock, classified as either a field description (attached to the parameter directly below it, no blank line between) or freestanding documentation (separated by a blank line, or above a constraint / non-parameter line).classifyComments()is the single source of truth;CommentBlockandclassifyCommentsare exported, andPictModel.commentsexposes the blocks.3. Docs
docs/contents/reference/pict.mdx— documented numeric IN sets, optional sub-model order (syntax table + PICT-differences section), and LIKE literal semantics.docs/contents/tools/pict-online.mdx— same clarifications in the tool page's Constraints/Parameters tables.Testing
npm test→ 18 suites, 179 tests passing (includespict-comments.test.tsand new numeric/float-IN and LIKE tests).pytest→ 47 tests passing (numeric & float IN sets, order-less sub-models, malformed order, LIKE literal/wildcard).Not included
[SKU] = "Datacenter"matching an alias rather than only the first name) is a separate spec question left for a design decision.pict/reference repo) are intentionally excluded.🤖 Generated with Claude Code