Parse: Stub out parsing of matching patterns using expr parser.

Add a parseMatchingPattern method that just calls down to the expr parser and shoves the expr in an ExprPattern. We'll augment the expr parser with matching pattern productions soon.

Swift SVN r5833
This commit is contained in:
Joe Groff
2013-06-27 05:13:37 +00:00
parent 10f136f7d3
commit 2cfd14b4c0
2 changed files with 16 additions and 1 deletions

View File

@@ -375,7 +375,7 @@ Optional<TuplePatternElt> Parser::parsePatternTupleElement(bool allowInitExpr) {
/// Parse a tuple pattern.
///
/// pattern-tuple:
//// '(' pattern-tuple-body? ')'
/// '(' pattern-tuple-body? ')'
/// pattern-tuple-body:
/// pattern-tuple-element (',' pattern-tuple-body)*
@@ -422,3 +422,17 @@ NullablePtr<Pattern> Parser::parsePatternTuple(bool AllowInitExpr) {
return TuplePattern::create(Context, LPLoc, elts, RPLoc);
}
NullablePtr<Pattern> Parser::parseMatchingPattern() {
// TODO: Since we expect a pattern in this position, we should optimistically
// parse pattern nodes for shared productions. For ease of initial
// implementation, for now we always go through the expr parser and let name
// binding determine what productions are really patterns.
NullablePtr<Expr> subExpr = parseExpr(diag::expected_pattern);
if (subExpr.isNull())
return nullptr;
return new (Context) ExprPattern(subExpr.get(),
/*isResolved*/ false,
/*matchExpr*/ nullptr);
}