syntax: Fix complexity of string parsing. Closes #16624.
This commit is contained in:
parent
f92015f71b
commit
bc7a85de29
2 changed files with 31 additions and 5 deletions
|
@ -412,14 +412,21 @@ pub fn str_lit(lit: &str) -> String {
|
||||||
loop {
|
loop {
|
||||||
match chars.next() {
|
match chars.next() {
|
||||||
Some((i, c)) => {
|
Some((i, c)) => {
|
||||||
let em = error(i);
|
|
||||||
match c {
|
match c {
|
||||||
'\\' => {
|
'\\' => {
|
||||||
if chars.peek().expect(em.as_slice()).val1() == '\n' {
|
let ch = chars.peek().unwrap_or_else(|| {
|
||||||
|
fail!("{}", error(i).as_slice())
|
||||||
|
}).val1();
|
||||||
|
|
||||||
|
if ch == '\n' {
|
||||||
eat(&mut chars);
|
eat(&mut chars);
|
||||||
} else if chars.peek().expect(em.as_slice()).val1() == '\r' {
|
} else if ch == '\r' {
|
||||||
chars.next();
|
chars.next();
|
||||||
if chars.peek().expect(em.as_slice()).val1() != '\n' {
|
let ch = chars.peek().unwrap_or_else(|| {
|
||||||
|
fail!("{}", error(i).as_slice())
|
||||||
|
}).val1();
|
||||||
|
|
||||||
|
if ch != '\n' {
|
||||||
fail!("lexer accepted bare CR");
|
fail!("lexer accepted bare CR");
|
||||||
}
|
}
|
||||||
eat(&mut chars);
|
eat(&mut chars);
|
||||||
|
@ -433,7 +440,11 @@ pub fn str_lit(lit: &str) -> String {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'\r' => {
|
'\r' => {
|
||||||
if chars.peek().expect(em.as_slice()).val1() != '\n' {
|
let ch = chars.peek().unwrap_or_else(|| {
|
||||||
|
fail!("{}", error(i).as_slice())
|
||||||
|
}).val1();
|
||||||
|
|
||||||
|
if ch != '\n' {
|
||||||
fail!("lexer accepted bare CR");
|
fail!("lexer accepted bare CR");
|
||||||
}
|
}
|
||||||
chars.next();
|
chars.next();
|
||||||
|
|
15
src/test/run-pass/slowparse-string.rs
Normal file
15
src/test/run-pass/slowparse-string.rs
Normal file
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue