fix: spans for backpassing args

closes #882

Co-authored-by: Kasey White <kwhitemsg@gmail.com>
This commit is contained in:
rvcas
2024-03-20 17:26:30 -04:00
parent 8495f98c1d
commit 898ef74457
25 changed files with 136 additions and 51 deletions

View File

@@ -27,6 +27,7 @@ Test(
tipo: (),
},
annotation: None,
location: 38..42,
},
],
kind: Expect {

View File

@@ -32,6 +32,7 @@ Fn(
name: "x",
},
annotation: None,
location: 17..18,
},
],
kind: Let {

View File

@@ -1,5 +1,5 @@
use crate::{
ast,
ast::{self, Span},
expr::UntypedExpr,
parser::{annotation, error::ParseError, pattern, token::Token},
};
@@ -9,17 +9,7 @@ pub fn let_(
r: Recursive<'_, Token, UntypedExpr, ParseError>,
) -> impl Parser<Token, UntypedExpr, Error = ParseError> + '_ {
just(Token::Let)
.ignore_then(
pattern()
.then(just(Token::Colon).ignore_then(annotation()).or_not())
.map(|(pattern, annotation)| ast::AssignmentPattern {
pattern,
annotation,
})
.separated_by(just(Token::Comma))
.allow_trailing()
.at_least(1),
)
.ignore_then(assignment_patterns())
.then(choice((just(Token::Equal), just(Token::LArrow))))
.then(r.clone())
.validate(move |((patterns, kind), value), span, emit| {
@@ -42,20 +32,25 @@ pub fn let_(
})
}
fn assignment_patterns() -> impl Parser<Token, Vec<ast::AssignmentPattern>, Error = ParseError> {
pattern()
.then(just(Token::Colon).ignore_then(annotation()).or_not())
.map_with_span(|(pattern, annotation), span| ast::AssignmentPattern {
pattern,
annotation,
location: span,
})
.separated_by(just(Token::Comma))
.allow_trailing()
.at_least(1)
}
pub fn expect(
r: Recursive<'_, Token, UntypedExpr, ParseError>,
) -> impl Parser<Token, UntypedExpr, Error = ParseError> + '_ {
just(Token::Expect)
.ignore_then(
pattern()
.then(just(Token::Colon).ignore_then(annotation()).or_not())
.map(|(pattern, annotation)| ast::AssignmentPattern {
pattern,
annotation,
})
.separated_by(just(Token::Comma))
.allow_trailing()
.at_least(1)
assignment_patterns()
.then(choice((just(Token::Equal), just(Token::LArrow))))
.or_not(),
)
@@ -66,22 +61,13 @@ pub fn expect(
}
let (patterns, kind) = opt_pattern.unwrap_or_else(|| {
(
vec![ast::AssignmentPattern {
pattern: ast::UntypedPattern::Constructor {
is_record: false,
location: span,
name: "True".to_string(),
arguments: vec![],
module: None,
constructor: (),
with_spread: false,
tipo: (),
},
annotation: None,
}],
Token::Equal,
)
let filler_true = ast::AssignmentPattern::new(
ast::UntypedPattern::true_(span),
None,
Span::empty(),
);
(vec![filler_true], Token::Equal)
});
let patterns = patterns

View File

@@ -23,6 +23,7 @@ Assignment {
name: "x",
},
annotation: None,
location: 16..17,
},
],
kind: Let {
@@ -53,6 +54,7 @@ Assignment {
name: "b",
},
annotation: None,
location: 4..5,
},
],
kind: Let {

View File

@@ -34,6 +34,7 @@ Assignment {
tipo: (),
},
annotation: None,
location: 7..14,
},
],
kind: Expect {

View File

@@ -33,6 +33,7 @@ Assignment {
tipo: (),
},
annotation: None,
location: 0..0,
},
],
kind: Expect {

View File

@@ -23,6 +23,7 @@ Assignment {
name: "a",
},
annotation: None,
location: 13..14,
},
],
kind: Let {
@@ -44,6 +45,7 @@ Assignment {
tipo: (),
},
annotation: None,
location: 0..0,
},
],
kind: Expect {

View File

@@ -23,6 +23,7 @@ Assignment {
name: "b",
},
annotation: None,
location: 14..15,
},
],
kind: Let {
@@ -38,6 +39,7 @@ Assignment {
name: "a",
},
annotation: None,
location: 4..5,
},
],
kind: Let {

View File

@@ -23,6 +23,7 @@ Assignment {
name: "b",
},
annotation: None,
location: 14..15,
},
],
kind: Let {
@@ -38,6 +39,7 @@ Assignment {
name: "a",
},
annotation: None,
location: 4..5,
},
],
kind: Let {

View File

@@ -23,6 +23,7 @@ Assignment {
name: "b",
},
annotation: None,
location: 16..17,
},
],
kind: Let {
@@ -42,6 +43,7 @@ Assignment {
name: "a",
},
annotation: None,
location: 4..5,
},
],
kind: Let {

View File

@@ -24,6 +24,7 @@ Assignment {
tipo: (),
},
annotation: None,
location: 0..0,
},
],
kind: Expect {

View File

@@ -34,6 +34,7 @@ Sequence {
name: "x",
},
annotation: None,
location: 4..5,
},
],
kind: Let {
@@ -124,6 +125,7 @@ Sequence {
name: "map_add_x",
},
annotation: None,
location: 24..33,
},
],
kind: Let {

View File

@@ -21,6 +21,7 @@ Sequence {
name: "i",
},
annotation: None,
location: 8..9,
},
],
kind: Let {
@@ -43,6 +44,7 @@ Sequence {
name: "j",
},
annotation: None,
location: 28..29,
},
],
kind: Let {
@@ -69,6 +71,7 @@ Sequence {
name: "k",
},
annotation: None,
location: 48..49,
},
],
kind: Let {

View File

@@ -35,6 +35,7 @@ Assignment {
name: "thing",
},
annotation: None,
location: 4..9,
},
],
kind: Let {

View File

@@ -47,6 +47,7 @@ Sequence {
name: "tuple",
},
annotation: None,
location: 4..9,
},
],
kind: Let {

View File

@@ -34,6 +34,7 @@ Sequence {
name: "a",
},
annotation: None,
location: 4..5,
},
],
kind: Let {

View File

@@ -92,6 +92,7 @@ When {
name: "amazing",
},
annotation: None,
location: 55..62,
},
],
kind: Let {