Skip to content

Comments

Support Infinite hash raw strings#41

Open
RedCMD wants to merge 5 commits intojtbandes:mainfrom
RedCMD:infiniteHashRawStrings
Open

Support Infinite hash raw strings#41
RedCMD wants to merge 5 commits intojtbandes:mainfrom
RedCMD:infiniteHashRawStrings

Conversation

@RedCMD
Copy link
Contributor

@RedCMD RedCMD commented Oct 6, 2025

@RedCMD
Copy link
Contributor Author

RedCMD commented Oct 6, 2025

I noticed your comment
Allow \("""...""") to appear inside a block string
I assume this won't apply for raw strings? #"""\#(#"""..."""#)"""#
because the starting and ending delimiters are different?

@jtbandes
Copy link
Owner

jtbandes commented Oct 7, 2025

I assume this won't apply for raw strings? #"""\#(#"""..."""#)"""# because the starting and ending delimiters are different?

I'm not quite sure I understand which scenario you are asking about, but I believe all the nesting options are valid. In your example, some of the " are part of the string since it's not actually a multi-line string.

https://godbolt.org/z/W71MEWcaa

I think the point of the comment/rule you pointed out is: usually [something]""" is not allowed for multi-line strings (the closing delimiter should be on its own line) however, actually \###(""" is okay since that starts a string interpolation.

Honestly, I'm not sure if keeping the invalid.illegal rules is really worth it 🤷 It was a convention I inherited from other TextMate grammars, but generally highlighting valid code seems much more important than highlighting invalid code.

@RedCMD
Copy link
Contributor Author

RedCMD commented Feb 13, 2026

Refactored it again
supports infinite hash raw strings
added more tests
added a Markdown test example
made single-line strings end at eol $ and mark the last char as invalid invalid.illegal.returns-not-allowed.swift

I'm pretty happy with it now
image
image


only issue I know is that if theres an invalid escape (thats too big)
the grammar will then 'forget' how many hashes # it was tracking and just assume the next escape is correct
so it thinks \#n is a valid escape here (because \###a is a too big invalid escape)

##"""
\###a
\#n
"""##
image

could add a hardcoded #""" ... """# rule so that single # raw strings always work 100% of the time


I revisited this after coming from here:

@RedCMD RedCMD marked this pull request as ready for review February 13, 2026 09:03
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.

Raw string literals (more than one #, grammar limitations prevent us from supporting escapes)

2 participants