i have wasted several hours now on this trivial bug …
i hope someone (marijn?) can help me fix this in a few minutes
(how can i “buy you a coffee”?)
i want to parse “string blocks” in the nix language
''
stringcontent
''
i have based my parser on the javascript parser for template strings
the parser works as long as there is a newline at the end of string
when i parse
''stringcontent''
then the stringcontent
is missing in the parse tree
reproduce
git clone https://github.com/milahu/lezer-nix --depth 1 \
--branch repro-bug-stringblock-missing-end-of-string
cd lezer-nix
npm install
npm run build
npm run test # fail: string block with interpolation single line
node test/manual-test.js "$(printf "''x\n''")" # pass
node test/manual-test.js "$(printf "''x''")" # fail
debug output
node test/manual-test.js "$(printf "''x\n''")"
i = 0 + next = 120 = "x" + afterQuote = false + afterDollar = false
i = 1 + next = 10 = "\n" + afterQuote = false + afterDollar = false
acceptToken(StringBlockContent) from newline
break 73
i = 0 + next = 39 = "'" + afterQuote = false + afterDollar = false
found singlequote 1
i = 1 + next = 39 = "'" + afterQuote = true + afterDollar = false
found singlequote 2
acceptToken(stringBlockEnd) with empty string
break 50
Nix
StringBlock "''x\n''"
StringBlockContent "x\n"
node test/manual-test.js "$(printf "''x''")"
i = 0 + next = 120 = "x" + afterQuote = false + afterDollar = false
i = 1 + next = 39 = "'" + afterQuote = false + afterDollar = false
found singlequote 1
i = 2 + next = 39 = "'" + afterQuote = true + afterDollar = false
found singlequote 2
acceptToken(StringBlockContent, -2)
acceptToken(stringBlockEnd)
break 50
Nix
StringBlock ''x''
in the second case, the StringBlockContent
is missing