tree-sitter / tree-sitter-python

Python grammar for tree-sitter
MIT License
360 stars 132 forks source link

Clean up string implementation #192

Closed tausbn closed 1 year ago

tausbn commented 1 year ago

Does a few things:

Basically, with the old setup there was no convenient way to extract the string content of a string node. Its source text would encompass also the interpolations contained therein.

With what's contained in this change, the source text of the string_content node is now exactly the string content for that part of the string.

Note that this required the addition of a few instances of token.immediate. Without this, something like

f"foo   {0}"

(that is, _string_content followed by an interpolation) would get the whitespace before the interpolation gobbled up as extras. By requiring an immediate token, we ensure that the whitespaces ends up with the preceding string content, as desired.