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>, expression: Recursive<'a, Token, UntypedExpr, ParseError>,
sequence: Recursive<'a, Token, UntypedExpr, ParseError>, sequence: Recursive<'a, Token, UntypedExpr, ParseError>,
) -> impl Parser<Token, UntypedExpr, Error = ParseError> + 'a { ) -> 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(( choice((
just(Token::Todo).ignore_then(choice(( just(Token::Todo)
clause(expression.clone()) .ignore_then(message.clone())
.ignored()
.rewind()
.map_with_span(|_, span| UntypedExpr::todo(None, span)),
choice((string::hybrid(), expression.clone()))
.or_not()
.map_with_span(UntypedExpr::todo), .map_with_span(UntypedExpr::todo),
))), just(Token::Fail)
just(Token::Fail).ignore_then(choice(( .ignore_then(message)
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), .map_with_span(UntypedExpr::fail),
))),
just(Token::Trace) just(Token::Trace)
.ignore_then(choice((string::hybrid(), expression.clone()))) .ignore_then(choice((string::hybrid(), expression.clone())))
.then(sequence.clone().or_not()) .then(sequence.clone().or_not())

View File

@ -4,9 +4,9 @@ description: "Code:\n\nfail @\"foo\"\n"
--- ---
Trace { Trace {
kind: Error, kind: Error,
location: 5..11, location: 0..11,
then: ErrorTerm { then: ErrorTerm {
location: 5..11, location: 0..11,
}, },
text: String { text: String {
location: 5..11, location: 5..11,

View File

@ -4,9 +4,9 @@ description: "Code:\n\nfail \"foo\"\n"
--- ---
Trace { Trace {
kind: Error, kind: Error,
location: 5..10, location: 0..10,
then: ErrorTerm { then: ErrorTerm {
location: 5..10, location: 0..10,
}, },
text: String { text: String {
location: 5..10, location: 5..10,

View File

@ -4,12 +4,12 @@ description: "Code:\n\nfail\n"
--- ---
Trace { Trace {
kind: Error, kind: Error,
location: 1..2, location: 0..4,
then: ErrorTerm { then: ErrorTerm {
location: 1..2, location: 0..4,
}, },
text: String { text: String {
location: 1..2, location: 0..4,
value: "aiken::error", value: "aiken::error",
}, },
} }

View File

@ -4,9 +4,9 @@ description: "Code:\n\nfail str.join([@\"Some string \", some_params, @\" some s
--- ---
Trace { Trace {
kind: Error, kind: Error,
location: 5..67, location: 0..67,
then: ErrorTerm { then: ErrorTerm {
location: 5..67, location: 0..67,
}, },
text: Call { text: Call {
arguments: [ arguments: [

View File

@ -4,9 +4,9 @@ description: "Code:\n\ntodo @\"foo\"\n"
--- ---
Trace { Trace {
kind: Todo, kind: Todo,
location: 5..11, location: 0..11,
then: ErrorTerm { then: ErrorTerm {
location: 5..11, location: 0..11,
}, },
text: String { text: String {
location: 5..11, location: 5..11,

View File

@ -4,12 +4,12 @@ description: "Code:\n\ntodo\n"
--- ---
Trace { Trace {
kind: Todo, kind: Todo,
location: 1..2, location: 0..4,
then: ErrorTerm { then: ErrorTerm {
location: 1..2, location: 0..4,
}, },
text: String { text: String {
location: 1..2, location: 0..4,
value: "aiken::todo", value: "aiken::todo",
}, },
} }

View File

@ -4,9 +4,9 @@ description: "Code:\n\ntodo string.join([\"foo\", \"bar\"])\n"
--- ---
Trace { Trace {
kind: Todo, kind: Todo,
location: 5..32, location: 0..32,
then: ErrorTerm { then: ErrorTerm {
location: 5..32, location: 0..32,
}, },
text: Call { text: Call {
arguments: [ arguments: [

View File

@ -4,9 +4,9 @@ description: "Code:\n\ntodo \"foo\"\n"
--- ---
Trace { Trace {
kind: Todo, kind: Todo,
location: 5..10, location: 0..10,
then: ErrorTerm { then: ErrorTerm {
location: 5..10, location: 0..10,
}, },
text: String { text: String {
location: 5..10, location: 5..10,

View File

@ -26,12 +26,12 @@ When {
guard: None, guard: None,
then: Trace { then: Trace {
kind: Todo, kind: Todo,
location: 35..39, location: 28..32,
then: ErrorTerm { then: ErrorTerm {
location: 35..39, location: 28..32,
}, },
text: String { text: String {
location: 35..39, location: 28..32,
value: "aiken::todo", value: "aiken::todo",
}, },
}, },
@ -53,12 +53,12 @@ When {
guard: None, guard: None,
then: Trace { then: Trace {
kind: Todo, kind: Todo,
location: 52..53, location: 47..51,
then: ErrorTerm { then: ErrorTerm {
location: 52..53, location: 47..51,
}, },
text: String { text: String {
location: 52..53, location: 47..51,
value: "aiken::todo", value: "aiken::todo",
}, },
}, },

View File

@ -26,12 +26,12 @@ When {
guard: None, guard: None,
then: Trace { then: Trace {
kind: Error, kind: Error,
location: 33..34, location: 28..32,
then: ErrorTerm { then: ErrorTerm {
location: 33..34, location: 28..32,
}, },
text: String { text: String {
location: 33..34, location: 28..32,
value: "aiken::error", value: "aiken::error",
}, },
}, },

View File

@ -46,9 +46,9 @@ When {
guard: None, guard: None,
then: Trace { then: Trace {
kind: Todo, kind: Todo,
location: 52..68, location: 47..68,
then: ErrorTerm { then: ErrorTerm {
location: 52..68, location: 47..68,
}, },
text: String { text: String {
location: 52..68, location: 52..68,