diff --git a/crates/aiken-lang/src/ast.rs b/crates/aiken-lang/src/ast.rs index 81acaa96..19cfc423 100644 --- a/crates/aiken-lang/src/ast.rs +++ b/crates/aiken-lang/src/ast.rs @@ -116,7 +116,7 @@ fn str_to_keyword(word: &str) -> Option { "type" => Some(Token::Type), "trace" => Some(Token::Trace), "test" => Some(Token::Test), - "error" => Some(Token::ErrorTerm), + "error" => Some(Token::Fail), "validator" => Some(Token::Validator), _ => None, } diff --git a/crates/aiken-lang/src/expr.rs b/crates/aiken-lang/src/expr.rs index 73bdf354..a5c43d98 100644 --- a/crates/aiken-lang/src/expr.rs +++ b/crates/aiken-lang/src/expr.rs @@ -552,7 +552,7 @@ impl UntypedExpr { } } - pub fn error(reason: Option, location: Span) -> Self { + pub fn fail(reason: Option, location: Span) -> Self { UntypedExpr::Trace { location, kind: TraceKind::Error, diff --git a/crates/aiken-lang/src/format.rs b/crates/aiken-lang/src/format.rs index 8193d135..353aa117 100644 --- a/crates/aiken-lang/src/format.rs +++ b/crates/aiken-lang/src/format.rs @@ -873,7 +873,7 @@ impl<'comments> Formatter<'comments> { ) -> Document<'a> { let (keyword, default_text) = match kind { TraceKind::Trace => ("trace", None), - TraceKind::Error => ("error", Some(DEFAULT_ERROR_STR.to_string())), + TraceKind::Error => ("fail", Some(DEFAULT_ERROR_STR.to_string())), TraceKind::Todo => ("todo", Some(DEFAULT_TODO_STR.to_string())), }; diff --git a/crates/aiken-lang/src/parser/expr/error_todo.rs b/crates/aiken-lang/src/parser/expr/fail_todo.rs similarity index 89% rename from crates/aiken-lang/src/parser/expr/error_todo.rs rename to crates/aiken-lang/src/parser/expr/fail_todo.rs index fe63483e..966b6f8d 100644 --- a/crates/aiken-lang/src/parser/expr/error_todo.rs +++ b/crates/aiken-lang/src/parser/expr/fail_todo.rs @@ -17,9 +17,9 @@ pub fn parser( just(Token::Todo) .ignore_then(message().or_not()) .map_with_span(UntypedExpr::todo), - just(Token::ErrorTerm) + just(Token::Fail) .ignore_then(message().or_not()) - .map_with_span(UntypedExpr::error), + .map_with_span(UntypedExpr::fail), )) } @@ -31,7 +31,7 @@ mod tests { fn error_basic() { assert_expr!( r#" - error @"foo" + fail @"foo" "# ); } @@ -40,7 +40,7 @@ mod tests { fn error_sugar() { assert_expr!( r#" - error "foo" + fail "foo" "# ); } diff --git a/crates/aiken-lang/src/parser/expr/mod.rs b/crates/aiken-lang/src/parser/expr/mod.rs index b0027e69..94ad489c 100644 --- a/crates/aiken-lang/src/parser/expr/mod.rs +++ b/crates/aiken-lang/src/parser/expr/mod.rs @@ -7,7 +7,7 @@ pub mod assignment; mod block; pub(crate) mod bytearray; mod chained; -mod error_todo; +mod fail_todo; mod if_else; mod int; mod list; @@ -23,7 +23,7 @@ pub use anonymous_function::parser as anonymous_function; pub use block::parser as block; pub use bytearray::parser as bytearray; pub use chained::parser as chained; -pub use error_todo::parser as error_todo; +pub use fail_todo::parser as fail_todo; pub use if_else::parser as if_else; pub use int::parser as int; pub use list::parser as list; @@ -43,7 +43,7 @@ pub fn parser( ) -> impl Parser + '_ { recursive(|expression| { choice(( - error_todo(sequence.clone()), + fail_todo(sequence.clone()), pure_expression(sequence, expression), )) }) diff --git a/crates/aiken-lang/src/parser/expr/snapshots/error_basic.snap b/crates/aiken-lang/src/parser/expr/snapshots/error_basic.snap index c7569fae..1f547cb1 100644 --- a/crates/aiken-lang/src/parser/expr/snapshots/error_basic.snap +++ b/crates/aiken-lang/src/parser/expr/snapshots/error_basic.snap @@ -1,15 +1,15 @@ --- -source: crates/aiken-lang/src/parser/expr/error_todo.rs -description: "Code:\n\nerror @\"foo\"\n" +source: crates/aiken-lang/src/parser/expr/fail_todo.rs +description: "Code:\n\nfail @\"foo\"\n" --- Trace { kind: Error, - location: 0..12, + location: 0..11, then: ErrorTerm { - location: 0..12, + location: 0..11, }, text: String { - location: 6..12, + location: 5..11, value: "foo", }, } diff --git a/crates/aiken-lang/src/parser/expr/snapshots/error_sugar.snap b/crates/aiken-lang/src/parser/expr/snapshots/error_sugar.snap index a1ee2c84..aac19d17 100644 --- a/crates/aiken-lang/src/parser/expr/snapshots/error_sugar.snap +++ b/crates/aiken-lang/src/parser/expr/snapshots/error_sugar.snap @@ -1,15 +1,15 @@ --- -source: crates/aiken-lang/src/parser/expr/error_todo.rs -description: "Code:\n\nerror \"foo\"\n" +source: crates/aiken-lang/src/parser/expr/fail_todo.rs +description: "Code:\n\nfail \"foo\"\n" --- Trace { kind: Error, - location: 0..11, + location: 0..10, then: ErrorTerm { - location: 0..11, + location: 0..10, }, text: String { - location: 6..11, + location: 5..10, value: "foo", }, } diff --git a/crates/aiken-lang/src/parser/expr/when/clause.rs b/crates/aiken-lang/src/parser/expr/when/clause.rs index 50a64114..6ac37655 100644 --- a/crates/aiken-lang/src/parser/expr/when/clause.rs +++ b/crates/aiken-lang/src/parser/expr/when/clause.rs @@ -63,7 +63,7 @@ mod tests { assert_expr!( r#" when val is { - Bar1{..} -> error + Bar1{..} -> fail } "# ); diff --git a/crates/aiken-lang/src/parser/expr/when/snapshots/when_clause_solo_error.snap b/crates/aiken-lang/src/parser/expr/when/snapshots/when_clause_solo_error.snap index 92b6171f..025955a4 100644 --- a/crates/aiken-lang/src/parser/expr/when/snapshots/when_clause_solo_error.snap +++ b/crates/aiken-lang/src/parser/expr/when/snapshots/when_clause_solo_error.snap @@ -1,16 +1,16 @@ --- source: crates/aiken-lang/src/parser/expr/when/clause.rs -description: "Code:\n\nwhen val is {\n Bar1{..} -> error\n}\n" +description: "Code:\n\nwhen val is {\n Bar1{..} -> fail\n}\n" --- When { - location: 0..35, + location: 0..34, subject: Var { location: 5..8, name: "val", }, clauses: [ UntypedClause { - location: 16..33, + location: 16..32, patterns: [ Constructor { is_record: true, @@ -26,12 +26,12 @@ When { guard: None, then: Trace { kind: Error, - location: 28..33, + location: 28..32, then: ErrorTerm { - location: 28..33, + location: 28..32, }, text: String { - location: 28..33, + location: 28..32, value: "aiken::error", }, }, diff --git a/crates/aiken-lang/src/parser/lexer.rs b/crates/aiken-lang/src/parser/lexer.rs index d196ce37..4940efa7 100644 --- a/crates/aiken-lang/src/parser/lexer.rs +++ b/crates/aiken-lang/src/parser/lexer.rs @@ -222,7 +222,9 @@ pub fn lexer() -> impl Parser, Error = ParseError> { let keyword = text::ident().map(|s: String| match s.as_str() { "trace" => Token::Trace, - "error" => Token::ErrorTerm, + "fail" => Token::Fail, + // TODO: delete this eventually + "error" => Token::Fail, "as" => Token::As, "assert" => Token::Expect, "expect" => Token::Expect, diff --git a/crates/aiken-lang/src/parser/token.rs b/crates/aiken-lang/src/parser/token.rs index ddd92116..43b25f81 100644 --- a/crates/aiken-lang/src/parser/token.rs +++ b/crates/aiken-lang/src/parser/token.rs @@ -74,7 +74,7 @@ pub enum Token { Fn, If, Else, - ErrorTerm, + Fail, Expect, Is, Let, @@ -170,7 +170,7 @@ impl fmt::Display for Token { Token::Trace => "trace", Token::Type => "type", Token::Test => "test", - Token::ErrorTerm => "error", + Token::Fail => "fail", Token::Validator => "validator", }; write!(f, "\"{s}\"") diff --git a/crates/aiken-lang/src/tests/format.rs b/crates/aiken-lang/src/tests/format.rs index f37aa2cb..ad2955ee 100644 --- a/crates/aiken-lang/src/tests/format.rs +++ b/crates/aiken-lang/src/tests/format.rs @@ -247,7 +247,7 @@ fn test_format_nested_function_calls() { , when output.datum is { InlineDatum(_) -> True - _ -> error "expected inline datum" + _ -> fail "expected inline datum" }, ] |> list.and @@ -271,13 +271,13 @@ fn test_format_trace_todo_error() { fn foo_3() { when x is { Foo -> True - _ -> error + _ -> fail } } fn foo_4() { if 14 == 42 { - error "I don't think so" + fail "I don't think so" } else { trace "been there" True diff --git a/crates/aiken-lang/src/tests/snapshots/format_nested_function_calls.snap b/crates/aiken-lang/src/tests/snapshots/format_nested_function_calls.snap index b072e1d0..d69f74c1 100644 --- a/crates/aiken-lang/src/tests/snapshots/format_nested_function_calls.snap +++ b/crates/aiken-lang/src/tests/snapshots/format_nested_function_calls.snap @@ -1,6 +1,6 @@ --- source: crates/aiken-lang/src/tests/format.rs -description: "Code:\n\nfn foo(output) {\n [\n output.address.stake_credential == Some(\n Inline(\n VerificationKeyCredential(\n #\"66666666666666666666666666666666666666666666666666666666\",\n ))\n )\n ,\n when output.datum is {\n InlineDatum(_) -> True\n _ -> error \"expected inline datum\"\n },\n ]\n |> list.and\n}\n" +description: "Code:\n\nfn foo(output) {\n [\n output.address.stake_credential == Some(\n Inline(\n VerificationKeyCredential(\n #\"66666666666666666666666666666666666666666666666666666666\",\n ))\n )\n ,\n when output.datum is {\n InlineDatum(_) -> True\n _ -> fail \"expected inline datum\"\n },\n ]\n |> list.and\n}\n" --- fn foo(output) { [ @@ -13,7 +13,7 @@ fn foo(output) { ), when output.datum is { InlineDatum(_) -> True - _ -> error @"expected inline datum" + _ -> fail @"expected inline datum" }, ] |> list.and diff --git a/crates/aiken-lang/src/tests/snapshots/format_trace_todo_error.snap b/crates/aiken-lang/src/tests/snapshots/format_trace_todo_error.snap index a41a4be8..ccf193c7 100644 --- a/crates/aiken-lang/src/tests/snapshots/format_trace_todo_error.snap +++ b/crates/aiken-lang/src/tests/snapshots/format_trace_todo_error.snap @@ -1,6 +1,6 @@ --- source: crates/aiken-lang/src/tests/format.rs -description: "Code:\n\nfn foo_1() {\n todo\n}\n\nfn foo_2() {\n todo \"my custom message\"\n}\n\nfn foo_3() {\n when x is {\n Foo -> True\n _ -> error\n }\n}\n\nfn foo_4() {\n if 14 == 42 {\n error \"I don't think so\"\n } else {\n trace \"been there\"\n True\n }\n}\n" +description: "Code:\n\nfn foo_1() {\n todo\n}\n\nfn foo_2() {\n todo \"my custom message\"\n}\n\nfn foo_3() {\n when x is {\n Foo -> True\n _ -> fail\n }\n}\n\nfn foo_4() {\n if 14 == 42 {\n fail \"I don't think so\"\n } else {\n trace \"been there\"\n True\n }\n}\n" --- fn foo_1() { todo @@ -13,13 +13,13 @@ fn foo_2() { fn foo_3() { when x is { Foo -> True - _ -> error + _ -> fail } } fn foo_4() { if 14 == 42 { - error @"I don't think so" + fail @"I don't think so" } else { trace @"been there" True diff --git a/crates/aiken-project/src/tests/gen_uplc.rs b/crates/aiken-project/src/tests/gen_uplc.rs index d58b28e9..a390b446 100644 --- a/crates/aiken-project/src/tests/gen_uplc.rs +++ b/crates/aiken-project/src/tests/gen_uplc.rs @@ -2601,7 +2601,7 @@ fn when_bool_is_true() { True -> True False -> - error + fail } } "#; @@ -2622,7 +2622,7 @@ fn when_bool_is_true_switched_cases() { test it() { when True is { False -> - error + fail True -> True } @@ -2645,7 +2645,7 @@ fn when_bool_is_false() { test it() { when False is { False -> - error + fail True -> True }