Merge pull request #4460 from roc-lang/crash

Crash
This commit is contained in:
Richard Feldman 2022-11-25 17:18:21 -05:00 committed by GitHub
commit 58fad36f9d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
62 changed files with 1247 additions and 455 deletions

View file

@ -196,6 +196,9 @@ pub enum Expr<'a> {
Underscore(&'a str),
// The "crash" keyword
Crash,
// Tags
Tag(&'a str),

View file

@ -173,6 +173,7 @@ fn loc_term_or_underscore_or_conditional<'a>(
loc!(specialize(EExpr::SingleQuote, single_quote_literal_help())),
loc!(specialize(EExpr::Number, positive_number_literal_help())),
loc!(specialize(EExpr::Closure, closure_help(options))),
loc!(crash_kw()),
loc!(underscore_expression()),
loc!(record_literal_help()),
loc!(specialize(EExpr::List, list_literal_help())),
@ -238,6 +239,15 @@ fn underscore_expression<'a>() -> impl Parser<'a, Expr<'a>, EExpr<'a>> {
}
}
fn crash_kw<'a>() -> impl Parser<'a, Expr<'a>, EExpr<'a>> {
move |arena: &'a Bump, state: State<'a>, min_indent: u32| {
let (_, _, next_state) = crate::parser::keyword_e(crate::keyword::CRASH, EExpr::Crash)
.parse(arena, state, min_indent)?;
Ok((MadeProgress, Expr::Crash, next_state))
}
}
fn loc_possibly_negative_or_negated_term<'a>(
options: ExprParseOptions,
) -> impl Parser<'a, Loc<Expr<'a>>, EExpr<'a>> {
@ -1886,7 +1896,8 @@ fn expr_to_pattern_help<'a>(arena: &'a Bump, expr: &Expr<'a>) -> Result<Pattern<
| Expr::MalformedClosure
| Expr::PrecedenceConflict { .. }
| Expr::RecordUpdate { .. }
| Expr::UnaryOp(_, _) => Err(()),
| Expr::UnaryOp(_, _)
| Expr::Crash => Err(()),
Expr::Str(string) => Ok(Pattern::StrLiteral(*string)),
Expr::SingleQuote(string) => Ok(Pattern::SingleQuote(string)),

View file

@ -7,5 +7,6 @@ pub const IS: &str = "is";
pub const DBG: &str = "dbg";
pub const EXPECT: &str = "expect";
pub const EXPECT_FX: &str = "expect-fx";
pub const CRASH: &str = "crash";
pub const KEYWORDS: [&str; 8] = [IF, THEN, ELSE, WHEN, AS, IS, EXPECT, EXPECT_FX];
pub const KEYWORDS: [&str; 10] = [IF, THEN, ELSE, WHEN, AS, IS, DBG, EXPECT, EXPECT_FX, CRASH];

View file

@ -358,6 +358,7 @@ pub enum EExpr<'a> {
Closure(EClosure<'a>, Position),
Underscore(Position),
Crash(Position),
InParens(EInParens<'a>, Position),
Record(ERecord<'a>, Position),