remove suffixed from Ident::Access and cleanup

This commit is contained in:
Luke Boswell 2024-04-28 08:41:39 +10:00
parent 20f277c132
commit 74e531b994
No known key found for this signature in database
GPG key ID: F6DB3C9DB47377B0
4 changed files with 4 additions and 98 deletions

View file

@ -1169,7 +1169,7 @@ pub fn canonicalize_expr<'a>(
output, output,
) )
} }
ast::Expr::TaskAwaitBang(..) => todo!("canonicalize_expr on TaskAwaitBang"), ast::Expr::TaskAwaitBang(..) => internal_error!("a Expr::TaskAwaitBang expression was not completed removed in desugar_value_def_suffixed"),
ast::Expr::Tag(tag) => { ast::Expr::Tag(tag) => {
let variant_var = var_store.fresh(); let variant_var = var_store.fresh();
let ext_var = var_store.fresh(); let ext_var = var_store.fresh();

View file

@ -254,11 +254,6 @@ fn parse_ident_seq<'a>(
let expr = apply_expr_access_chain(arena, expr, suffixes); let expr = apply_expr_access_chain(arena, expr, suffixes);
Ok((MadeProgress, Loc::at(loc_ident.region, expr), state)) Ok((MadeProgress, Loc::at(loc_ident.region, expr), state))
} }
// loc!(map_with_arena!(
// assign_or_destructure_identifier(),
// ident_to_expr
// ))
// }
fn underscore_expression<'a>() -> impl Parser<'a, Expr<'a>, EExpr<'a>> { fn underscore_expression<'a>() -> impl Parser<'a, Expr<'a>, EExpr<'a>> {
move |arena: &'a Bump, state: State<'a>, min_indent: u32| { move |arena: &'a Bump, state: State<'a>, min_indent: u32| {
@ -2816,11 +2811,7 @@ fn ident_to_expr<'a>(arena: &'a Bump, src: Ident<'a>) -> Expr<'a> {
match src { match src {
Ident::Tag(string) => Expr::Tag(string), Ident::Tag(string) => Expr::Tag(string),
Ident::OpaqueRef(string) => Expr::OpaqueRef(string), Ident::OpaqueRef(string) => Expr::OpaqueRef(string),
Ident::Access { Ident::Access { module_name, parts } => {
module_name,
parts,
suffixed: _,
} => {
let mut iter = parts.iter(); let mut iter = parts.iter();
// The first value in the iterator is the variable name, // The first value in the iterator is the variable name,

View file

@ -42,7 +42,6 @@ pub enum Ident<'a> {
Access { Access {
module_name: &'a str, module_name: &'a str,
parts: &'a [Accessor<'a>], parts: &'a [Accessor<'a>],
suffixed: u8,
}, },
/// `.foo { foo: 42 }` or `.1 (1, 2, 3)` /// `.foo { foo: 42 }` or `.1 (1, 2, 3)`
AccessorFunction(Accessor<'a>), AccessorFunction(Accessor<'a>),
@ -193,12 +192,7 @@ pub fn parse_ident<'a>(
match chomp_identifier_chain(arena, state.bytes(), state.pos()) { match chomp_identifier_chain(arena, state.bytes(), state.pos()) {
Ok((width, ident)) => { Ok((width, ident)) => {
let state = advance_state!(state, width as usize)?; let state = advance_state!(state, width as usize)?;
if let Ident::Access { if let Ident::Access { module_name, parts } = ident {
module_name,
parts,
suffixed,
} = ident
{
if module_name.is_empty() { if module_name.is_empty() {
if let Some(first) = parts.first() { if let Some(first) = parts.first() {
for keyword in crate::keyword::KEYWORDS.iter() { for keyword in crate::keyword::KEYWORDS.iter() {
@ -209,15 +203,7 @@ pub fn parse_ident<'a>(
} }
} }
return Ok(( return Ok((MadeProgress, Ident::Access { module_name, parts }, state));
MadeProgress,
Ident::Access {
module_name,
parts,
suffixed,
},
state,
));
} }
Ok((MadeProgress, ident, state)) Ok((MadeProgress, ident, state))
@ -534,22 +520,9 @@ fn chomp_identifier_chain<'a>(
chomped += width as usize; chomped += width as usize;
// Parse any `!` suffixes
let suffixed = 0;
// while let Ok((ch, width)) = char::from_utf8_slice_start(&buffer[chomped..]) {
// if ch == '!' {
// suffixed += 1;
// chomped += width;
// } else {
// // we're done
// break;
// }
// }
let ident = Ident::Access { let ident = Ident::Access {
module_name, module_name,
parts: parts.into_bump_slice(), parts: parts.into_bump_slice(),
suffixed,
}; };
Ok((chomped as u32, ident)) Ok((chomped as u32, ident))
@ -584,22 +557,9 @@ fn chomp_identifier_chain<'a>(
// just one segment, starting with a lowercase letter; that's a normal identifier // just one segment, starting with a lowercase letter; that's a normal identifier
let value = unsafe { std::str::from_utf8_unchecked(&buffer[..chomped]) }; let value = unsafe { std::str::from_utf8_unchecked(&buffer[..chomped]) };
// Parse any `!` suffixes
let suffixed = 0;
// while let Ok((ch, width)) = char::from_utf8_slice_start(&buffer[chomped..]) {
// if ch == '!' {
// suffixed += 1;
// chomped += width;
// } else {
// // we're done
// break;
// }
// }
let ident = Ident::Access { let ident = Ident::Access {
module_name: "", module_name: "",
parts: arena.alloc([Accessor::RecordField(value)]), parts: arena.alloc([Accessor::RecordField(value)]),
suffixed,
}; };
Ok((chomped as u32, ident)) Ok((chomped as u32, ident))

View file

@ -12,7 +12,6 @@ use crate::string_literal::StrLikeLiteral;
use bumpalo::collections::string::String; use bumpalo::collections::string::String;
use bumpalo::collections::Vec; use bumpalo::collections::Vec;
use bumpalo::Bump; use bumpalo::Bump;
use roc_error_macros::internal_error;
use roc_region::all::{Loc, Region}; use roc_region::all::{Loc, Region};
/// Different patterns are supported in different circumstances. /// Different patterns are supported in different circumstances.
@ -50,14 +49,6 @@ pub fn loc_pattern_help<'a>() -> impl Parser<'a, Loc<Pattern<'a>>, EPattern<'a>>
let pattern_state = state.clone(); let pattern_state = state.clone();
// Return early with the suffixed statement
// match pattern.value {
// Pattern::Identifier { .. } if suffixed > 0 => {
// return Ok((MadeProgress, pattern, pattern_state))
// }
// _ => {}
// }
let (pattern_spaces, state) = let (pattern_spaces, state) =
match space0_e(EPattern::AsKeyword).parse(arena, state, min_indent) { match space0_e(EPattern::AsKeyword).parse(arena, state, min_indent) {
Err(_) => return Ok((MadeProgress, pattern, pattern_state)), Err(_) => return Ok((MadeProgress, pattern, pattern_state)),
@ -393,42 +384,6 @@ fn loc_ident_pattern_help<'a>(
Ok((MadeProgress, loc_pat, state)) Ok((MadeProgress, loc_pat, state))
} }
} }
// Parse a statement that begins with a suffixed identifier, e.g. `Stdout.line! "Hello"`
Ident::Access {
module_name,
parts,
suffixed,
..
} if suffixed > 0 => {
if module_name.is_empty() && parts.len() == 1 {
if let Accessor::RecordField(var) = &parts[0] {
Ok((
MadeProgress,
Loc {
region: loc_ident.region,
value: Pattern::Identifier { ident: var },
},
state,
))
} else {
internal_error!("unexpected suffixed TupleIndex");
}
} else if let Accessor::RecordField(var) = &parts[0] {
return Ok((
MadeProgress,
Loc {
region: loc_ident.region,
value: Pattern::QualifiedIdentifier {
module_name,
ident: var,
},
},
state,
));
} else {
internal_error!("unexpected suffixed TupleIndex");
}
}
Ident::Access { Ident::Access {
module_name, parts, .. module_name, parts, ..
} => { } => {