improve error recovery for var decls and simplify parser code.

Swift SVN r105
This commit is contained in:
Chris Lattner
2010-07-27 06:57:02 +00:00
parent 4cba5da90e
commit e842e93c89

View File

@@ -289,7 +289,9 @@ void Parser::ParseDeclAttributeList(DeclAttributes &Attributes) {
}
}
/// ParseDeclVar
/// ParseDeclVar - Parse a 'var' declaration, returning null (and doing no
/// token skipping) on error.
///
/// decl-var:
/// 'var' decl-attribute-list? identifier ':' type
/// 'var' decl-attribute-list? identifier ':' type '=' expression
@@ -303,25 +305,18 @@ VarDecl *Parser::ParseDeclVar() {
ParseDeclAttributeList(Attributes);
llvm::StringRef Identifier;
if (ParseIdentifier(Identifier, "expected identifier in var declaration")) {
// FIXME: Should stop at ',' when in a tuple argument.
SkipUntil(tok::semi);
if (ParseIdentifier(Identifier, "expected identifier in var declaration"))
return 0;
}
Type *Ty = 0;
if (ConsumeIf(tok::colon) &&
ParseType(Ty, "expected type in var declaration")) {
SkipUntil(tok::semi);
ParseType(Ty, "expected type in var declaration"))
return 0;
}
NullablePtr<Expr> Init;
if (ConsumeIf(tok::equal)) {
if (ParseExpr(Init, "expected expression in var declaration")) {
SkipUntil(tok::semi);
if (ParseExpr(Init, "expected expression in var declaration"))
return 0;
}
// If there was an expression, but it had a parse error, give the var decl
// an artificial int type to avoid chained errors.