fix: comments in record patterns closes #946
This commit is contained in:
@@ -23,7 +23,7 @@ Test(
|
||||
arguments: [],
|
||||
module: None,
|
||||
constructor: (),
|
||||
with_spread: false,
|
||||
spread_location: None,
|
||||
tipo: (),
|
||||
},
|
||||
annotation: None,
|
||||
|
||||
@@ -30,7 +30,7 @@ Assignment {
|
||||
],
|
||||
module: None,
|
||||
constructor: (),
|
||||
with_spread: false,
|
||||
spread_location: None,
|
||||
tipo: (),
|
||||
},
|
||||
annotation: None,
|
||||
|
||||
@@ -29,7 +29,7 @@ Assignment {
|
||||
arguments: [],
|
||||
module: None,
|
||||
constructor: (),
|
||||
with_spread: false,
|
||||
spread_location: None,
|
||||
tipo: (),
|
||||
},
|
||||
annotation: None,
|
||||
|
||||
@@ -41,7 +41,7 @@ Assignment {
|
||||
arguments: [],
|
||||
module: None,
|
||||
constructor: (),
|
||||
with_spread: false,
|
||||
spread_location: None,
|
||||
tipo: (),
|
||||
},
|
||||
annotation: None,
|
||||
|
||||
@@ -20,7 +20,7 @@ Assignment {
|
||||
arguments: [],
|
||||
module: None,
|
||||
constructor: (),
|
||||
with_spread: false,
|
||||
spread_location: None,
|
||||
tipo: (),
|
||||
},
|
||||
annotation: None,
|
||||
|
||||
@@ -19,7 +19,9 @@ When {
|
||||
arguments: [],
|
||||
module: None,
|
||||
constructor: (),
|
||||
with_spread: true,
|
||||
spread_location: Some(
|
||||
21..23,
|
||||
),
|
||||
tipo: (),
|
||||
},
|
||||
],
|
||||
@@ -46,7 +48,9 @@ When {
|
||||
arguments: [],
|
||||
module: None,
|
||||
constructor: (),
|
||||
with_spread: true,
|
||||
spread_location: Some(
|
||||
40..42,
|
||||
),
|
||||
tipo: (),
|
||||
},
|
||||
],
|
||||
|
||||
@@ -19,7 +19,9 @@ When {
|
||||
arguments: [],
|
||||
module: None,
|
||||
constructor: (),
|
||||
with_spread: true,
|
||||
spread_location: Some(
|
||||
21..23,
|
||||
),
|
||||
tipo: (),
|
||||
},
|
||||
],
|
||||
|
||||
@@ -19,7 +19,9 @@ When {
|
||||
arguments: [],
|
||||
module: None,
|
||||
constructor: (),
|
||||
with_spread: true,
|
||||
spread_location: Some(
|
||||
21..23,
|
||||
),
|
||||
tipo: (),
|
||||
},
|
||||
],
|
||||
@@ -39,7 +41,9 @@ When {
|
||||
arguments: [],
|
||||
module: None,
|
||||
constructor: (),
|
||||
with_spread: true,
|
||||
spread_location: Some(
|
||||
40..42,
|
||||
),
|
||||
tipo: (),
|
||||
},
|
||||
],
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use chumsky::prelude::*;
|
||||
|
||||
use crate::{
|
||||
ast::{CallArg, UntypedPattern},
|
||||
ast::{CallArg, Span, UntypedPattern},
|
||||
parser::{error::ParseError, token::Token},
|
||||
};
|
||||
|
||||
@@ -10,23 +10,26 @@ pub fn parser(
|
||||
) -> impl Parser<Token, UntypedPattern, Error = ParseError> + '_ {
|
||||
select! {Token::UpName { name } => name}
|
||||
.then(args(expression))
|
||||
.map_with_span(|(name, (arguments, with_spread, is_record)), location| {
|
||||
UntypedPattern::Constructor {
|
||||
is_record,
|
||||
location,
|
||||
name,
|
||||
arguments,
|
||||
module: None,
|
||||
constructor: (),
|
||||
with_spread,
|
||||
tipo: (),
|
||||
}
|
||||
})
|
||||
.map_with_span(
|
||||
|(name, (arguments, spread_location, is_record)), location| {
|
||||
UntypedPattern::Constructor {
|
||||
is_record,
|
||||
location,
|
||||
name,
|
||||
arguments,
|
||||
module: None,
|
||||
constructor: (),
|
||||
spread_location,
|
||||
tipo: (),
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn args(
|
||||
expression: Recursive<'_, Token, UntypedPattern, ParseError>,
|
||||
) -> impl Parser<Token, (Vec<CallArg<UntypedPattern>>, bool, bool), Error = ParseError> + '_ {
|
||||
) -> impl Parser<Token, (Vec<CallArg<UntypedPattern>>, Option<Span>, bool), Error = ParseError> + '_
|
||||
{
|
||||
let record_constructor_pattern_arg_parser = choice((
|
||||
select! {Token::Name {name} => name}
|
||||
.then_ignore(just(Token::Colon))
|
||||
@@ -49,8 +52,9 @@ pub(crate) fn args(
|
||||
.allow_trailing()
|
||||
.then(
|
||||
just(Token::DotDot)
|
||||
.then_ignore(just(Token::Comma).or_not())
|
||||
.ignored()
|
||||
.map_with_span(|_spread, span| span)
|
||||
.then_ignore(just(Token::Comma).or_not())
|
||||
.or_not(),
|
||||
)
|
||||
.delimited_by(just(Token::LeftBrace), just(Token::RightBrace));
|
||||
@@ -66,8 +70,9 @@ pub(crate) fn args(
|
||||
.allow_trailing()
|
||||
.then(
|
||||
just(Token::DotDot)
|
||||
.then_ignore(just(Token::Comma).or_not())
|
||||
.ignored()
|
||||
.map_with_span(|_spread, span| span)
|
||||
.then_ignore(just(Token::Comma).or_not())
|
||||
.or_not(),
|
||||
)
|
||||
.delimited_by(just(Token::LeftParen), just(Token::RightParen));
|
||||
@@ -79,8 +84,8 @@ pub(crate) fn args(
|
||||
.or_not()
|
||||
.map(|opt_args| {
|
||||
opt_args
|
||||
.map(|((a, b), c)| (a, b.is_some(), c))
|
||||
.unwrap_or_else(|| (vec![], false, false))
|
||||
.map(|((a, b), c)| (a, b, c))
|
||||
.unwrap_or_else(|| (vec![], None, false))
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,6 @@ Constructor {
|
||||
arguments: [],
|
||||
module: None,
|
||||
constructor: (),
|
||||
with_spread: false,
|
||||
spread_location: None,
|
||||
tipo: (),
|
||||
}
|
||||
|
||||
@@ -11,6 +11,6 @@ Constructor {
|
||||
"module",
|
||||
),
|
||||
constructor: (),
|
||||
with_spread: false,
|
||||
spread_location: None,
|
||||
tipo: (),
|
||||
}
|
||||
|
||||
@@ -30,6 +30,6 @@ Constructor {
|
||||
],
|
||||
module: None,
|
||||
constructor: (),
|
||||
with_spread: false,
|
||||
spread_location: None,
|
||||
tipo: (),
|
||||
}
|
||||
|
||||
@@ -26,6 +26,6 @@ Constructor {
|
||||
],
|
||||
module: None,
|
||||
constructor: (),
|
||||
with_spread: false,
|
||||
spread_location: None,
|
||||
tipo: (),
|
||||
}
|
||||
|
||||
@@ -39,6 +39,6 @@ Constructor {
|
||||
],
|
||||
module: None,
|
||||
constructor: (),
|
||||
with_spread: false,
|
||||
spread_location: None,
|
||||
tipo: (),
|
||||
}
|
||||
|
||||
@@ -20,6 +20,8 @@ Constructor {
|
||||
],
|
||||
module: None,
|
||||
constructor: (),
|
||||
with_spread: true,
|
||||
spread_location: Some(
|
||||
9..11,
|
||||
),
|
||||
tipo: (),
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ Pair {
|
||||
arguments: [],
|
||||
module: None,
|
||||
constructor: (),
|
||||
with_spread: false,
|
||||
spread_location: None,
|
||||
tipo: (),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ pub fn parser(
|
||||
.or_not(),
|
||||
)
|
||||
.map_with_span(|(name, opt_pattern), span| {
|
||||
if let Some((c_name, (arguments, with_spread, is_record))) = opt_pattern {
|
||||
if let Some((c_name, (arguments, spread_location, is_record))) = opt_pattern {
|
||||
UntypedPattern::Constructor {
|
||||
is_record,
|
||||
location: span,
|
||||
@@ -26,7 +26,7 @@ pub fn parser(
|
||||
arguments,
|
||||
module: Some(name),
|
||||
constructor: (),
|
||||
with_spread,
|
||||
spread_location,
|
||||
tipo: (),
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user