Skip to content

Conversation

@konard
Copy link
Member

@konard konard commented Dec 13, 2025

Summary

This PR implements issue #184: adds support for multi-word references without quotes.

Key Changes:

JavaScript & Python:

  • Link.ids is now the primary storage (array of strings)
  • Link.id is a computed property that:
    • Returns the single string for single-reference IDs
    • Throws an error for multi-reference IDs with message: "Use the 'ids' property instead of 'id'"
  • Removed context-aware value parsing (out of scope per feedback)
  • Values are parsed as separate references, not grouped by context

Rust & C#:

  • Already support multi-word IDs (stored as joined strings)
  • No breaking changes to existing API

Usage Example:

// Parse multi-reference
const result = parser.parse('(some example: value)');

// Access ids (always works)
console.log(result[0].ids); // ['some', 'example']

// Access id (throws for multi-refs)
console.log(result[0].id); // Error: "Use the 'ids' property instead of 'id'"

// Single refs still work with id
const single = parser.parse('(papa: value)');
console.log(single[0].id); // 'papa'
console.log(single[0].ids); // ['papa']

Breaking Changes:

For multi-reference IDs:

  • Must use .ids property to access the array of reference parts
  • The .id property will throw an error if the ID has multiple parts

Test Plan:

  • All JS tests pass (207 tests)
  • All Python tests pass (195 tests)
  • All Rust tests pass (39 tests)
  • All C# tests pass (191 tests)
  • Prettier formatting check passes

🤖 Generated with Claude Code

Fixes #184

Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: #184
@konard konard self-assigned this Dec 13, 2025
@konard
Copy link
Member Author

konard commented Dec 13, 2025

🔍 Clarification Needed for Issue #184 Implementation

Hi @konard,

I've been analyzing the issue requirements and want to ensure I understand the expected behavior correctly before implementing:

Current Understanding

The issue mentions supporting "multi-references" with this example:

(some example: some example is a link)

And switching to arrays for both id and values.

Questions

  1. Multi-word ID representation: Should the id field change from a single string to an array of strings?

    • Current: id = "some example" (quoted)
    • Proposed: id = ["some", "example"] (array of tokens)
  2. Syntax clarification: In (some example: some example is a link):

    • Is some example before the colon the multi-reference ID (2 tokens)?
    • Is some example is a link after the colon the values (5 tokens)?
    • Expected parse result would be: Link(id=["some", "example"], values=[Ref("some"), Ref("example"), Ref("is"), Ref("a"), Ref("link")])?
  3. Reference resolution: The issue mentions "if we have defined any multi references in the file, it means we should treat some example in any places as single multi-reference."

    • Does this mean we need a two-pass parser or context-aware parsing?
    • When some example appears later in the document, should it be recognized as a single reference ["some", "example"] rather than two separate references?
  4. Backward compatibility: Should the existing quoted string syntax still be supported?

    • e.g., ('some example': value) should still work and produce id = "some example"?
  5. Formatting output: When formatting back to string, should multi-word IDs:

    • Be output without quotes: some example: ...
    • Or with quotes for compatibility: 'some example': ...

Please let me know if my understanding is correct or if there's additional context I should consider.

Thanks!

konard and others added 6 commits December 13, 2025 12:23
Implements issue #184 for JavaScript:
- Grammar updated to allow multiple space-separated references before colon
- ID field can now be string[] for multi-word references (e.g., ["some", "example"])
- Single-word IDs remain as string for backward compatibility
- Context-aware multi-reference recognition in values
- Added 22 new tests for multi-reference feature
- All 210 tests pass (188 existing + 22 new)

Example usage:
  (some example: some example is a link)
  -> id: ["some", "example"], values: [MultiRef["some", "example"], "is", "a", "link"]

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Implements issue #184 for Python:
- Parser updated to support multi-word IDs before colon (e.g., "some example:")
- ID field can now be list[str] for multi-word references
- Single-word IDs remain as string for backward compatibility
- Context-aware multi-reference recognition in values
- Added 22 new tests for multi-reference feature
- All 198 tests pass (176 existing + 22 new)

Example usage:
  (some example: some example is a link)
  -> id: ["some", "example"], values: [MultiRef["some", "example"], "is", "a", "link"]

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add RefId enum with Single(String) and Multi(Vec<String>) variants
- Update Link struct to use Option<RefId> for id field
- Add multi_ref_id parser for space-separated words before colon
- Add id_string() and to_single_string() helper methods
- Update all tests to use id_string() for assertions
- Add 11 new multi-reference tests

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add multiRefId rule in Parser.peg for space-separated words before colon
- Update EscapeReference to not quote strings with only spaces
- Update NeedsParentheses to not trigger on spaces
- Add 11 new multi-reference tests
- Update existing tests for new formatting behavior

Multi-word IDs are now supported without quotes:
  (some example: value) parses as id="some example"

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Run Prettier on JS files
- Run Black on Python files
- Run cargo fmt on Rust files

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@konard konard changed the title [WIP] Support multiple references as single reference feat: Add multi-reference support for unquoted multi-word IDs (#184) Dec 13, 2025
@konard konard marked this pull request as ready for review December 13, 2025 11:41
@konard
Copy link
Member Author

konard commented Dec 13, 2025

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $18.471777 USD
  • Calculated by Anthropic: $13.166545 USD
  • Difference: $-5.305232 (-28.72%)
    📎 Log file uploaded as GitHub Gist (2606KB)
    🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard
Copy link
Member Author

konard commented Dec 13, 2025

🔄 Auto-restart 1/3

Detected uncommitted changes from previous run. Starting new session to review and commit them.

Uncommitted files:

M js/package-lock.json
?? experiments/grammar_backup.pegjs

Auto-restart will stop after changes are committed or after 2 more iterations. Please wait until working session will end and give your feedback.

@konard
Copy link
Member Author

konard commented Dec 13, 2025

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $1.129287 USD
  • Calculated by Anthropic: $0.791603 USD
  • Difference: $-0.337684 (-29.90%)
    📎 Log file uploaded as GitHub Gist (2857KB)
    🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard
Copy link
Member Author

konard commented Dec 14, 2025

Single quoted reference is single quoted reference. Not multiple references. There also should be no such thing as Link( ... Values[Ref(...)]). We need to have only something like this: Link(Id=["reference1", "reference2"], Values=(Link((Id=["reference1"])).

Does this mean we need a two-pass parser or context-aware parsing?
When some example appears later in the document, should it be recognized as a single reference ["some", "example"] rather than two separate references?

I think it is out of the scope of the parser for now. If later we will have interpreter it should handle multi-references as he likes.

Backward compatibility

Quoted references are just single references nothing else, of course they should continue to work.

We can keep id as a string for backward compatibility, but it should use actual ids array, and if array has more than one value we should throw an error to use ids instead of id.

So we should make id a computable property out of ids.

If everything is clear now, please implement it.

@konard konard marked this pull request as draft December 14, 2025 20:57
@konard
Copy link
Member Author

konard commented Dec 14, 2025

🤖 AI Work Session Started

Starting automated work session at 2025-12-14T20:57:41.591Z

The PR has been converted to draft mode while work is in progress.

This comment marks the beginning of an AI work session. Please wait working session to finish, and provide your feedback.

konard and others added 2 commits December 14, 2025 22:09
…uted property

Per feedback in issue #184:
- Changed Link class to use _ids array as primary storage
- The id property now throws an error for multi-refs (use ids instead)
- Single refs maintain backward compatibility via id property
- Removed context-aware value parsing (out of scope per feedback)
- Values are parsed as separate references, not grouped

Breaking changes for multi-refs:
- Access link.ids for the array of reference parts
- link.id throws for multi-refs with message to use ids

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@konard konard marked this pull request as ready for review December 14, 2025 21:12
@konard
Copy link
Member Author

konard commented Dec 14, 2025

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $12.320612 USD
  • Calculated by Anthropic: $8.268780 USD
  • Difference: $-4.051832 (-32.89%)
    📎 Log file uploaded as GitHub Gist (1857KB)
    🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard
Copy link
Member Author

konard commented Dec 23, 2025

Get latest changes from default branch and double check that we have the same test cases in all supported languages.

@konard konard marked this pull request as draft December 23, 2025 19:56
@konard
Copy link
Member Author

konard commented Dec 23, 2025

🤖 AI Work Session Started

Starting automated work session at 2025-12-23T19:56:31.938Z

The PR has been converted to draft mode while work is in progress.

This comment marks the beginning of an AI work session. Please wait working session to finish, and provide your feedback.

konard and others added 4 commits December 23, 2025 20:57
Add comprehensive multi-reference tests for Go and Java to match the test coverage in JS, Python, Rust, and C#.

Also fix formatters in both languages to not quote multi-word IDs when they're in parenthesized form with a colon. Multi-word IDs like "some example" should be formatted as `(some example: value)` instead of `('some example': value)`.

Changes:
- Add go/multi_ref_test.go with 12 tests covering multi-reference parsing, formatting, and backward compatibility
- Add java/src/test/java/.../MultiRefTest.java with 12 tests for multi-reference feature
- Add escapeReferenceForParenthesizedID and escapeReferenceForIndentedID helpers to go/lino.go
- Add escapeReferenceForParenthesizedId helper to java/.../Link.java
- Update formatting logic to use new helpers when formatting IDs in parenthesized and indented contexts

All tests pass across all languages (JS: 207, Python: 195, Rust: 39, C#: 191, Go: 90, Java: 12).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Update testQuotedReferencesWithSpaces to expect multi-word IDs to be formatted without quotes in parenthesized form, consistent with the new multi-reference feature (issue #184).

After parsing, Java cannot distinguish between quoted IDs like 'a a' and unquoted multi-word IDs like 'a a' - both are stored as the string "a a". The formatter now treats all multi-word IDs consistently by not quoting them in parenthesized form.
@konard
Copy link
Member Author

konard commented Dec 23, 2025

✅ Work Completed

Successfully merged latest changes from main branch and ensured all test coverage is consistent across all languages.

Changes Made:

  1. Merged main branch - Brought in Go and Java implementations from main
  2. Added multi-reference tests for Go - Created go/multi_ref_test.go with 12 comprehensive tests
  3. Added multi-reference tests for Java - Created java/.../MultiRefTest.java with 12 comprehensive tests
  4. Fixed Go formatter - Added helpers to prevent quoting multi-word IDs in parenthesized/indented contexts
  5. Fixed Java formatter - Added helper to prevent quoting multi-word IDs in parenthesized contexts
  6. Updated test expectation - Fixed Java test that expected quoted formatting for consistency

Test Coverage Summary:

All languages now have complete multi-reference test coverage:

  • JavaScript: 207 tests ✅
  • Python: 195 tests ✅
  • Rust: 39 tests ✅
  • C#: 191 tests ✅
  • Go: 90 tests ✅ (12 new multi-ref tests)
  • Java: 129 tests ✅ (12 new multi-ref tests)

CI Status:

All CI workflows passing:

  • ✅ JavaScript
  • ✅ Python
  • ✅ Rust
  • ✅ C#
  • ✅ Go (including formatting check)
  • ✅ Java (including spotless check)

The PR is now ready for review. All languages have consistent test coverage for the multi-reference feature, and all tests pass across all platforms.

@konard konard marked this pull request as ready for review December 23, 2025 20:15
@konard
Copy link
Member Author

konard commented Dec 23, 2025

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $5.985269 USD
  • Calculated by Anthropic: $3.961141 USD
  • Difference: $-2.024128 (-33.82%)
    📎 Log file uploaded as GitHub Gist (845KB)
    🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

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.

Support multiple references as single reference

2 participants