feat: remove the need for # in front of tuples

This commit is contained in:
rvcas 2022-12-12 18:40:51 -05:00 committed by Lucas
parent dfc57b347a
commit a4f6388eca
2 changed files with 23 additions and 32 deletions

View File

@ -336,13 +336,11 @@ fn constant_value_parser() -> impl Parser<Token, ast::UntypedConstant, Error = P
} }
}); });
let constant_tuple_parser = just(Token::Hash) let constant_tuple_parser = r
.ignore_then( .clone()
r.clone() .separated_by(just(Token::Comma))
.separated_by(just(Token::Comma)) .allow_trailing()
.allow_trailing() .delimited_by(just(Token::LeftParen), just(Token::RightParen))
.delimited_by(just(Token::LeftParen), just(Token::RightParen)),
)
.map_with_span(|elements, span| ast::UntypedConstant::Tuple { .map_with_span(|elements, span| ast::UntypedConstant::Tuple {
location: span, location: span,
elements, elements,
@ -851,13 +849,11 @@ pub fn expr_parser(
label, label,
}); });
let tuple = just(Token::Hash) let tuple = r
.ignore_then( .clone()
r.clone() .separated_by(just(Token::Comma))
.separated_by(just(Token::Comma)) .allow_trailing()
.allow_trailing() .delimited_by(just(Token::LeftParen), just(Token::RightParen))
.delimited_by(just(Token::LeftParen), just(Token::RightParen)),
)
.map_with_span(|elems, span| expr::UntypedExpr::Tuple { .map_with_span(|elems, span| expr::UntypedExpr::Tuple {
location: span, location: span,
elems, elems,
@ -1301,13 +1297,11 @@ pub fn type_parser() -> impl Parser<Token, ast::Annotation, Error = ParseError>
name, name,
} }
}), }),
just(Token::Hash) // Tuple
.ignore_then( r.clone()
r.clone() .separated_by(just(Token::Comma))
.separated_by(just(Token::Comma)) .allow_trailing()
.allow_trailing() .delimited_by(just(Token::LeftParen), just(Token::RightParen))
.delimited_by(just(Token::LeftParen), just(Token::RightParen)),
)
.map_with_span(|elems, span| ast::Annotation::Tuple { .map_with_span(|elems, span| ast::Annotation::Tuple {
location: span, location: span,
elems, elems,
@ -1528,13 +1522,10 @@ pub fn pattern_parser() -> impl Parser<Token, ast::UntypedPattern, Error = Parse
value, value,
} }
}), }),
just(Token::Hash) r.clone()
.ignore_then( .separated_by(just(Token::Comma))
r.clone() .allow_trailing()
.separated_by(just(Token::Comma)) .delimited_by(just(Token::LeftParen), just(Token::RightParen))
.allow_trailing()
.delimited_by(just(Token::LeftParen), just(Token::RightParen)),
)
.map_with_span(|elems, span| ast::UntypedPattern::Tuple { .map_with_span(|elems, span| ast::UntypedPattern::Tuple {
location: span, location: span,
elems, elems,

View File

@ -1,15 +1,15 @@
use sample use sample
pub fn spend(datum: sample.Datum, rdmr: sample.Redeemer, _ctx: Nil) -> Bool { pub fn spend(datum: sample.Datum, rdmr: sample.Redeemer, _ctx: Nil) -> Bool {
let _x = #(datum, rdmr, #[244]) let x = (datum, rdmr, #[244])
let y = [#(#[222], #[222]), #(#[233], #[52])] let y = [(#[222], #[222]), (#[233], #[52])]
let [z, f, ..g] = y let [z, f, ..g] = y
let #(a, b) = x let (a, b, _) = x
z == #(#[222], #[222]) z == (#[222], #[222])
} }
test foo() { test foo() {