src/compiler/Parser.cpp
changeset 212 443d24cfdf2d
parent 209 5cbec15fadfe
child 220 5df4a112967d
     1.1 --- a/src/compiler/Parser.cpp	Sat Nov 17 23:13:39 2012 -0800
     1.2 +++ b/src/compiler/Parser.cpp	Sun Nov 18 14:53:23 2012 -0800
     1.3 @@ -139,30 +139,21 @@
     1.4  }
     1.5  
     1.6  Expression *
     1.7 -Parser::arrayLiteral(TokenKind kind)
     1.8 +Parser::fixedArrayLiteral()
     1.9  {
    1.10 -    assert(kind == TOK_LBRACE || kind == TOK_LBRACKET);
    1.11 -
    1.12 -    TokenKind close = (kind == TOK_LBRACE)
    1.13 -                      ? TOK_RBRACE
    1.14 -                      : TOK_RBRACKET;
    1.15 -
    1.16      SourcePosition pos = scanner_.begin();
    1.17  
    1.18      ExpressionList *list = new (pool_) ExpressionList();
    1.19      do {
    1.20 -        if (match(close))
    1.21 +        // { } is an illegal array literal.
    1.22 +        if (list->length() > 0 && match(TOK_LBRACE))
    1.23              break;
    1.24  
    1.25          Expression *expr = NULL;
    1.26 -        if (kind == TOK_LBRACE) {
    1.27 -            if (peek(TOK_LBRACE))
    1.28 -                expr = arrayLiteral(TOK_LBRACE);
    1.29 -            else
    1.30 -                expr = primitive();
    1.31 -        } else {
    1.32 -            expr = expression();
    1.33 -        }
    1.34 +        if (peek(TOK_LBRACE))
    1.35 +            expr = fixedArrayLiteral();
    1.36 +        else
    1.37 +            expr = primitive();
    1.38          if (!expr)
    1.39              return NULL;
    1.40  
    1.41 @@ -170,13 +161,13 @@
    1.42              return NULL;
    1.43  
    1.44          if (!match(TOK_COMMA)) {
    1.45 -            if (!expect(close))
    1.46 +            if (!expect(TOK_RBRACE))
    1.47                  return NULL;
    1.48              break;
    1.49          }
    1.50      } while (true);
    1.51  
    1.52 -    return new (pool_) ArrayLiteral(pos, kind, list);
    1.53 +    return new (pool_) ArrayLiteral(pos, TOK_LBRACE, list);
    1.54  }
    1.55  
    1.56  Expression *
    1.57 @@ -882,7 +873,7 @@
    1.58          return NULL;
    1.59  
    1.60      ExpressionList *dims = NULL;
    1.61 -    if (match(TOK_LBRACE)) {
    1.62 +    if (peek(TOK_LBRACKET)) {
    1.63          if ((dims = dimensions()) == NULL)
    1.64              return NULL;;
    1.65      }
    1.66 @@ -894,7 +885,8 @@
    1.67          switch (scanner_.peek()) {
    1.68            // Note: we don't support [] literals yet.
    1.69            case TOK_LBRACE:
    1.70 -            if ((expr = arrayLiteral(scanner_.scan())) == NULL)
    1.71 +            scanner_.scan();
    1.72 +            if ((expr = fixedArrayLiteral()) == NULL)
    1.73                  return NULL;
    1.74              break;
    1.75