3 ms·
Thanks! I relayed this to Yuki and we'll make sure to fix the issues. > You can include the start delimiter in the string: At first I had no clue why we thoug
by purplesyringa 2mo ago
Thanks! I relayed this to Yuki and we'll make sure to fix the issues.
> You can include the start delimiter in the string:
At first I had no clue why we thought that didn't work, in fact, my prototype had a fun commit specifically about adding opening brackets:
-while b"]" + b"=" * level + b"]" in obj:
+# Somewhat surprisingly, Lua forbids even opening brackets inside brackets.
+while b"[" + b"=" * level + b"[" in obj or b"]" + b"=" * level + b"]" in obj:
...but I think I've figured out the problem. It seems like Lua 5.1 specifically forbids level-0 opening brackets within level-0 strings:
> print [[ a [[b c ]]
stdin:1: nesting of [[...]] is deprecated near '['
...and Cobalt implements this check for compatibility. So that's another edge case to handle, I guess.
> Another note that this doesn't cover is ending with a part of the ending terminator.
That's very useful to know, thanks!
> So you can't just use the bracketed form to encode arbitrary byte sequences, [...] if you care about the exact representation of line breaks
That's right, and the post actually covers how we resolved that closer to the end. In a nutshell, we replace CRs with an escape character, and then use a bitset to denote which symbols are supposed to be CRs and which ones are literal characters. It's not quite a string literal per se, but it's rather cheap in runtime and minimizes file size.