fix: panic when split float numbers in scientific notation

This commit is contained in:
roife 2024-03-06 22:50:29 +08:00
parent 52d8ae791d
commit 03420c330e

View file

@ -190,7 +190,7 @@ impl Builder<'_, '_> {
fn do_float_split(&mut self, has_pseudo_dot: bool) { fn do_float_split(&mut self, has_pseudo_dot: bool) {
let text = &self.lexed.range_text(self.pos..self.pos + 1); let text = &self.lexed.range_text(self.pos..self.pos + 1);
self.pos += 1;
match text.split_once('.') { match text.split_once('.') {
Some((left, right)) => { Some((left, right)) => {
assert!(!left.is_empty()); assert!(!left.is_empty());
@ -216,9 +216,27 @@ impl Builder<'_, '_> {
self.state = State::PendingExit; self.state = State::PendingExit;
} }
} }
None => unreachable!(), None => {
// illegal float literal which doesn't have dot in form (like 1e0)
// we should emit an error node here
(self.sink)(StrStep::Error { msg: "illegal float literal", pos: self.pos });
(self.sink)(StrStep::Enter { kind: SyntaxKind::ERROR });
(self.sink)(StrStep::Token { kind: SyntaxKind::FLOAT_NUMBER, text: text });
(self.sink)(StrStep::Exit);
// move up
(self.sink)(StrStep::Exit);
self.state = if has_pseudo_dot {
State::Normal
} else {
State::PendingExit
};
} }
} }
self.pos += 1;
}
} }
fn n_attached_trivias<'a>( fn n_attached_trivias<'a>(