move suffixed parsing into chomp_identifier_chain

This commit is contained in:
Luke Boswell 2024-03-22 19:19:59 +11:00
parent d988eadbb1
commit 370ac1e6b8
No known key found for this signature in database
GPG key ID: F6DB3C9DB47377B0
4 changed files with 43 additions and 17 deletions

View file

@ -1829,18 +1829,6 @@ fn parse_expr_end<'a>(
}
}
}
.map(|(progress, expr, state)| {
// If the next thing after the expression is a `!`, then it's Suffixed
if state.bytes().starts_with(b"!") {
(
progress,
Expr::Suffixed(arena.alloc(expr)),
state.advance(1),
)
} else {
(progress, expr, state)
}
})
}
pub fn loc_expr<'a>(accept_multi_backpassing: bool) -> impl Parser<'a, Loc<Expr<'a>>, EExpr<'a>> {
@ -2510,12 +2498,19 @@ fn ident_to_expr<'a>(arena: &'a Bump, src: Ident<'a>) -> Expr<'a> {
match src {
Ident::Tag(string) => Expr::Tag(string),
Ident::OpaqueRef(string) => Expr::OpaqueRef(string),
Ident::Access { module_name, parts } => {
Ident::Access {
module_name,
parts,
suffixed,
} => {
let mut iter = parts.iter();
// The first value in the iterator is the variable name,
// e.g. `foo` in `foo.bar.baz`
let mut answer = match iter.next() {
Some(Accessor::RecordField(ident)) if suffixed => {
Expr::Suffixed(arena.alloc(Expr::Var { module_name, ident }))
}
Some(Accessor::RecordField(ident)) => Expr::Var { module_name, ident },
Some(Accessor::TupleIndex(_)) => {
// TODO: make this state impossible to represent in Ident::Access,