Compute and store position of TNodes during parsing for improved error messages. - #155
Open
ianjosephwilson wants to merge 7 commits into
Open
Conversation
Contributor
Author
|
@davepeck Thanks for merging the last part. This part is ready to review. |
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.
Design Notes
Goals
Translation
(template_part_index, offset_in_template_part) = translate(parser_line_number, offset_in_parser_line)The underlying
HTMLParserprovides a line position viagetpos()that is relative to the entire template flattened into a continuous string with interpolations replaced with placeholders. That line position is translated to a "part" position in theTemplateusing unified indexing (combined strings and interpolations). This part position applies to all templates with the same tuple of strings.Note that the purpose of the "unified indexing" (all this
2*len(t.strings) - 1orindex // 2madness) is that it allows for exact storage of the part location and also has less complicated usage and more direct iteration. This is especially true when starting at a part and ending at a part compared to storing and trying to iterate from as_indexor ani_index.Source Position and Info
The translation from line position to part position is performed for all nodes during parsing and then stored with that tnode. For tags (elements and components) more info is wanted. This extra source info is stored in a lookup to avoid overloading the cache and core apis. A new
TTreestructure is used to store theroot: TNodeand the lookup packed assinfos. This keeps the coreTNodesubclasses simple as they only have one extra field:source_pos: PartPosition. This assumes that if a node needs extra source info then its source position is unique within that template which seems sensible for now.Next Steps
Assuming we don't hit any brick wall blockers we'd keep going along until we get to semi-functioning exception handling:
TemplateRefslicingSourceReaderand printable repr ofTemplates