remove unwraps from escape parsing
these could not cause panics, but it is nice to reduce the number of unwraps either way
This commit is contained in:
parent
6849cd578f
commit
f2d1a82f34
@ -95,16 +95,18 @@ impl<'a> Parser<'a> {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
value *= 16;
|
value *= 16;
|
||||||
span = span.merge(next.pos());
|
span = span.merge(next.pos);
|
||||||
value += as_hex(self.toks.next().unwrap().kind)
|
value += as_hex(next.kind);
|
||||||
|
self.toks.next();
|
||||||
}
|
}
|
||||||
if self.toks.peek().is_some() && self.toks.peek().unwrap().kind.is_whitespace() {
|
if matches!(self.toks.peek(), Some(Token { kind: ' ', .. }) | Some(Token { kind: '\n', .. }) | Some(Token { kind: '\t', .. }))
|
||||||
|
{
|
||||||
self.toks.next();
|
self.toks.next();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let next = self.toks.next().unwrap();
|
span = span.merge(first.pos);
|
||||||
span = span.merge(next.pos());
|
value = first.kind as u32;
|
||||||
value = next.kind as u32;
|
self.toks.next();
|
||||||
}
|
}
|
||||||
|
|
||||||
let c = std::char::from_u32(value).ok_or(("Invalid escape sequence.", span))?;
|
let c = std::char::from_u32(value).ok_or(("Invalid escape sequence.", span))?;
|
||||||
|
@ -372,7 +372,8 @@ impl<'a> Parser<'a> {
|
|||||||
span = span.merge(next.pos);
|
span = span.merge(next.pos);
|
||||||
self.toks.peek_forward(1);
|
self.toks.peek_forward(1);
|
||||||
}
|
}
|
||||||
if self.toks.peek().is_some() && self.toks.peek().unwrap().kind.is_whitespace() {
|
if matches!(self.toks.peek(), Some(Token { kind: ' ', .. }) | Some(Token { kind: '\n', .. }) | Some(Token { kind: '\t', .. }))
|
||||||
|
{
|
||||||
self.toks.peek_forward(1);
|
self.toks.peek_forward(1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user