Changing how patterns work
to support qualified names in patterns
This commit is contained in:
parent
24e0ecbe73
commit
c04e4356a1
@ -230,8 +230,9 @@ pub enum Pattern {
|
||||
Ignored,
|
||||
TuplePattern(Vec<Pattern>),
|
||||
Literal(PatternLiteral),
|
||||
TupleStruct(Rc<String>, Vec<Pattern>),
|
||||
Record(Rc<String>, Vec<(Rc<String>, Pattern)>),
|
||||
TupleStruct(QualifiedName, Vec<Pattern>),
|
||||
Record(QualifiedName, Vec<(Rc<String>, Pattern)>),
|
||||
VarOrName(QualifiedName),
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
@ -242,8 +243,6 @@ pub enum PatternLiteral {
|
||||
},
|
||||
StringPattern(Rc<String>),
|
||||
BoolPattern(bool),
|
||||
//TODO I think VarPattern also needs to know about FQSNs
|
||||
VarPattern(QualifiedName)
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
|
@ -936,13 +936,15 @@ impl Parser {
|
||||
let qualified_name = self.qualified_name()?;
|
||||
match self.token_handler.peek_kind() {
|
||||
LCurlyBrace => {
|
||||
|
||||
let members = delimited!(self, LCurlyBrace, record_pattern_entry, Comma, RCurlyBrace);
|
||||
Pattern::Record(qualified_name, members)
|
||||
},
|
||||
LParen => {
|
||||
|
||||
let members = delimited!(self, LParen, pattern, Comma, RParen);
|
||||
Pattern::TupleStruct(qualified_name, members)
|
||||
},
|
||||
_ => {
|
||||
|
||||
Pattern::VarPattern(qualified_name)
|
||||
},
|
||||
}
|
||||
},
|
||||
@ -950,6 +952,31 @@ impl Parser {
|
||||
}
|
||||
}
|
||||
|
||||
#[recursive_descent_method]
|
||||
fn pattern_literal(&mut self) -> ParseResult<Pattern> {
|
||||
match self.token_handler.peek_kind() {
|
||||
Keyword(Kw::True) => {
|
||||
self.token_handler.next();
|
||||
Pattern::Literal(PatternLiteral::BoolPattern(true))
|
||||
},
|
||||
Keyword(Kw::False) => {
|
||||
self.token_handler.next();
|
||||
Pattern::Literal(PatternLiteral::BoolPattern(false))
|
||||
},
|
||||
StrLiteral(s) => {
|
||||
self.token_handler.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.token_handler.next();
|
||||
Pattern::Ignored
|
||||
},
|
||||
other => return ParseError::new_with_token(format!("{:?} is not a valid Pattern", other), tok)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
#[recursive_descent_method]
|
||||
fn simple_pattern(&mut self) -> ParseResult<Pattern> {
|
||||
|
Loading…
Reference in New Issue
Block a user