From f2f8ac7ee86c9b94ad7c31a650b17b02af774666 Mon Sep 17 00:00:00 2001 From: greg Date: Sat, 5 Jan 2019 17:32:49 -0800 Subject: [PATCH] Make parserrors have token --- schala-lang/language/src/parsing.rs | 71 +++++++++++++++-------------- 1 file changed, 37 insertions(+), 34 deletions(-) diff --git a/schala-lang/language/src/parsing.rs b/schala-lang/language/src/parsing.rs index 224c732..cce6c6e 100644 --- a/schala-lang/language/src/parsing.rs +++ b/schala-lang/language/src/parsing.rs @@ -848,40 +848,43 @@ impl Parser { #[recursive_descent_method] fn simple_pattern(&mut self) -> ParseResult { - Ok(match self.peek() { - Identifier(_) => { - let id = self.identifier()?; - match self.peek() { - LCurlyBrace => { - let members = delimited!(self, LCurlyBrace, record_pattern_entry, Comma, RCurlyBrace); - Pattern::Record(id, members) - }, - LParen => { - let members = delimited!(self, LParen, pattern, Comma, RParen); - Pattern::TupleStruct(id, members) - }, - _ => Pattern::Literal(PatternLiteral::VarPattern(id)) - } - }, - Keyword(Kw::True) => { - self.next(); - Pattern::Literal(PatternLiteral::BoolPattern(true)) - }, - Keyword(Kw::False) => { - self.next(); - Pattern::Literal(PatternLiteral::BoolPattern(false)) - }, - StrLiteral(s) => { - self.next(); - Pattern::Literal(PatternLiteral::StringPattern(s)) - }, - DigitGroup(_) | HexLiteral(_) | BinNumberSigil | Period => self.signed_number_literal()?, - Operator(ref op) if **op == "-" => self.signed_number_literal()?, - Underscore => { - self.next(); - Pattern::Ignored - }, - other => return ParseError::new(&format!("{:?} is not a valid Pattern", other)) + Ok({ + let tok = self.token_handler.peek_token(); + match tok.get_kind() { + Identifier(_) => { + let id = self.identifier()?; + match self.peek() { + LCurlyBrace => { + let members = delimited!(self, LCurlyBrace, record_pattern_entry, Comma, RCurlyBrace); + Pattern::Record(id, members) + }, + LParen => { + let members = delimited!(self, LParen, pattern, Comma, RParen); + Pattern::TupleStruct(id, members) + }, + _ => Pattern::Literal(PatternLiteral::VarPattern(id)) + } + }, + Keyword(Kw::True) => { + self.next(); + Pattern::Literal(PatternLiteral::BoolPattern(true)) + }, + Keyword(Kw::False) => { + self.next(); + Pattern::Literal(PatternLiteral::BoolPattern(false)) + }, + StrLiteral(s) => { + self.next(); + Pattern::Literal(PatternLiteral::StringPattern(s)) + }, + DigitGroup(_) | HexLiteral(_) | BinNumberSigil | Period => self.signed_number_literal()?, + Operator(ref op) if **op == "-" => self.signed_number_literal()?, + Underscore => { + self.next(); + Pattern::Ignored + }, + other => return ParseError::new_with_token(&format!("{:?} is not a valid Pattern", other), tok) + } }) }