From f3e384352860380e28e00d5dd2da290312300fb3 Mon Sep 17 00:00:00 2001 From: greg Date: Sun, 13 May 2018 02:50:43 -0700 Subject: [PATCH] Decomplexify delimited! --- schala-lang/src/parsing.rs | 46 +++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/schala-lang/src/parsing.rs b/schala-lang/src/parsing.rs index ca9c2f7..f775c9a 100644 --- a/schala-lang/src/parsing.rs +++ b/schala-lang/src/parsing.rs @@ -324,13 +324,13 @@ macro_rules! parse_method { } macro_rules! delimited { - ($self:expr, $start:pat, $start_str:expr, $parse_fn:ident, $( $delim:pat )|+, $end:pat, $end_str:expr, nonstrict) => { - delimited!($self, $start, $start_str, $parse_fn, $( $delim )|*, $end, $end_str, false) + ($self:expr, $start:pat, $parse_fn:ident, $( $delim:pat )|+, $end:pat, nonstrict) => { + delimited!($self, $start, $parse_fn, $( $delim )|*, $end, false) }; - ($self:expr, $start:pat, $start_str:expr, $parse_fn:ident, $( $delim:pat )|+, $end:pat, $end_str:expr) => { - delimited!($self, $start, $start_str, $parse_fn, $( $delim )|*, $end, $end_str, true) + ($self:expr, $start:pat, $parse_fn:ident, $( $delim:pat )|+, $end:pat) => { + delimited!($self, $start, $parse_fn, $( $delim )|*, $end, true) }; - ($self:expr, $start:pat, $start_str:expr, $parse_fn:ident, $( $delim:pat )|+, $end:pat, $end_str:expr, $strictness:expr) => { + ($self:expr, $start:pat, $parse_fn:ident, $( $delim:pat )|+, $end:pat, $strictness:expr) => { { expect!($self, $start); let mut acc = vec![]; @@ -431,11 +431,11 @@ impl Parser { let name = self.identifier()?; match self.peek() { LParen => { - let tuple_members = delimited!(self, LParen, '(', type_name, Comma, RParen, ')'); + let tuple_members = delimited!(self, LParen, type_name, Comma, RParen); Ok(TupleStruct(name, tuple_members)) }, LCurlyBrace => { - let typed_identifier_list = delimited!(self, LCurlyBrace, '{', typed_identifier, Comma, RCurlyBrace, '}'); + let typed_identifier_list = delimited!(self, LCurlyBrace, typed_identifier, Comma, RCurlyBrace); Ok(Record(name, typed_identifier_list)) }, _ => Ok(UnitStruct(name)) @@ -452,7 +452,7 @@ impl Parser { parse_method!(func_declaration(&mut self) -> ParseResult { let signature = self.signature()?; if let LCurlyBrace = self.peek() { - let statements = delimited!(self, LCurlyBrace, '{', statement, Newline | Semicolon, RCurlyBrace, '}', nonstrict); + let statements = delimited!(self, LCurlyBrace, statement, Newline | Semicolon, RCurlyBrace, nonstrict); Ok(Declaration::FuncDecl(signature, statements)) } else { Ok(Declaration::FuncSig(signature)) @@ -462,7 +462,7 @@ impl Parser { parse_method!(signature(&mut self) -> ParseResult { expect!(self, Keyword(Func)); let name = self.identifier()?; - let params = delimited!(self, LParen, '(', formal_param, Comma, RParen, ')'); + let params = delimited!(self, LParen, formal_param, Comma, RParen); let type_anno = match self.peek() { Colon => Some(self.type_anno()?), _ => None, @@ -500,7 +500,7 @@ impl Parser { }); parse_method!(signature_block(&mut self) -> ParseResult> { - Ok(delimited!(self, LCurlyBrace, '{', signature, Newline | Semicolon, RCurlyBrace, '}', nonstrict)) + Ok(delimited!(self, LCurlyBrace, signature, Newline | Semicolon, RCurlyBrace, nonstrict)) }); parse_method!(impl_declaration(&mut self) -> ParseResult { @@ -529,7 +529,7 @@ impl Parser { }); parse_method!(decl_block(&mut self) -> ParseResult> { - Ok(delimited!(self, LCurlyBrace, '{', func_declaration, Newline | Semicolon, RCurlyBrace, '}', nonstrict)) + Ok(delimited!(self, LCurlyBrace, func_declaration, Newline | Semicolon, RCurlyBrace, nonstrict)) }); parse_method!(expression(&mut self) -> ParseResult { @@ -553,7 +553,7 @@ impl Parser { parse_method!(type_name(&mut self) -> ParseResult { use self::TypeName::*; Ok(match self.peek() { - LParen => Tuple(delimited!(self, LParen, '(', type_name, Comma, RParen, ')')), + LParen => Tuple(delimited!(self, LParen, type_name, Comma, RParen)), _ => Singleton(self.type_singleton_name()?), }) }); @@ -562,7 +562,7 @@ impl Parser { Ok(TypeSingletonName { name: self.identifier()?, params: match self.peek() { - LAngleBracket => delimited!(self, LAngleBracket, '<', type_name, Comma, RAngleBracket, '>'), + LAngleBracket => delimited!(self, LAngleBracket, type_name, Comma, RAngleBracket), _ => vec![], } }) @@ -625,7 +625,7 @@ impl Parser { parse_method!(call_expr(&mut self) -> ParseResult { let index = self.index_expr()?; Ok(if let LParen = self.peek() { - let arguments = delimited!(self, LParen, ')', expression, Comma, RParen, '('); + let arguments = delimited!(self, LParen, expression, Comma, RParen); Expression(ExpressionType::Call { f: bx!(index), arguments }, None) //TODO fix this none } else { index @@ -635,7 +635,7 @@ impl Parser { parse_method!(index_expr(&mut self) -> ParseResult { let primary = self.primary()?; Ok(if let LSquareBracket = self.peek() { - let indexers = delimited!(self, LSquareBracket, '[', expression, Comma, RSquareBracket, ']'); + let indexers = delimited!(self, LSquareBracket, expression, Comma, RSquareBracket); Expression(ExpressionType::Index { indexee: bx!(Expression(primary.0, None)), indexers, @@ -660,7 +660,7 @@ impl Parser { }); parse_method!(list_expr(&mut self) -> ParseResult { - let exprs = delimited!(self, LSquareBracket, '[', expression, Comma, RSquareBracket, ']'); + let exprs = delimited!(self, LSquareBracket, expression, Comma, RSquareBracket); Ok(Expression(ExpressionType::ListLiteral(exprs), None)) }); @@ -670,7 +670,7 @@ impl Parser { parse_method!(lambda_expr(&mut self) -> ParseResult { expect!(self, LCurlyBrace); - let params = delimited!(self, Pipe, '|', formal_param, Comma, Pipe, '|'); + let params = delimited!(self, Pipe, formal_param, Comma, Pipe); let mut body = Vec::new(); loop { match self.peek() { @@ -691,7 +691,7 @@ impl Parser { let old_struct_value = self.restrictions.no_struct_literal; self.restrictions.no_struct_literal = false; let output = { - let mut inner = delimited!(self, LParen, '(', expression, Comma, RParen, ')'); + let mut inner = delimited!(self, LParen, expression, Comma, RParen); match inner.len() { 0 => Ok(Expression(TupleLiteral(vec![]), None)), 1 => Ok(inner.pop().unwrap()), @@ -715,7 +715,7 @@ impl Parser { }); parse_method!(record_block(&mut self) -> ParseResult, Expression)>> { - Ok(delimited!(self, LCurlyBrace, '{', record_entry, Comma, RCurlyBrace, '}')) + Ok(delimited!(self, LCurlyBrace, record_entry, Comma, RCurlyBrace)) }); parse_method!(record_entry(&mut self) -> ParseResult<(Rc, Expression)> { @@ -748,7 +748,7 @@ impl Parser { }); parse_method!(block(&mut self) -> ParseResult { - Ok(delimited!(self, LCurlyBrace, '{', statement, Newline | Semicolon, RCurlyBrace, '}', nonstrict)) + Ok(delimited!(self, LCurlyBrace, statement, Newline | Semicolon, RCurlyBrace, nonstrict)) }); parse_method!(match_expr(&mut self) -> ParseResult { @@ -762,7 +762,7 @@ impl Parser { }); parse_method!(match_body(&mut self) -> ParseResult> { - Ok(delimited!(self, LCurlyBrace, '{', match_arm, Comma, RCurlyBrace, '}')) + Ok(delimited!(self, LCurlyBrace, match_arm, Comma, RCurlyBrace)) }); parse_method!(match_arm(&mut self) -> ParseResult { @@ -800,7 +800,7 @@ impl Parser { parse_method!(for_expr(&mut self) -> ParseResult { expect!(self, Keyword(Kw::For)); let enumerators = if let LCurlyBrace = self.peek() { - delimited!(self, LCurlyBrace, '{', enumerator, Comma | Newline, RCurlyBrace, '}') + delimited!(self, LCurlyBrace, enumerator, Comma | Newline, RCurlyBrace) } else { let single_enum = { self.restrictions.no_struct_literal = true; @@ -825,7 +825,7 @@ impl Parser { use self::ForBody::*; Ok(match self.peek() { LCurlyBrace => { - let statements = delimited!(self, LCurlyBrace, '{', statement, Newline | Semicolon, RCurlyBrace, '}', nonstrict); + let statements = delimited!(self, LCurlyBrace, statement, Newline | Semicolon, RCurlyBrace, nonstrict); StatementBlock(statements) }, Keyword(Kw::Return) => {