@@ -121,11 +121,67 @@ impl Lexer {
121121 if self . peek ( ) == '\n' {
122122 self . line += 1 ;
123123 }
124- self . advance ( ) ;
124+ // check for escape sequence \` \n \\ \t \r \a \b \f \v \e \Xhh \0ooo \Uhhhhhhhh
125+ if self . peek ( ) == '\\' {
126+ self . source . remove ( self . current ) ;
127+ if self . peek ( ) == '`' {
128+ self . advance ( ) ;
129+ } else if self . peek ( ) == 'n' {
130+ self . source . remove ( self . current ) ;
131+ self . source . insert ( self . current , '\n' ) ;
132+ self . advance ( ) ;
133+ self . line += 1 ;
134+ } else if self . peek ( ) == '\\' {
135+ self . source . remove ( self . current ) ;
136+ self . source . insert ( self . current , '\\' ) ;
137+ self . advance ( ) ;
138+ } else if self . peek ( ) == 't' {
139+ self . source . remove ( self . current ) ;
140+ self . source . insert ( self . current , '\t' ) ;
141+ self . advance ( ) ;
142+ } else if self . peek ( ) == 'r' {
143+ self . source . remove ( self . current ) ;
144+ self . source . insert ( self . current , '\r' ) ;
145+ self . advance ( ) ;
146+ } else if self . peek ( ) == 'a' {
147+ self . source . remove ( self . current ) ;
148+ self . source . insert ( self . current , '\x07' ) ;
149+ self . advance ( ) ;
150+ } else if self . peek ( ) == 'b' {
151+ self . source . remove ( self . current ) ;
152+ self . source . insert ( self . current , '\x08' ) ;
153+ self . advance ( ) ;
154+ } else if self . peek ( ) == 'f' {
155+ self . source . remove ( self . current ) ;
156+ self . source . insert ( self . current , '\x0C' ) ;
157+ self . advance ( ) ;
158+ } else if self . peek ( ) == 'v' {
159+ self . source . remove ( self . current ) ;
160+ self . source . insert ( self . current , '\x0b' ) ;
161+ self . advance ( ) ;
162+ } else if self . peek ( ) == 'e' {
163+ self . source . remove ( self . current ) ;
164+ self . source . insert ( self . current , '\x1b' ) ;
165+ self . advance ( ) ;
166+ } else if self . peek ( ) == 'X' {
167+ todo ! ( ) ;
168+ } else if self . peek ( ) == 'O' {
169+ todo ! ( ) ;
170+ } else if self . peek ( ) == 'U' {
171+ todo ! ( ) ;
172+ } else {
173+ error:: error ( self . line , format ! ( "unknown escape sequence {}" , self . peek( ) ) ) ;
174+ }
175+ } else {
176+ self . advance ( ) ;
177+ }
178+
179+ // self.advance();
125180 }
126181 if self . is_at_end ( ) {
127182 error:: error ( self . line , "unterminated string" ) ;
128183 }
184+ // println!("{}", self.get_text());
129185 self . advance ( ) ;
130186 self . start += 1 ;
131187 self . current -= 1 ;
0 commit comments