|
@@ -32,9 +32,35 @@ class Lexer
|
32
|
32
|
number = source.match(/^\d+(\.\d+)?/)[0]
|
33
|
33
|
@position += number.size
|
34
|
34
|
Token.new(TokenKinds::NUMBER, number.to_f)
|
35
|
|
- elsif source.match(/^"(.*)"/)
|
36
|
|
- string = source.match(/^"([^"]*)"/)[1]
|
37
|
|
- @position += (string.size + 2)
|
|
35
|
+ elsif source[0] == '"'
|
|
36
|
+ @position += 1
|
|
37
|
+ string = String.new
|
|
38
|
+
|
|
39
|
+ while !at_end && @source[@position] != '"'
|
|
40
|
+ if @source[@position] == '\\'
|
|
41
|
+ if @source[@position + 1] == '"'
|
|
42
|
+ @position += 1
|
|
43
|
+ elsif @source[@position + 1] == 'n'
|
|
44
|
+ @position += 2
|
|
45
|
+ string << "\n"
|
|
46
|
+ next
|
|
47
|
+ elsif @source[@position + 1] == 't'
|
|
48
|
+ @position += 2
|
|
49
|
+ string << "\t"
|
|
50
|
+ next
|
|
51
|
+ end
|
|
52
|
+ end
|
|
53
|
+
|
|
54
|
+ string << @source[@position]
|
|
55
|
+ @position += 1
|
|
56
|
+ end
|
|
57
|
+
|
|
58
|
+ if at_end
|
|
59
|
+ raise 'Unterminated string'
|
|
60
|
+ elsif @source[@position] == '"'
|
|
61
|
+ @position += 1
|
|
62
|
+ end
|
|
63
|
+
|
38
|
64
|
Token.new(TokenKinds::STRING, string)
|
39
|
65
|
elsif source.match(/^\:([a-z][a-zA-Z0-9_]*)/)
|
40
|
66
|
atom = source.match(/^\:([a-z][a-zA-Z0-9_]*)/)[1]
|