Add Meta map to MapRef and ListRef for custom parser metadata#47
Merged
Add Meta map to MapRef and ListRef for custom parser metadata#47
Conversation
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
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
This change adds a
Metamap field to bothMapRefandListReftypes, allowing custom parsers to attach additional metadata during the parsing process. TheMetamap is initialized early in the BO (before-open) phase so that custom rule actions can store and retrieve information throughout parsing.Key Changes
Added
Metafield toMapRefandListRef: Amap[string]anyfield 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 createMapRefandListRefinstances with initializedMetamaps immediately, rather than wrapping plain maps/slices later in the BC phase.Updated BC phase logic: Changed the BC callbacks to set
ImplicitandChildfields on already-createdMapRef/ListRefinstances instead of wrapping plain types.Added helper functions: Introduced
nodeListAppend(),nodeListVal(), andnodeListSetVal()to abstract list node operations, supporting both plain[]anyandListReftypes.Updated utility functions: Enhanced
deepMerge()anddeepClone()to properly handle the newMetafield, including newcloneMeta()andmergeMeta()helper functions.Updated equality checks: Modified comparison functions in
both_ref_test.go,mapref_test.go, andlistref_test.goto compareMetamaps, treating nil and empty maps as equal.Added comprehensive tests: New test cases verify that
Metais properly initialized and accessible during the BO phase for bothMapRefandListRef.Implementation Details
Metamap is created as an empty (non-nil) map during BO phase initialization, allowing immediate use by custom parsers without nil checks.Metamaps as equivalent for backward compatibility.ListRefwrappers, reducing code duplication in grammar rules.https://claude.ai/code/session_016aAAUHNZTZeCXsok8URXam