Skip to content

Commit b7b62b3

Browse files
committed
Added support for escaping \r\n\t
1 parent d6251ec commit b7b62b3

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

src/compiler/grammar/expr/tokenizer.rs

+23-5
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,30 @@ where
201201
let mut found_end = false;
202202

203203
for (_, &ch) in self.iter.by_ref() {
204-
if ch == stop_ch && last_ch != b'\\' {
205-
found_end = true;
206-
break;
207-
} else if ch != b'\\' || last_ch == b'\\' {
208-
buf.push(ch);
204+
if last_ch != b'\\' {
205+
if ch != stop_ch {
206+
buf.push(ch);
207+
} else {
208+
found_end = true;
209+
break;
210+
}
211+
} else {
212+
match ch {
213+
b'n' => {
214+
buf.push(b'\n');
215+
}
216+
b'r' => {
217+
buf.push(b'\r');
218+
}
219+
b't' => {
220+
buf.push(b'\t');
221+
}
222+
_ => {
223+
buf.push(ch);
224+
}
225+
}
209226
}
227+
210228
last_ch = ch;
211229
}
212230

src/compiler/lexer/tokenizer.rs

+10
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,16 @@ impl<'x> Iterator for Tokenizer<'x> {
496496
self.push_byte(ch);
497497
}
498498
_ => {
499+
let ch = if last_ch == b'\\' {
500+
match ch {
501+
b'n' => b'\n',
502+
b'r' => b'\r',
503+
b't' => b'\t',
504+
_ => ch,
505+
}
506+
} else {
507+
ch
508+
};
499509
if !str_type.has_other && ch != b'-' {
500510
str_type.has_other = true;
501511
self.state = State::QuotedString(str_type);

0 commit comments

Comments
 (0)