Make parserrors have token
This commit is contained in:
parent
d0c5dce92b
commit
f2f8ac7ee8
@ -848,40 +848,43 @@ impl Parser {
|
||||
|
||||
#[recursive_descent_method]
|
||||
fn simple_pattern(&mut self) -> ParseResult<Pattern> {
|
||||
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)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user