parser: Note intent to switch to a Pratt parser

This commit is contained in:
John 2024-02-27 23:35:41 -06:00
parent ca51a35f5c
commit 67bb3d4ae3

View File

@ -326,7 +326,7 @@ const PARENS: (Type, Type) = (Type::LParen, Type::RParen);
const fn delim<'t, T>( const fn delim<'t, T>(
f: impl Fn(&mut Parser<'t>) -> PResult<T>, f: impl Fn(&mut Parser<'t>) -> PResult<T>,
delim: (Type, Type), delim: (Type, Type),
while_parsing: Parsing, while_parsing: Parsing,
) -> impl Fn(&mut Parser<'t>) -> PResult<T> { ) -> impl Fn(&mut Parser<'t>) -> PResult<T> {
move |parser| { move |parser| {
parser.match_type(delim.0, while_parsing)?; parser.match_type(delim.0, while_parsing)?;
@ -337,13 +337,13 @@ const fn delim<'t, T>(
} }
/// Parses constructions of the form `(f sep ~until)*` /// Parses constructions of the form `(f sep ~until)*`
/// ///
/// where `~until` is a negative lookahead assertion /// where `~until` is a negative lookahead assertion
const fn sep<'t, T>( const fn sep<'t, T>(
f: impl Fn(&mut Parser<'t>) -> PResult<T>, f: impl Fn(&mut Parser<'t>) -> PResult<T>,
sep: Type, sep: Type,
until: Type, until: Type,
while_parsing: Parsing, while_parsing: Parsing,
) -> impl Fn(&mut Parser<'t>) -> PResult<Vec<T>> { ) -> impl Fn(&mut Parser<'t>) -> PResult<Vec<T>> {
move |parser| { move |parser| {
let mut args = vec![]; let mut args = vec![];
@ -359,13 +359,13 @@ const fn sep<'t, T>(
} }
/// Parses constructions of the form `(f ~until)*` /// Parses constructions of the form `(f ~until)*`
/// ///
/// where `~until` is a negative lookahead assertion /// where `~until` is a negative lookahead assertion
#[allow(dead_code)] #[allow(dead_code)]
const fn rep<'t, T>( const fn rep<'t, T>(
f: impl Fn(&mut Parser<'t>) -> PResult<T>, f: impl Fn(&mut Parser<'t>) -> PResult<T>,
until: Type, until: Type,
while_parsing: Parsing, while_parsing: Parsing,
) -> impl Fn(&mut Parser<'t>) -> PResult<Vec<T>> { ) -> impl Fn(&mut Parser<'t>) -> PResult<Vec<T>> {
move |parser| { move |parser| {
let mut out = vec![]; let mut out = vec![];
@ -380,16 +380,16 @@ const fn rep<'t, T>(
macro item_like() { macro item_like() {
Type::Hash Type::Hash
| Type::Keyword( | Type::Keyword(
Keyword::Pub Keyword::Pub
| Keyword::Type | Keyword::Type
| Keyword::Const | Keyword::Const
| Keyword::Static | Keyword::Static
| Keyword::Mod | Keyword::Mod
| Keyword::Fn | Keyword::Fn
| Keyword::Struct | Keyword::Struct
| Keyword::Enum | Keyword::Enum
| Keyword::Impl, | Keyword::Impl,
) )
} }
/// Top level parsing /// Top level parsing
@ -897,6 +897,7 @@ impl<'t> Parser<'t> {
}; };
Ok(Assign { head, op, tail: self.expr_from(Self::exprkind_assign)?.into() }.into()) Ok(Assign { head, op, tail: self.expr_from(Self::exprkind_assign)?.into() }.into())
} }
// TODO: use a pratt parser for binary expressions, to simplify this
binary! { binary! {
exprkind_compare {exprkind_range, compare_op} exprkind_compare {exprkind_range, compare_op}
exprkind_range {exprkind_logic, range_op} exprkind_range {exprkind_logic, range_op}