From db3b5c74bb37ffa68c0b7a932b7865b20c2857da Mon Sep 17 00:00:00 2001 From: rvcas Date: Sat, 15 Jul 2023 20:00:00 -0400 Subject: [PATCH] fix: todo and fail spans --- .../src/parser/expr/fail_todo_trace.rs | 30 ++++++++----------- .../parser/expr/snapshots/error_basic.snap | 4 +-- .../parser/expr/snapshots/error_sugar.snap | 4 +-- .../src/parser/expr/snapshots/fail_empty.snap | 6 ++-- .../src/parser/expr/snapshots/fail_expr.snap | 4 +-- .../src/parser/expr/snapshots/todo_basic.snap | 4 +-- .../src/parser/expr/snapshots/todo_empty.snap | 6 ++-- .../src/parser/expr/snapshots/todo_expr.snap | 4 +-- .../src/parser/expr/snapshots/todo_sugar.snap | 4 +-- .../snapshots/when_clause_double_todo.snap | 12 ++++---- .../snapshots/when_clause_solo_error.snap | 6 ++-- .../expr/when/snapshots/when_clause_todo.snap | 4 +-- 12 files changed, 41 insertions(+), 47 deletions(-) diff --git a/crates/aiken-lang/src/parser/expr/fail_todo_trace.rs b/crates/aiken-lang/src/parser/expr/fail_todo_trace.rs index 61b8f2f8..cdec3694 100644 --- a/crates/aiken-lang/src/parser/expr/fail_todo_trace.rs +++ b/crates/aiken-lang/src/parser/expr/fail_todo_trace.rs @@ -14,25 +14,19 @@ pub fn parser<'a>( expression: Recursive<'a, Token, UntypedExpr, ParseError>, sequence: Recursive<'a, Token, UntypedExpr, ParseError>, ) -> impl Parser + 'a { + let message = choice(( + clause(expression.clone()).ignored().rewind().to(None), + choice((string::hybrid(), expression.clone())).or_not(), + )) + .boxed(); + choice(( - just(Token::Todo).ignore_then(choice(( - clause(expression.clone()) - .ignored() - .rewind() - .map_with_span(|_, span| UntypedExpr::todo(None, span)), - choice((string::hybrid(), expression.clone())) - .or_not() - .map_with_span(UntypedExpr::todo), - ))), - just(Token::Fail).ignore_then(choice(( - clause(expression.clone()) - .ignored() - .rewind() - .map_with_span(|_, span| UntypedExpr::fail(None, span)), - choice((string::hybrid(), expression.clone())) - .or_not() - .map_with_span(UntypedExpr::fail), - ))), + just(Token::Todo) + .ignore_then(message.clone()) + .map_with_span(UntypedExpr::todo), + just(Token::Fail) + .ignore_then(message) + .map_with_span(UntypedExpr::fail), just(Token::Trace) .ignore_then(choice((string::hybrid(), expression.clone()))) .then(sequence.clone().or_not()) 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 5efe3038..2a1d8c0d 100644 --- a/crates/aiken-lang/src/parser/expr/snapshots/error_basic.snap +++ b/crates/aiken-lang/src/parser/expr/snapshots/error_basic.snap @@ -4,9 +4,9 @@ description: "Code:\n\nfail @\"foo\"\n" --- Trace { kind: Error, - location: 5..11, + location: 0..11, then: ErrorTerm { - location: 5..11, + location: 0..11, }, text: String { location: 5..11, 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 5f5a60e4..1cb7d47e 100644 --- a/crates/aiken-lang/src/parser/expr/snapshots/error_sugar.snap +++ b/crates/aiken-lang/src/parser/expr/snapshots/error_sugar.snap @@ -4,9 +4,9 @@ description: "Code:\n\nfail \"foo\"\n" --- Trace { kind: Error, - location: 5..10, + location: 0..10, then: ErrorTerm { - location: 5..10, + location: 0..10, }, text: String { location: 5..10, diff --git a/crates/aiken-lang/src/parser/expr/snapshots/fail_empty.snap b/crates/aiken-lang/src/parser/expr/snapshots/fail_empty.snap index e99d8a88..654eef1f 100644 --- a/crates/aiken-lang/src/parser/expr/snapshots/fail_empty.snap +++ b/crates/aiken-lang/src/parser/expr/snapshots/fail_empty.snap @@ -4,12 +4,12 @@ description: "Code:\n\nfail\n" --- Trace { kind: Error, - location: 1..2, + location: 0..4, then: ErrorTerm { - location: 1..2, + location: 0..4, }, text: String { - location: 1..2, + location: 0..4, value: "aiken::error", }, } diff --git a/crates/aiken-lang/src/parser/expr/snapshots/fail_expr.snap b/crates/aiken-lang/src/parser/expr/snapshots/fail_expr.snap index a7223e61..2e7d8190 100644 --- a/crates/aiken-lang/src/parser/expr/snapshots/fail_expr.snap +++ b/crates/aiken-lang/src/parser/expr/snapshots/fail_expr.snap @@ -4,9 +4,9 @@ description: "Code:\n\nfail str.join([@\"Some string \", some_params, @\" some s --- Trace { kind: Error, - location: 5..67, + location: 0..67, then: ErrorTerm { - location: 5..67, + location: 0..67, }, text: Call { arguments: [ diff --git a/crates/aiken-lang/src/parser/expr/snapshots/todo_basic.snap b/crates/aiken-lang/src/parser/expr/snapshots/todo_basic.snap index 201c08bf..9470a1a8 100644 --- a/crates/aiken-lang/src/parser/expr/snapshots/todo_basic.snap +++ b/crates/aiken-lang/src/parser/expr/snapshots/todo_basic.snap @@ -4,9 +4,9 @@ description: "Code:\n\ntodo @\"foo\"\n" --- Trace { kind: Todo, - location: 5..11, + location: 0..11, then: ErrorTerm { - location: 5..11, + location: 0..11, }, text: String { location: 5..11, diff --git a/crates/aiken-lang/src/parser/expr/snapshots/todo_empty.snap b/crates/aiken-lang/src/parser/expr/snapshots/todo_empty.snap index ae059379..bc1fc0d1 100644 --- a/crates/aiken-lang/src/parser/expr/snapshots/todo_empty.snap +++ b/crates/aiken-lang/src/parser/expr/snapshots/todo_empty.snap @@ -4,12 +4,12 @@ description: "Code:\n\ntodo\n" --- Trace { kind: Todo, - location: 1..2, + location: 0..4, then: ErrorTerm { - location: 1..2, + location: 0..4, }, text: String { - location: 1..2, + location: 0..4, value: "aiken::todo", }, } diff --git a/crates/aiken-lang/src/parser/expr/snapshots/todo_expr.snap b/crates/aiken-lang/src/parser/expr/snapshots/todo_expr.snap index 45117539..9767c66a 100644 --- a/crates/aiken-lang/src/parser/expr/snapshots/todo_expr.snap +++ b/crates/aiken-lang/src/parser/expr/snapshots/todo_expr.snap @@ -4,9 +4,9 @@ description: "Code:\n\ntodo string.join([\"foo\", \"bar\"])\n" --- Trace { kind: Todo, - location: 5..32, + location: 0..32, then: ErrorTerm { - location: 5..32, + location: 0..32, }, text: Call { arguments: [ diff --git a/crates/aiken-lang/src/parser/expr/snapshots/todo_sugar.snap b/crates/aiken-lang/src/parser/expr/snapshots/todo_sugar.snap index 90e0777b..6e9bf4c0 100644 --- a/crates/aiken-lang/src/parser/expr/snapshots/todo_sugar.snap +++ b/crates/aiken-lang/src/parser/expr/snapshots/todo_sugar.snap @@ -4,9 +4,9 @@ description: "Code:\n\ntodo \"foo\"\n" --- Trace { kind: Todo, - location: 5..10, + location: 0..10, then: ErrorTerm { - location: 5..10, + location: 0..10, }, text: String { location: 5..10, diff --git a/crates/aiken-lang/src/parser/expr/when/snapshots/when_clause_double_todo.snap b/crates/aiken-lang/src/parser/expr/when/snapshots/when_clause_double_todo.snap index 0f9204ed..b708e48a 100644 --- a/crates/aiken-lang/src/parser/expr/when/snapshots/when_clause_double_todo.snap +++ b/crates/aiken-lang/src/parser/expr/when/snapshots/when_clause_double_todo.snap @@ -26,12 +26,12 @@ When { guard: None, then: Trace { kind: Todo, - location: 35..39, + location: 28..32, then: ErrorTerm { - location: 35..39, + location: 28..32, }, text: String { - location: 35..39, + location: 28..32, value: "aiken::todo", }, }, @@ -53,12 +53,12 @@ When { guard: None, then: Trace { kind: Todo, - location: 52..53, + location: 47..51, then: ErrorTerm { - location: 52..53, + location: 47..51, }, text: String { - location: 52..53, + location: 47..51, value: "aiken::todo", }, }, 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 85e7ae46..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 @@ -26,12 +26,12 @@ When { guard: None, then: Trace { kind: Error, - location: 33..34, + location: 28..32, then: ErrorTerm { - location: 33..34, + location: 28..32, }, text: String { - location: 33..34, + location: 28..32, value: "aiken::error", }, }, diff --git a/crates/aiken-lang/src/parser/expr/when/snapshots/when_clause_todo.snap b/crates/aiken-lang/src/parser/expr/when/snapshots/when_clause_todo.snap index c0b59c19..26c65eea 100644 --- a/crates/aiken-lang/src/parser/expr/when/snapshots/when_clause_todo.snap +++ b/crates/aiken-lang/src/parser/expr/when/snapshots/when_clause_todo.snap @@ -46,9 +46,9 @@ When { guard: None, then: Trace { kind: Todo, - location: 52..68, + location: 47..68, then: ErrorTerm { - location: 52..68, + location: 47..68, }, text: String { location: 52..68,