feat: implement string escape sequence parsing in lexer and add test coverage

Add escape sequence handling to the string literal lexer in compiler.c, translating
common escape sequences (\", \\, \n) into their literal character equivalents during
tokenization. Introduce a fixed-size buffer (MAX_STRING 1024) in the Parser struct to
accumulate the unescaped string content, along with a helper function addStringChar()
to append characters. The readString() function now loops over input characters,
breaking on an unescaped double quote, and processing backslash-prefixed escapes via
a switch statement. Remove the previous TODO placeholder comment and the elapsed time
computation simplification in benchmark/fib.lua. Add a new test file
test/string_escapes.wren that verifies the three supported escape sequences, and
remove the now-obsolete TODO about escapes from test/string_literals.wren.
This commit is contained in:
Bob Nystrom
2013-11-24 05:00:47 +00:00
parent 56f0f1639b
commit cc55fd2a57
4 changed files with 52 additions and 16 deletions
+8
View File
@@ -0,0 +1,8 @@
// Escape characters.
io.write("\"") // expect: "
io.write("\\") // expect: \
io.write("(\n)") // expect: (
// expect: )
// TODO(bob): Non-printing escapes like \t.
// TODO(bob): Unicode escape sequences.
-2
View File
@@ -1,4 +1,2 @@
io.write("".count) // expect: 0
io.write("a string") // expect: a string
// TODO(bob): Escapes.