From 18c761a5b5a7746c92782785577da3a5d5267591 Mon Sep 17 00:00:00 2001 From: greg Date: Sat, 16 Sep 2017 14:34:37 -0700 Subject: [PATCH] Wrap all parse methods in record-printing macro --- src/schala_lang/parsing.rs | 62 +++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/src/schala_lang/parsing.rs b/src/schala_lang/parsing.rs index 8754235..d2ca1e1 100644 --- a/src/schala_lang/parsing.rs +++ b/src/schala_lang/parsing.rs @@ -440,7 +440,6 @@ impl Operation { } macro_rules! parse_method { - ($name:ident(&mut $self:ident) -> $type:ty $body:block) => { fn $name(&mut $self) -> $type { let next_token = $self.peek(); @@ -477,28 +476,28 @@ impl Parser { } }); - fn type_alias(&mut self) -> ParseResult { + parse_method!(type_alias(&mut self) -> ParseResult { expect!(self, Keyword(Alias), "Expected 'alias'"); let alias = self.identifier()?; expect!(self, Operator(ref c) if **c == "=", "Expected '='"); let original = self.identifier()?; Ok(Declaration::TypeAlias(alias, original)) - } + }); - fn type_declaration(&mut self) -> ParseResult { + parse_method!(type_declaration(&mut self) -> ParseResult { expect!(self, Keyword(Type), "Expected 'type'"); let name = self.identifier()?; expect!(self, Operator(ref c) if **c == "=", "Expected '='"); let body = self.type_body()?; Ok(Declaration::TypeDecl(name, body)) - } + }); - fn type_body(&mut self) -> ParseResult { + parse_method!(type_body(&mut self) -> ParseResult { let variant = Variant::Singleton(self.identifier()?); Ok(TypeBody(vec!(variant))) - } + }); - fn func_declaration(&mut self) -> ParseResult { + parse_method!(func_declaration(&mut self) -> ParseResult { expect!(self, Keyword(Func), "Expected 'fn'"); let name = self.identifier()?; expect!(self, LParen, "Expected '('"); @@ -509,11 +508,11 @@ impl Parser { params: params }; Ok(decl) - } + }); - fn param_list(&mut self) -> ParseResult { + parse_method!(param_list(&mut self) -> ParseResult { Ok(vec!()) - } + }); parse_method!(expression(&mut self) -> ParseResult { self.precedence_expr(Operation::min_precedence()) @@ -545,20 +544,20 @@ impl Parser { Ok(lhs) } - fn primary(&mut self) -> ParseResult { + parse_method!(primary(&mut self) -> ParseResult { match self.peek() { LParen => self.paren_expr(), Identifier(_) => self.identifier_expr(), _ => self.literal(), } - } + }); - fn paren_expr(&mut self) -> ParseResult { + parse_method!(paren_expr(&mut self) -> ParseResult { expect!(self, LParen, "Expected '('"); let expr = self.expression()?; expect!(self, RParen, "Expected ')'"); Ok(expr) - } + }); fn identifier_expr(&mut self) -> ParseResult { let identifier = self.identifier()?; @@ -581,7 +580,7 @@ impl Parser { } } - fn call_expr(&mut self) -> ParseResult> { + parse_method!(call_expr(&mut self) -> ParseResult> { let mut exprs = Vec::new(); expect!(self, LParen, "Expected '('"); loop { @@ -596,9 +595,9 @@ impl Parser { } expect!(self, RParen, "Expected ')'"); Ok(exprs) - } + }); - fn index_expr(&mut self) -> ParseResult> { + parse_method!(index_expr(&mut self) -> ParseResult> { expect!(self, LSquareBracket, "Expected '['"); let mut exprs = Vec::new(); loop { @@ -613,29 +612,30 @@ impl Parser { } expect!(self, RSquareBracket, "Expected ']'"); Ok(exprs) - } + }); - fn identifier(&mut self) -> ParseResult> { + parse_method!(identifier(&mut self) -> ParseResult> { match self.next() { Identifier(s) => Ok(s), p => ParseError::new(&format!("Expected an identifier, got {:?}", p)), } - } + }); - fn literal(&mut self) -> ParseResult { + parse_method!(literal(&mut self) -> ParseResult { match self.peek() { DigitGroup(_) | HexNumberSigil | BinNumberSigil | Period => self.number_literal(), t => panic!("trying to parse {:?}", t), - } } - fn number_literal(&mut self) -> ParseResult { + }); + + parse_method!(number_literal(&mut self) -> ParseResult { match self.peek() { HexNumberSigil | BinNumberSigil => self.int_literal(), _ => self.float_literal(), } - } + }); - fn int_literal(&mut self) -> ParseResult { + parse_method!(int_literal(&mut self) -> ParseResult { use self::Expression::*; match self.next() { BinNumberSigil => { @@ -648,9 +648,9 @@ impl Parser { }, _ => return ParseError::new("Expected '0x' or '0b'"), } - } + }); - fn float_literal(&mut self) -> ParseResult { + parse_method!(float_literal(&mut self) -> ParseResult { use self::Expression::*; let mut digits = self.digits()?; if let TokenType::Period = self.peek() { @@ -668,9 +668,9 @@ impl Parser { Err(e) => unimplemented!("Need to handle numbers that don't parse to a Rust u64 {}", e), } } - } + }); - fn digits(&mut self) -> ParseResult { + parse_method!(digits(&mut self) -> ParseResult { let mut ds = String::new(); loop { match self.peek() { @@ -680,7 +680,7 @@ impl Parser { } } Ok(ds) - } + }); } fn parse_binary(digits: String) -> ParseResult {