Simplify PartPosition - #162
Merged
Merged
Conversation
Contributor
Author
|
@ianjosephwilson for your consideration |
Contributor
|
@davepeck This does seem more elegant overall than what I'd call my brute force approach. There is one weird situation but the math works and the ambiguous case seems resolved. I'm not tied to it so you should just merge it. We can keep adjusting things. The one thing I do prefer is iterating over entire template with the 2-based index whenever that is needed but it seems like more and more of those loops are being replaced with more specialized solutions. Maybe we'll see what is in there when the smoke clears from all this. |
ianjosephwilson
pushed a commit
to ianjosephwilson/tdom
that referenced
this pull request
Aug 25, 2026
* Consider a different shape for PartPosition * Follow-on: simplify `abs_pos_to_part_pos()`. * I think I prefer this for readability
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.
Instead of
PartPosition.indexrepresenting an index into interleaved strings and interpolations, we now havePartPosition.s_indexwhich can only ever represent an index to a Template string. Anoffsetof0means "just before this string" (and therefore "just after the preceding interpolation, if any"); anoffsetoflen(the_string)means "just after this string" (and therefore "just before the following interpolation, if any").This simplifies a bunch of downstream code (see
extract()andabs_pos_to_part_pos()for example) and removes some of the awkwardness aroundoffsetif the position were previously an interpolation.