Skip to content

Refactor multisource plugin to use directive framework#6

Merged
rjrodger merged 1 commit intomainfrom
claude/align-go-jsonic-ts-e5LHi
Mar 19, 2026
Merged

Refactor multisource plugin to use directive framework#6
rjrodger merged 1 commit intomainfrom
claude/align-go-jsonic-ts-e5LHi

Conversation

@rjrodger
Copy link
Contributor

Summary

Refactored the multisource plugin to leverage the new directive framework instead of implementing custom lexer matchers and token handling. This simplifies the codebase and improves maintainability by delegating parsing logic to the directive system.

Key Changes

  • Removed custom lexer implementation: Eliminated the lexMode state machine, custom token matchers (msrcpath), and manual path parsing logic that handled quoted and unquoted paths
  • Adopted directive framework: Replaced custom rule extensions with a DirectiveOptions configuration that defines the multisource directive behavior declaratively
  • Simplified path resolution: Extracted resolveSource() into a standalone function that's called from the directive's action handler
  • Enhanced rule handling: Implemented custom rule modifications through the directive's Custom callback to handle special cases like top-level references and map merging
  • Added comprehensive tests: New test cases for path plugin integration, map merging with @path syntax, and top-level reference resolution

Implementation Details

  • The directive framework handles tokenization and rule matching, eliminating ~150 lines of manual lexer code
  • Map merging behavior (when @path appears in pair position) is now handled through parent rule inspection in the action handler
  • Special handling for top-level @path references uses rule depth and custom flags to distinguish between value and map contexts
  • The Custom callback modifies the val, map, and pair rules to inject directive-specific alternatives at appropriate positions

https://claude.ai/code/session_01UCcfE3sNcpkMr5eYdoR12u

Align the Go implementation with the TypeScript version by using the
directive package instead of manually implementing token registration,
custom matchers, and rule modifications. Add jsonic/path/go as a test
dependency for Path plugin compatibility testing.

https://claude.ai/code/session_01UCcfE3sNcpkMr5eYdoR12u
@rjrodger rjrodger merged commit 5b0609b into main Mar 19, 2026
8 checks passed
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