fix: todo and fail spans

This commit is contained in:
rvcas 2023-07-15 20:00:00 -04:00 committed by Lucas
parent 69fdee9f7e
commit db3b5c74bb
12 changed files with 41 additions and 47 deletions

View File

@ -14,25 +14,19 @@ pub fn parser<'a>(
expression: Recursive<'a, Token, UntypedExpr, ParseError>,
sequence: Recursive<'a, Token, UntypedExpr, ParseError>,
) -> impl Parser<Token, UntypedExpr, Error = ParseError> + '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()
just(Token::Todo)
.ignore_then(message.clone())
.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()
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())

View File

@ -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,

View File

@ -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,

View File

@ -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",
},
}

View File

@ -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: [

View File

@ -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,

View File

@ -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",
},
}

View File

@ -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: [

View File

@ -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,

View File

@ -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",
},
},

View File

@ -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",
},
},

View File

@ -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,