Commit d910e90e authored by Robert Griesemer's avatar Robert Griesemer

- heuristics for parsing composite literals in some cases

- fixed result parsing of function types

R=r
OCL=15585
CL=15585
parent b90b213e
...@@ -275,13 +275,33 @@ func (P *Parser) ParseParameters() int { ...@@ -275,13 +275,33 @@ func (P *Parser) ParseParameters() int {
} }
func (P *Parser) ParseResultList() {
P.Trace("ResultList");
P.ParseType();
for P.tok == Scanner.COMMA {
P.Next();
P.ParseType();
}
if P.tok != Scanner.RPAREN {
P.ParseType();
}
P.Ecart();
}
func (P *Parser) ParseResult() { func (P *Parser) ParseResult() {
P.Trace("Result"); P.Trace("Result");
if P.tok == Scanner.LPAREN { if P.tok == Scanner.LPAREN {
// one or more named results P.Next();
// TODO: here we allow empty returns - should probably fix this P.ParseResultList();
P.ParseParameters(); for P.tok == Scanner.COMMA {
P.Next();
P.ParseResultList();
}
P.Expect(Scanner.RPAREN);
} else { } else {
// anonymous result // anonymous result
...@@ -503,8 +523,6 @@ func (P *Parser) ParseExpressionPairList() { ...@@ -503,8 +523,6 @@ func (P *Parser) ParseExpressionPairList() {
func (P *Parser) ParseCompositeLit() AST.Expr { func (P *Parser) ParseCompositeLit() AST.Expr {
P.Trace("CompositeLit"); P.Trace("CompositeLit");
P.Expect(Scanner.HASH);
P.ParseType();
P.Expect(Scanner.LBRACE); P.Expect(Scanner.LBRACE);
// TODO: should allow trailing ',' // TODO: should allow trailing ','
if P.tok != Scanner.RBRACE { if P.tok != Scanner.RBRACE {
...@@ -549,9 +567,6 @@ func (P *Parser) ParseOperand(ident *AST.Ident) AST.Expr { ...@@ -549,9 +567,6 @@ func (P *Parser) ParseOperand(ident *AST.Ident) AST.Expr {
} else { } else {
switch P.tok { switch P.tok {
case Scanner.IDENT:
panic("UNREACHABLE");
case Scanner.LPAREN: case Scanner.LPAREN:
P.Next(); P.Next();
x = P.ParseExpression(); x = P.ParseExpression();
...@@ -570,11 +585,17 @@ func (P *Parser) ParseOperand(ident *AST.Ident) AST.Expr { ...@@ -570,11 +585,17 @@ func (P *Parser) ParseOperand(ident *AST.Ident) AST.Expr {
P.ParseFunctionLit(); P.ParseFunctionLit();
case Scanner.HASH: case Scanner.HASH:
P.Next();
P.ParseType();
P.ParseCompositeLit(); P.ParseCompositeLit();
default: default:
P.Error(P.pos, "operand expected"); if P.tok != Scanner.IDENT && P.TryType() {
P.Next(); // make progress P.ParseCompositeLit();
} else {
P.Error(P.pos, "operand expected");
P.Next(); // make progress
}
} }
} }
...@@ -1152,14 +1173,14 @@ func (P *Parser) ParseDecl(exported bool, keyword int) { ...@@ -1152,14 +1173,14 @@ func (P *Parser) ParseDecl(exported bool, keyword int) {
P.Expect(keyword); P.Expect(keyword);
if P.tok == Scanner.LPAREN { if P.tok == Scanner.LPAREN {
P.Next(); P.Next();
for P.tok == Scanner.IDENT { for P.tok != Scanner.RPAREN {
P.ParseSpec(exported, keyword); P.ParseSpec(exported, keyword);
if P.tok != Scanner.RPAREN { if P.tok != Scanner.RPAREN {
// P.Expect(Scanner.SEMICOLON); // P.Expect(Scanner.SEMICOLON);
P.Optional(Scanner.SEMICOLON); // TODO this seems wrong! (needed for math.go) P.Optional(Scanner.SEMICOLON); // TODO this seems wrong! (needed for math.go)
} }
} }
P.Next(); P.Next(); // consume ")"
} else { } else {
P.ParseSpec(exported, keyword); P.ParseSpec(exported, keyword);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment