Skip to content

Add Meta map to MapRef and ListRef for custom parser metadata#47

Merged
rjrodger merged 2 commits intomasterfrom
claude/add-mapref-listref-bo-72QxH
Mar 25, 2026
Merged

Add Meta map to MapRef and ListRef for custom parser metadata#47
rjrodger merged 2 commits intomasterfrom
claude/add-mapref-listref-bo-72QxH

Conversation

@rjrodger
Copy link
Copy Markdown
Collaborator

Summary

This change adds a Meta map field to both MapRef and ListRef types, allowing custom parsers to attach additional metadata during the parsing process. The Meta map is initialized early in the BO (before-open) phase so that custom rule actions can store and retrieve information throughout parsing.

Key Changes

  • Added Meta field to MapRef and ListRef: A map[string]any field that is initialized as an empty map when these types are created in the BO phase, enabling custom parsers to store metadata.

  • Updated grammar initialization: Modified the BO callbacks in Grammar() to create MapRef and ListRef instances with initialized Meta maps immediately, rather than wrapping plain maps/slices later in the BC phase.

  • Updated BC phase logic: Changed the BC callbacks to set Implicit and Child fields on already-created MapRef/ListRef instances instead of wrapping plain types.

  • Added helper functions: Introduced nodeListAppend(), nodeListVal(), and nodeListSetVal() to abstract list node operations, supporting both plain []any and ListRef types.

  • Updated utility functions: Enhanced deepMerge() and deepClone() to properly handle the new Meta field, including new cloneMeta() and mergeMeta() helper functions.

  • Updated equality checks: Modified comparison functions in both_ref_test.go, mapref_test.go, and listref_test.go to compare Meta maps, treating nil and empty maps as equal.

  • Added comprehensive tests: New test cases verify that Meta is properly initialized and accessible during the BO phase for both MapRef and ListRef.

Implementation Details

  • The Meta map is created as an empty (non-nil) map during BO phase initialization, allowing immediate use by custom parsers without nil checks.
  • The equality comparison logic treats nil and empty Meta maps as equivalent for backward compatibility.
  • Helper functions abstract the differences between plain list types and ListRef wrappers, reducing code duplication in grammar rules.

https://claude.ai/code/session_016aAAUHNZTZeCXsok8URXam

claude added 2 commits March 25, 2026 16:50
Move MapRef/ListRef creation from BC (before-close) to BO (before-open)
so they are available throughout parsing. Add Meta map[string]any field
to both types, initialized in BO, allowing custom parsers to attach
additional information during the parse phase.

- MapRef and ListRef structs gain a Meta field
- BO callbacks create the ref types early when enabled
- BC callbacks now update Implicit/Child on existing refs
- Add nodeListAppend/nodeListVal/nodeListSetVal helpers for ListRef
- Add cloneMeta/mergeMeta helpers for deep operations
- Update test comparisons to handle Meta field

https://claude.ai/code/session_016aAAUHNZTZeCXsok8URXam
Split on /\r?\n/ instead of '\n' so that carriage returns from Windows
line endings don't end up in the last column of each TSV row.

https://claude.ai/code/session_016aAAUHNZTZeCXsok8URXam
@rjrodger rjrodger merged commit a906b0e into master Mar 25, 2026
7 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