This commit is contained in:
Luke Boswell 2024-04-01 16:19:44 +11:00
parent b8ec53738a
commit 5ae188c08f
No known key found for this signature in database
GPG key ID: F6DB3C9DB47377B0
3 changed files with 19 additions and 84 deletions

View file

@ -886,30 +886,6 @@ pub fn desugar_expr<'a>(
})
}
LowLevelDbg(_, _, _) => unreachable!("Only exists after desugaring"),
// Suffixed(expr) => {
// // Rewrite `Suffixed(BinOps([args...], Var(...)))` to `BinOps([args...], Suffixed(Var(...)))`
// // This is to handle cases like e.g. `"Hello" |> line!`
// if let BinOps(args, sub_expr) = expr {
// return desugar_expr(
// arena,
// arena.alloc(Loc::at(
// loc_expr.region,
// BinOps(
// args,
// arena.alloc(Loc::at(sub_expr.region, Suffixed(&sub_expr.value))),
// ),
// )),
// src,
// line_info,
// module_path,
// );
// }
// // Suffixed are also desugared in Defs
// // Any nodes that don't get desugared will be caught by canonicalize_expr
// // and we can handle those cases as required
// loc_expr
// }
}
}

View file

@ -1000,8 +1000,6 @@ pub enum Pattern<'a> {
MalformedIdent(&'a str, crate::ident::BadIdent),
}
// pub fn contains_bang_suffixed
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum Base {
Octal,
@ -1511,14 +1509,7 @@ macro_rules! impl_extract_spaces {
match self {
$t::SpaceBefore(item, before) => {
match item {
$t::SpaceBefore(_, _) => {
// TODO this probably isn't right, but was causing a panic with just todo!()
Spaces {
before,
item: **item,
after: &[],
}
},
$t::SpaceBefore(_, _) => todo!(),
$t::SpaceAfter(item, after) => {
Spaces {
before,

View file

@ -626,7 +626,7 @@ pub fn parse_single_def<'a>(
options,
start,
spaces_before_current_start,
// TODO figure out why including spaces_before_current here doubles things up
// TODO including spaces_before_current here doubles things up
&[],
|_, loc_def_expr| -> ValueDef<'a> { ValueDef::Stmt(arena.alloc(loc_def_expr)) },
) {
@ -634,41 +634,12 @@ pub fn parse_single_def<'a>(
Either::Second(ValueDef::Stmt(loc_expr)) if is_loc_expr_suffixed(loc_expr) => {
Ok((MadeProgress, Some(single_def), state))
}
_ => Ok((NoProgress, None, initial)),
_ => Ok((NoProgress, None, initial)), // a hacky way to get expression-based error messages. TODO fix this
},
_ => Ok((NoProgress, None, initial)),
_ => Ok((NoProgress, None, initial)), // a hacky way to get expression-based error messages. TODO fix this
}
// a hacky way to get expression-based error messages. TODO fix this
}
Ok((_, loc_pattern, state)) => {
// // Check if we have a Statement with Suffixed first,
// // re-parse the state as an expression
// // and then use a `{}=` pattern for the ValueDef::Body.
// if is_statement {
// let parse_def_expr =
// space0_before_e(increment_min_indent(expr_start(options)), EExpr::IndentEnd);
// let (_, loc_def_expr, updated_state) =
// parse_def_expr.parse(arena, state, min_indent)?;
// let loc_pattern = Loc::at(region, Pattern::RecordDestructure(Collection::empty()));
// let value_def = ValueDef::Body(arena.alloc(loc_pattern), &*arena.alloc(loc_def_expr));
// let region = Region::span_across(&loc_pattern.region, &loc_def_expr.region);
// Ok((
// MadeProgress,
// Some(SingleDef {
// type_or_value: Either::Second(value_def),
// region,
// spaces_before: spaces_before_current,
// }),
// updated_state,
// ))
// }
// First let's check whether this is an ability definition.
let opt_tag_and_args: Option<(&str, Region, &[Loc<Pattern>])> = match loc_pattern.value
{
@ -721,7 +692,6 @@ pub fn parse_single_def<'a>(
// Stdout.line! "Bar"
// a=Stdout.line! "Foo"
// Task.ok {}
// any less than +4 and this doesn't work reliably
operator_result_state.line_indent() + 1,
arena,
operator_result_state.clone(),
@ -923,7 +893,6 @@ pub fn parse_single_def_assignment<'a>(
let (mut progress, mut loc_def_expr, mut state) =
parse_def_expr.parse(arena, state, min_indent)?;
// TODO how do we get region if we use parse_defs_expr which only returns expr???
let region = Region::span_across(&loc_pattern.region, &loc_def_expr.region);
// If the expression is actually a suffixed statement, then we need to continue
@ -934,7 +903,7 @@ pub fn parse_single_def_assignment<'a>(
// we will keep the pattern `loc_pattern` for the new Defs
defs.push_value_def(
ValueDef::Stmt(arena.alloc(loc_def_expr)),
region,
Region::span_across(&loc_pattern.region, &loc_def_expr.region),
spaces_before_current,
&[],
);
@ -1742,20 +1711,6 @@ fn parse_expr_operator<'a>(
.with_spaces_before(spaces_after_operator, new_expr.region);
}
// For suffixed expressions we restrict multi-line statements to be indented
// so that we can parse a statement like,
// ```
// "hello"
// |> sayHi!
// ```
// if we don't do this then we do not know where the statement ends
// and the next expressions starts
let new_indent = if is_loc_expr_suffixed(&new_expr) {
min_indent + 1
} else {
min_indent
};
match space0_e(EExpr::IndentEnd).parse(arena, state.clone(), min_indent) {
Err((_, _)) => {
let args = std::mem::replace(&mut expr_state.arguments, Vec::new_in(arena));
@ -1780,7 +1735,20 @@ fn parse_expr_operator<'a>(
expr_state.end = new_end;
expr_state.spaces_after = spaces;
// TODO new start?
// For suffixed expressions we restrict multi-line statements to be indented
// so that we can parse a statement like,
// ```
// "hello"
// |> sayHi!
// ```
// if we don't do this then we do not know where the statement ends
// and the next expressions starts
let new_indent = if is_loc_expr_suffixed(&new_expr) {
min_indent + 1
} else {
min_indent
};
parse_expr_end(new_indent, options, expr_state, arena, state, initial_state)
}
}