fix: wire up with_meta to emit __start_line__/__end_line__#2
Open
bejaratommy wants to merge 1 commit into
Open
fix: wire up with_meta to emit __start_line__/__end_line__#2bejaratommy wants to merge 1 commit into
bejaratommy wants to merge 1 commit into
Conversation
The with_meta serialization option (and the --with-meta CLI flag) was accepted but had no effect since the v8 overhaul: no serialize path ever read options.with_meta, so output never contained line metadata. Emit __start_line__/__end_line__ keys on each body dict (document body and block bodies) from the positions Lark already propagates, matching the option's documented behavior. Only active when with_meta is set, so default output is unchanged. Fixes amplify-education#291
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
The
with_metaserialization option — and thehcl2tojson --with-metaCLI flag — has been a no-op since the v8 architecture overhaul. The flag is accepted and documented ("Add__start_line__and__end_line__metadata to each block/attribute"), but noserialize()path ever readsoptions.with_meta, so the output never contains line metadata.Change
Lark already runs with
propagate_positions=Trueand the transformer attaches a populatedMetato every rule, so the line numbers are available — they were just never written out.BodyRule.serializenow emits__start_line__/__end_line__on each body dict (the document body and each block body) whenwith_metais set, sourced from the rule's propagatedMeta. This is a single, uniform injection point that covers both the top-level-attribute case above and block bodies. The keys are added as constants inhcl2/const.py.The metadata is only emitted when
with_meta=True(defaultFalse), so default output is unchanged. The empty-Metacase (trees built without positions, e.g. via the deserializer) is guarded, so nothing is emitted there.Tests
Added
test/unit/test_api.pycases asserting the metadata appears withwith_meta=True(top-level attribute and block body) and is absent by default.Fixes amplify-education#291