Make parserrors have token

This commit is contained in:
greg 2019-01-05 17:32:49 -08:00
parent d0c5dce92b
commit f2f8ac7ee8

View File

@ -848,40 +848,43 @@ impl Parser {
#[recursive_descent_method] #[recursive_descent_method]
fn simple_pattern(&mut self) -> ParseResult<Pattern> { fn simple_pattern(&mut self) -> ParseResult<Pattern> {
Ok(match self.peek() { Ok({
Identifier(_) => { let tok = self.token_handler.peek_token();
let id = self.identifier()?; match tok.get_kind() {
match self.peek() { Identifier(_) => {
LCurlyBrace => { let id = self.identifier()?;
let members = delimited!(self, LCurlyBrace, record_pattern_entry, Comma, RCurlyBrace); match self.peek() {
Pattern::Record(id, members) LCurlyBrace => {
}, let members = delimited!(self, LCurlyBrace, record_pattern_entry, Comma, RCurlyBrace);
LParen => { Pattern::Record(id, members)
let members = delimited!(self, LParen, pattern, Comma, RParen); },
Pattern::TupleStruct(id, members) LParen => {
}, let members = delimited!(self, LParen, pattern, Comma, RParen);
_ => Pattern::Literal(PatternLiteral::VarPattern(id)) Pattern::TupleStruct(id, members)
} },
}, _ => Pattern::Literal(PatternLiteral::VarPattern(id))
Keyword(Kw::True) => { }
self.next(); },
Pattern::Literal(PatternLiteral::BoolPattern(true)) Keyword(Kw::True) => {
}, self.next();
Keyword(Kw::False) => { Pattern::Literal(PatternLiteral::BoolPattern(true))
self.next(); },
Pattern::Literal(PatternLiteral::BoolPattern(false)) Keyword(Kw::False) => {
}, self.next();
StrLiteral(s) => { Pattern::Literal(PatternLiteral::BoolPattern(false))
self.next(); },
Pattern::Literal(PatternLiteral::StringPattern(s)) StrLiteral(s) => {
}, self.next();
DigitGroup(_) | HexLiteral(_) | BinNumberSigil | Period => self.signed_number_literal()?, Pattern::Literal(PatternLiteral::StringPattern(s))
Operator(ref op) if **op == "-" => self.signed_number_literal()?, },
Underscore => { DigitGroup(_) | HexLiteral(_) | BinNumberSigil | Period => self.signed_number_literal()?,
self.next(); Operator(ref op) if **op == "-" => self.signed_number_literal()?,
Pattern::Ignored Underscore => {
}, self.next();
other => return ParseError::new(&format!("{:?} is not a valid Pattern", other)) Pattern::Ignored
},
other => return ParseError::new_with_token(&format!("{:?} is not a valid Pattern", other), tok)
}
}) })
} }