red-knot: Use parse_unchecked to get all parse errors (#11725)

This commit is contained in:
Micha Reiser 2024-06-04 08:04:48 +02:00 committed by GitHub
parent 0c75548146
commit 64165bee43
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 58 additions and 125 deletions

View file

@ -64,7 +64,6 @@
//! [parsing]: https://en.wikipedia.org/wiki/Parsing
//! [lexer]: crate::lexer
use std::cell::OnceCell;
use std::ops::Deref;
pub use crate::error::{FStringErrorType, ParseError, ParseErrorType};
@ -308,7 +307,7 @@ impl Parsed<Mod> {
/// returns [`None`].
///
/// [`Some(Parsed<ModModule>)`]: Some
fn try_into_module(self) -> Option<Parsed<ModModule>> {
pub fn try_into_module(self) -> Option<Parsed<ModModule>> {
match self.syntax {
Mod::Module(module) => Some(Parsed {
syntax: module,
@ -327,7 +326,7 @@ impl Parsed<Mod> {
/// Otherwise, it returns [`None`].
///
/// [`Some(Parsed<ModExpression>)`]: Some
fn try_into_expression(self) -> Option<Parsed<ModExpression>> {
pub fn try_into_expression(self) -> Option<Parsed<ModExpression>> {
match self.syntax {
Mod::Module(_) => None,
Mod::Expression(expression) => Some(Parsed {
@ -370,14 +369,14 @@ pub struct Tokens {
raw: Vec<Token>,
/// Index of the first [`TokenKind::Unknown`] token or the length of the token vector.
first_unknown_or_len: OnceCell<usize>,
first_unknown_or_len: std::sync::OnceLock<usize>,
}
impl Tokens {
pub(crate) fn new(tokens: Vec<Token>) -> Tokens {
Tokens {
raw: tokens,
first_unknown_or_len: OnceCell::new(),
first_unknown_or_len: std::sync::OnceLock::new(),
}
}