Merge remote-tracking branch 'origin/main' into https-packages

This commit is contained in:
Richard Feldman 2022-11-25 19:50:06 -05:00
commit b2beeb770e
No known key found for this signature in database
GPG key ID: F1F21AA5B1D9E43B
85 changed files with 2666 additions and 1064 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

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

View file

@ -0,0 +1,10 @@
_ = crash ""
_ = crash "" ""
_ = crash 15 123
_ = try foo (\_ -> crash "")
_ =
_ = crash ""
crash
{ f: crash "" }

View file

@ -0,0 +1,210 @@
Defs(
Defs {
tags: [
Index(2147483648),
Index(2147483649),
Index(2147483650),
Index(2147483651),
Index(2147483652),
],
regions: [
@0-12,
@13-28,
@29-45,
@46-74,
@75-101,
],
space_before: [
Slice(start = 0, length = 0),
Slice(start = 0, length = 1),
Slice(start = 1, length = 1),
Slice(start = 2, length = 1),
Slice(start = 3, length = 1),
],
space_after: [
Slice(start = 0, length = 0),
Slice(start = 1, length = 0),
Slice(start = 2, length = 0),
Slice(start = 3, length = 0),
Slice(start = 4, length = 0),
],
spaces: [
Newline,
Newline,
Newline,
Newline,
],
type_defs: [],
value_defs: [
Body(
@0-1 Underscore(
"",
),
@4-12 Apply(
@4-9 Crash,
[
@10-12 Str(
PlainLine(
"",
),
),
],
Space,
),
),
Body(
@13-14 Underscore(
"",
),
@17-28 Apply(
@17-22 Crash,
[
@23-25 Str(
PlainLine(
"",
),
),
@26-28 Str(
PlainLine(
"",
),
),
],
Space,
),
),
Body(
@29-30 Underscore(
"",
),
@33-45 Apply(
@33-38 Crash,
[
@39-41 Num(
"15",
),
@42-45 Num(
"123",
),
],
Space,
),
),
Body(
@46-47 Underscore(
"",
),
@50-74 Apply(
@50-53 Var {
module_name: "",
ident: "try",
},
[
@54-57 Var {
module_name: "",
ident: "foo",
},
@59-73 ParensAround(
Closure(
[
@60-61 Underscore(
"",
),
],
@65-73 Apply(
@65-70 Crash,
[
@71-73 Str(
PlainLine(
"",
),
),
],
Space,
),
),
),
],
Space,
),
),
Body(
@75-76 Underscore(
"",
),
@81-101 SpaceBefore(
Defs(
Defs {
tags: [
Index(2147483648),
],
regions: [
@81-93,
],
space_before: [
Slice(start = 0, length = 0),
],
space_after: [
Slice(start = 0, length = 0),
],
spaces: [],
type_defs: [],
value_defs: [
Body(
@81-82 Underscore(
"",
),
@85-93 Apply(
@85-90 Crash,
[
@91-93 Str(
PlainLine(
"",
),
),
],
Space,
),
),
],
},
@96-101 SpaceBefore(
Crash,
[
Newline,
],
),
),
[
Newline,
],
),
),
],
},
@103-118 SpaceBefore(
Record(
[
@105-116 RequiredValue(
@105-106 "f",
[],
@108-116 Apply(
@108-113 Crash,
[
@114-116 Str(
PlainLine(
"",
),
),
],
Space,
),
),
],
),
[
Newline,
Newline,
],
),
)

View file

@ -0,0 +1,9 @@
_ = crash ""
_ = crash "" ""
_ = crash 15 123
_ = try foo (\_ -> crash "")
_ =
_ = crash ""
crash
{ f: crash "" }

View file

@ -156,6 +156,7 @@ mod test_parse {
pass/comment_before_op.expr,
pass/comment_inside_empty_list.expr,
pass/comment_with_non_ascii.expr,
pass/crash.expr,
pass/destructure_tag_assignment.expr,
pass/empty_app_header.header,
pass/empty_hosted_header.header,