-
-
Notifications
You must be signed in to change notification settings - Fork 313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add !
suffix to parser
#6586
Add !
suffix to parser
#6586
Changes from all commits
88042c2
9bc0ab7
8bbbd76
e255706
f48ac46
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -311,8 +311,20 @@ fn expr_start<'a>(options: ExprParseOptions) -> impl Parser<'a, Loc<Expr<'a>>, E | |
|
||
fn expr_operator_chain<'a>(options: ExprParseOptions) -> impl Parser<'a, Expr<'a>, EExpr<'a>> { | ||
line_min_indent(move |arena, state: State<'a>, min_indent: u32| { | ||
let (_, expr, state) = | ||
loc_possibly_negative_or_negated_term(options).parse(arena, state, min_indent)?; | ||
let (_, expr, state) = loc_possibly_negative_or_negated_term(options) | ||
.parse(arena, state, min_indent) | ||
.map(|(progress, expr, state)| { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought this wouldn't be needed as the map in |
||
// If the next thing after the expression is a `!`, then it's Suffixed | ||
if state.bytes().starts_with(b"!") { | ||
( | ||
progress, | ||
Loc::at(expr.region, Expr::Suffixed(arena.alloc(expr.value))), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm really unsure about this. My concern is the that Loc in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If so, we'll see this in error messages when we get to testing those - the red underline either will or won't include the |
||
state.advance(1), | ||
) | ||
} else { | ||
(progress, expr, state) | ||
} | ||
})?; | ||
|
||
let initial_state = state.clone(); | ||
let end = state.pos(); | ||
|
@@ -1640,7 +1652,7 @@ fn parse_expr_end<'a>( | |
Err((MadeProgress, f)) => Err((MadeProgress, f)), | ||
Ok(( | ||
_, | ||
has @ Loc { | ||
implements @ Loc { | ||
value: | ||
Expr::Var { | ||
module_name: "", | ||
|
@@ -1672,17 +1684,17 @@ fn parse_expr_end<'a>( | |
} | ||
|
||
// Attach any spaces to the `implements` keyword | ||
let has = if !expr_state.spaces_after.is_empty() { | ||
let implements = if !expr_state.spaces_after.is_empty() { | ||
arena | ||
.alloc(Implements::Implements) | ||
.with_spaces_before(expr_state.spaces_after, has.region) | ||
.with_spaces_before(expr_state.spaces_after, implements.region) | ||
} else { | ||
Loc::at(has.region, Implements::Implements) | ||
Loc::at(implements.region, Implements::Implements) | ||
}; | ||
|
||
let args = arguments.into_bump_slice(); | ||
let (_, (type_def, def_region), state) = | ||
finish_parsing_ability_def_help(min_indent, name, args, has, arena, state)?; | ||
finish_parsing_ability_def_help(min_indent, name, args, implements, arena, state)?; | ||
|
||
let mut defs = Defs::default(); | ||
|
||
|
@@ -1817,6 +1829,18 @@ 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>> { | ||
|
@@ -1945,6 +1969,7 @@ fn expr_to_pattern_help<'a>(arena: &'a Bump, expr: &Expr<'a>) -> Result<Pattern< | |
Expr::Str(string) => Pattern::StrLiteral(string), | ||
Expr::SingleQuote(string) => Pattern::SingleQuote(string), | ||
Expr::MalformedIdent(string, problem) => Pattern::MalformedIdent(string, problem), | ||
Expr::Suffixed(_) => todo!(), | ||
}; | ||
|
||
// Now we re-add the spaces | ||
|
@@ -2997,6 +3022,7 @@ where | |
Err((NoProgress, to_error("->", state.pos()))) | ||
} | ||
"<-" => good!(BinOp::Backpassing, 2), | ||
"!" => Err((NoProgress, to_error("!", state.pos()))), | ||
_ => bad_made_progress!(chomped), | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Suffixed( | ||
Var { | ||
module_name: "Stdout", | ||
ident: "line", | ||
}, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Stdout.line! |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
foo! (bar! baz) (blah stuff) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
Apply( | ||
@0-3 Suffixed( | ||
Var { | ||
module_name: "", | ||
ident: "foo", | ||
}, | ||
), | ||
[ | ||
@9-17 ParensAround( | ||
Apply( | ||
@9-12 Suffixed( | ||
Var { | ||
module_name: "", | ||
ident: "bar", | ||
}, | ||
), | ||
[ | ||
@14-17 Var { | ||
module_name: "", | ||
ident: "baz", | ||
}, | ||
], | ||
Space, | ||
), | ||
), | ||
@22-32 ParensAround( | ||
Apply( | ||
@22-26 Var { | ||
module_name: "", | ||
ident: "blah", | ||
}, | ||
[ | ||
@27-32 Var { | ||
module_name: "", | ||
ident: "stuff", | ||
}, | ||
], | ||
Space, | ||
), | ||
), | ||
], | ||
Space, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
foo! ( bar! baz) ( blah stuff) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be completed in follow up PRs. One for each flavour of sugar.