feat: rename IO.write to IO.print and add Unicode escape support in strings

Rename the IO.write method to IO.print, which now prints without a trailing newline, and add a new IO.print method that appends a newline after output. Update all benchmark, example, and test files to use IO.print instead of IO.write. Additionally, implement Unicode escape sequence parsing in the compiler's string tokenizer, supporting \uXXXX and \u{...} syntax with proper UTF-8 encoding for code points up to U+10FFFF.
This commit is contained in:
Bob Nystrom
2014-01-05 20:27:12 +00:00
parent e23e0ce6a3
commit c72db7d594
159 changed files with 1690 additions and 1599 deletions
+13 -13
View File
@@ -1,28 +1,28 @@
// Evaluate the 'then' expression if the condition is true.
if (true) IO.write("good") // expect: good
if (false) IO.write("bad")
if (true) IO.print("good") // expect: good
if (false) IO.print("bad")
// Evaluate the 'else' expression if the condition is false.
if (true) IO.write("good") else IO.write("bad") // expect: good
if (false) IO.write("bad") else IO.write("good") // expect: good
if (true) IO.print("good") else IO.print("bad") // expect: good
if (false) IO.print("bad") else IO.print("good") // expect: good
// Allow blocks for branches.
if (true) { IO.write("block") } // expect: block
if (false) null else { IO.write("block") } // expect: block
if (true) { IO.print("block") } // expect: block
if (false) null else { IO.print("block") } // expect: block
// Assignment in if condition.
var a = false
if (a = true) IO.write(a) // expect: true
if (a = true) IO.print(a) // expect: true
// Newline after "if".
if
(true) IO.write("good") // expect: good
(true) IO.print("good") // expect: good
// Newline after "else".
if (false) IO.write("bad") else
IO.write("good") // expect: good
if (false) IO.print("bad") else
IO.print("good") // expect: good
// Only false is falsy.
if (0) IO.write(0) // expect: 0
if (null) IO.write(null) // expect: null
if ("") IO.write("empty") // expect: empty
if (0) IO.print(0) // expect: 0
if (null) IO.print(null) // expect: null
if ("") IO.print("empty") // expect: empty