From 4f6defcf3e4f458fe2facf1ba28964ab535492ea Mon Sep 17 00:00:00 2001 From: KtorZ Date: Wed, 5 Jul 2023 14:42:14 +0200 Subject: [PATCH] =?UTF-8?q?rename:=20'r'=20=E2=86=92=20'expression'=20&=20?= =?UTF-8?q?'seq=5Fr'=20=E2=86=92=20'sequence'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Better readability. --- crates/aiken-lang/src/parser/annotation.rs | 16 +++++--- .../src/parser/expr/anonymous_function.rs | 4 +- crates/aiken-lang/src/parser/expr/block.rs | 6 +-- crates/aiken-lang/src/parser/expr/if_else.rs | 40 +++++++++++-------- crates/aiken-lang/src/parser/expr/mod.rs | 26 ++++++------ crates/aiken-lang/src/parser/expr/sequence.rs | 14 +++---- .../aiken-lang/src/parser/expr/when/guard.rs | 4 +- crates/aiken-lang/src/parser/pattern/mod.rs | 18 +++++---- 8 files changed, 71 insertions(+), 57 deletions(-) diff --git a/crates/aiken-lang/src/parser/annotation.rs b/crates/aiken-lang/src/parser/annotation.rs index 7b0f5244..8afdac55 100644 --- a/crates/aiken-lang/src/parser/annotation.rs +++ b/crates/aiken-lang/src/parser/annotation.rs @@ -5,7 +5,7 @@ use crate::ast; use super::{error::ParseError, token::Token}; pub fn parser() -> impl Parser { - recursive(|r| { + recursive(|expression| { choice(( // Type hole select! {Token::DiscardName { name } => name}.map_with_span(|name, span| { @@ -15,7 +15,8 @@ pub fn parser() -> impl Parser { } }), // Tuple - r.clone() + expression + .clone() .separated_by(just(Token::Comma)) .at_least(2) .allow_trailing() @@ -30,13 +31,14 @@ pub fn parser() -> impl Parser { // Function just(Token::Fn) .ignore_then( - r.clone() + expression + .clone() .separated_by(just(Token::Comma)) .allow_trailing() .delimited_by(just(Token::LeftParen), just(Token::RightParen)), ) .then_ignore(just(Token::RArrow)) - .then(r.clone()) + .then(expression.clone()) .map_with_span(|(arguments, ret), span| ast::Annotation::Fn { location: span, arguments, @@ -45,7 +47,8 @@ pub fn parser() -> impl Parser { // Constructor function select! {Token::UpName { name } => name} .then( - r.clone() + expression + .clone() .separated_by(just(Token::Comma)) .allow_trailing() .delimited_by(just(Token::Less), just(Token::Greater)) @@ -63,7 +66,8 @@ pub fn parser() -> impl Parser { just(Token::Dot) .ignore_then(select! {Token::UpName {name} => name}) .then( - r.separated_by(just(Token::Comma)) + expression + .separated_by(just(Token::Comma)) .allow_trailing() .delimited_by(just(Token::Less), just(Token::Greater)) .or_not(), diff --git a/crates/aiken-lang/src/parser/expr/anonymous_function.rs b/crates/aiken-lang/src/parser/expr/anonymous_function.rs index 5485a75e..39bdb044 100644 --- a/crates/aiken-lang/src/parser/expr/anonymous_function.rs +++ b/crates/aiken-lang/src/parser/expr/anonymous_function.rs @@ -7,7 +7,7 @@ use crate::{ }; pub fn parser( - seq_r: Recursive<'_, Token, UntypedExpr, ParseError>, + sequence: Recursive<'_, Token, UntypedExpr, ParseError>, ) -> impl Parser + '_ { just(Token::Fn) .ignore_then( @@ -17,7 +17,7 @@ pub fn parser( .delimited_by(just(Token::LeftParen), just(Token::RightParen)), ) .then(just(Token::RArrow).ignore_then(annotation()).or_not()) - .then(seq_r.delimited_by(just(Token::LeftBrace), just(Token::RightBrace))) + .then(sequence.delimited_by(just(Token::LeftBrace), just(Token::RightBrace))) .map_with_span( |((arguments, return_annotation), body), span| UntypedExpr::Fn { arguments, diff --git a/crates/aiken-lang/src/parser/expr/block.rs b/crates/aiken-lang/src/parser/expr/block.rs index e555de05..f40424e7 100644 --- a/crates/aiken-lang/src/parser/expr/block.rs +++ b/crates/aiken-lang/src/parser/expr/block.rs @@ -6,13 +6,13 @@ use crate::{ }; pub fn parser( - seq_r: Recursive<'_, Token, UntypedExpr, ParseError>, + sequence: Recursive<'_, Token, UntypedExpr, ParseError>, ) -> impl Parser + '_ { choice(( - seq_r + sequence .clone() .delimited_by(just(Token::LeftBrace), just(Token::RightBrace)), - seq_r.clone().delimited_by( + sequence.clone().delimited_by( choice((just(Token::LeftParen), just(Token::NewLineLeftParen))), just(Token::RightParen), ), diff --git a/crates/aiken-lang/src/parser/expr/if_else.rs b/crates/aiken-lang/src/parser/expr/if_else.rs index d0efcfec..3d9c5deb 100644 --- a/crates/aiken-lang/src/parser/expr/if_else.rs +++ b/crates/aiken-lang/src/parser/expr/if_else.rs @@ -9,31 +9,37 @@ use crate::{ use super::block; pub fn parser<'a>( - seq_r: Recursive<'a, Token, UntypedExpr, ParseError>, - r: Recursive<'a, Token, UntypedExpr, ParseError>, + sequence: Recursive<'a, Token, UntypedExpr, ParseError>, + expression: Recursive<'a, Token, UntypedExpr, ParseError>, ) -> impl Parser + 'a { just(Token::If) - .ignore_then(r.clone().then(block(seq_r.clone())).map_with_span( - |(condition, body), span| ast::IfBranch { - condition, - body, - location: span, - }, - )) + .ignore_then( + expression + .clone() + .then(block(sequence.clone())) + .map_with_span(|(condition, body), span| ast::IfBranch { + condition, + body, + location: span, + }), + ) .then( just(Token::Else) .ignore_then(just(Token::If)) - .ignore_then(r.clone().then(block(seq_r.clone())).map_with_span( - |(condition, body), span| ast::IfBranch { - condition, - body, - location: span, - }, - )) + .ignore_then( + expression + .clone() + .then(block(sequence.clone())) + .map_with_span(|(condition, body), span| ast::IfBranch { + condition, + body, + location: span, + }), + ) .repeated(), ) .then_ignore(just(Token::Else)) - .then(block(seq_r)) + .then(block(sequence)) .map_with_span(|((first, alternative_branches), final_else), span| { let mut branches = vec1::vec1![first]; diff --git a/crates/aiken-lang/src/parser/expr/mod.rs b/crates/aiken-lang/src/parser/expr/mod.rs index 05455021..37d676bf 100644 --- a/crates/aiken-lang/src/parser/expr/mod.rs +++ b/crates/aiken-lang/src/parser/expr/mod.rs @@ -40,9 +40,9 @@ use crate::{ use super::{error::ParseError, token::Token}; pub fn parser( - seq_r: Recursive<'_, Token, UntypedExpr, ParseError>, + sequence: Recursive<'_, Token, UntypedExpr, ParseError>, ) -> impl Parser + '_ { - recursive(|r| { + recursive(|expression| { let field_access_constructor = select! {Token::Name { name } => name} .map_with_span(|module, span| (module, span)) .then_ignore(just(Token::Dot)) @@ -59,20 +59,20 @@ pub fn parser( let expr_unit_parser = choice(( string(), int(), - record_update(r.clone()), - record(r.clone()), + record_update(expression.clone()), + record(expression.clone()), field_access_constructor, var(), - tuple(r.clone()), + tuple(expression.clone()), bytearray(), - list(r.clone()), - anonymous_function(seq_r.clone()), + list(expression.clone()), + anonymous_function(sequence.clone()), anonymous_binop(), - block(seq_r.clone()), - when(r.clone()), - assignment::let_(r.clone()), - assignment::expect(r.clone()), - if_else(seq_r, r.clone()), + block(sequence.clone()), + when(expression.clone()), + assignment::let_(expression.clone()), + assignment::expect(expression.clone()), + if_else(sequence, expression.clone()), )); // Parsing a function call into the appropriate structure @@ -118,7 +118,7 @@ pub fn parser( select! { Token::Name { name } => name } .then_ignore(just(Token::Colon)) .or_not() - .then(r) + .then(expression) .map_with_span(|(label, value), span| { ParserArg::Arg(Box::new(ast::CallArg { label, diff --git a/crates/aiken-lang/src/parser/expr/sequence.rs b/crates/aiken-lang/src/parser/expr/sequence.rs index 38e5eab2..68e5c075 100644 --- a/crates/aiken-lang/src/parser/expr/sequence.rs +++ b/crates/aiken-lang/src/parser/expr/sequence.rs @@ -7,11 +7,11 @@ use crate::{ }; pub fn parser() -> impl Parser { - recursive(|r| { + recursive(|expression| { choice(( just(Token::Trace) - .ignore_then(super::parser(r.clone())) - .then(r.clone()) + .ignore_then(super::parser(expression.clone())) + .then(expression.clone()) .map_with_span(|(text, then_), span| UntypedExpr::Trace { kind: TraceKind::Trace, location: span, @@ -19,17 +19,17 @@ pub fn parser() -> impl Parser { text: Box::new(super::string::flexible(text)), }), just(Token::ErrorTerm) - .ignore_then(super::parser(r.clone()).or_not()) + .ignore_then(super::parser(expression.clone()).or_not()) .map_with_span(|reason, span| { UntypedExpr::error(span, reason.map(super::string::flexible)) }), just(Token::Todo) - .ignore_then(super::parser(r.clone()).or_not()) + .ignore_then(super::parser(expression.clone()).or_not()) .map_with_span(|reason, span| { UntypedExpr::todo(span, reason.map(super::string::flexible)) }), - super::parser(r.clone()) - .then(r.repeated()) + super::parser(expression.clone()) + .then(expression.repeated()) .foldl(|current, next| current.append_in_sequence(next)), )) }) diff --git a/crates/aiken-lang/src/parser/expr/when/guard.rs b/crates/aiken-lang/src/parser/expr/when/guard.rs index 95459ebc..c7b445dd 100644 --- a/crates/aiken-lang/src/parser/expr/when/guard.rs +++ b/crates/aiken-lang/src/parser/expr/when/guard.rs @@ -6,7 +6,7 @@ use crate::{ }; pub fn parser() -> impl Parser { - recursive(|r| { + recursive(|expression| { let var_parser = select! { Token::Name { name } => name, Token::UpName { name } => name, @@ -19,7 +19,7 @@ pub fn parser() -> impl Parser impl Parser { - recursive(|r| { + recursive(|expression| { let record_constructor_pattern_arg_parser = choice(( select! {Token::Name {name} => name} .then_ignore(just(Token::Colon)) - .then(r.clone()) + .then(expression.clone()) .map_with_span(|(name, pattern), span| ast::CallArg { location: span, label: Some(name), @@ -37,7 +37,7 @@ pub fn parser() -> impl Parser { ) .delimited_by(just(Token::LeftBrace), just(Token::RightBrace)); - let tuple_constructor_pattern_arg_parser = r + let tuple_constructor_pattern_arg_parser = expression .clone() .map(|pattern| ast::CallArg { location: pattern.location(), @@ -121,7 +121,8 @@ pub fn parser() -> impl Parser { base, }, ), - r.clone() + expression + .clone() .separated_by(just(Token::Comma)) .allow_trailing() .delimited_by( @@ -133,10 +134,13 @@ pub fn parser() -> impl Parser { elems, }), just(Token::LeftSquare) - .ignore_then(r.clone().separated_by(just(Token::Comma))) + .ignore_then(expression.clone().separated_by(just(Token::Comma))) .then(choice(( - just(Token::Comma) - .ignore_then(just(Token::DotDot).ignore_then(r.clone().or_not()).or_not()), + just(Token::Comma).ignore_then( + just(Token::DotDot) + .ignore_then(expression.clone().or_not()) + .or_not(), + ), just(Token::Comma).ignored().or_not().map(|_| None), ))) .then_ignore(just(Token::RightSquare))