Skip to content

add SpannedString, a String that remembers its span - #232

Open
sunshowers wants to merge 1 commit into
jj-stack/parsewrapper-and-tokenstreamwrapper-don-t-work-with-internal-buffering-nznpslrrfrom
jj-stack/add-spannedstring-a-string-that-remembers-its-span-wotyuqpn
Open

add SpannedString, a String that remembers its span#232
sunshowers wants to merge 1 commit into
jj-stack/parsewrapper-and-tokenstreamwrapper-don-t-work-with-internal-buffering-nznpslrrfrom
jj-stack/add-spannedstring-a-string-that-remembers-its-span-wotyuqpn

Conversation

@sunshowers

Copy link
Copy Markdown
Contributor

In some situations it is useful to carry around span information along with a bare String. There isn't really a syn type that accepts either a LitStr or an Ident the way String does. Introduce SpannedString, which acts as that type and can be used as ParseWrapper<SpannedString>.

One alternative to this is to implement Deserialize on SpannedString directly, but error handling for that would require a third side-channel thread local on top of the two we already have. This is much more straightforward implementation-wise. (It also has a pleasing cripness -- it's easier to explain.)

In some situations it is useful to carry around span information along with a bare `String`. There isn't really a syn type that accepts either a `LitStr` or an `Ident` the way `String` does. Introduce `SpannedString`, which acts as that type and can be used as `ParseWrapper<SpannedString>`.

One alternative to this is to implement `Deserialize` on `SpannedString` directly, but error handling for that would require a third side-channel thread local on top of the two we already have. This is much more straightforward implementation-wise. (It also has a pleasing cripness -- it's easier to explain.)
@sunshowers
sunshowers force-pushed the jj-stack/add-spannedstring-a-string-that-remembers-its-span-wotyuqpn branch from 4147f4f to 831c294 Compare September 2, 2026 09:01
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.

1 participant