Skip to content

Add source reader and template repr. - #163

Merged
davepeck merged 5 commits into
t-strings:mainfrom
ianjosephwilson:ian/prep_for_custom_errors_part5
Aug 25, 2026
Merged

Add source reader and template repr.#163
davepeck merged 5 commits into
t-strings:mainfrom
ianjosephwilson:ian/prep_for_custom_errors_part5

Conversation

@ianjosephwilson

@ianjosephwilson ianjosephwilson commented Aug 24, 2026

Copy link
Copy Markdown
Contributor
  • Adds SourceReader class.
    • Created when an exception occurs to read back the source for error messages.
  • Adds MutableLinePosition class.
    • Accumulates the line position (w/ newlines) through interpolation expressions before showing the line/offset in error messages.
  • Adds interpolation_repr(), template_repr_iter() and template_repr() functions.
    • Utility functions for helping SourceReader.

This code is sort of disconnected until we add in the actual exception/error handling.

I was able to sub out the slicing concept for the TemplateSpan().extract() pretty easily but other parts might change ref for span but I'm not sure until we add the next chunk.

@ianjosephwilson

Copy link
Copy Markdown
Contributor Author

@davepeck Almost to the parser exceptions. It is amazing how much code and "shoehorning" all these details take.

@davepeck davepeck left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks @ianjosephwilson!

Some comments here to consider but overall a nice narrow slice.

PS: I merged in #162 and updated the tests in this PR to use the new coordinates.

Comment thread tdom/source.py Outdated
Comment thread tdom/source.py
@davepeck

Copy link
Copy Markdown
Contributor

@ianjosephwilson Looks good to me. LMK if you're ready for a merge. Thanks!

@ianjosephwilson

Copy link
Copy Markdown
Contributor Author

@davepeck Should be ready to merge. I'll go back over the coverage at the end because some of these small methods we might just remove.

@davepeck
davepeck merged commit c8cf6fd into t-strings:main Aug 25, 2026
1 check passed
@ianjosephwilson
ianjosephwilson deleted the ian/prep_for_custom_errors_part5 branch August 25, 2026 04:27
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