array()

in lib/parser.js [1061:1102]


  array() {
    // array = "[" [ arrayItems ] "]"
    // arrayItems = expr { "," expr }
    const begin = this.getIndex();
    var start = this.lexer.loc();
    this.match('[');
    var items = [];
    if (this.look.tag === ']') {
      const end = this.getIndex();
      this.move();
      return {
        type: 'array',
        items: items,
        tokenRange: [begin, end]
      };
    }

    var item = this.expr();
    items.push(item);

    while (this.look.tag !== ']') {
      if (this.look.tag === ',') {
        this.move();
        let item = this.expr();
        items.push(item);
      } else {
        this.error('expect ","');
      }
    }
    const end = this.getIndex();
    this.match(']');

    return {
      type: 'array',
      items: items,
      loc: {
        start: start,
        end: this.lexer.loc()
      },
      tokenRange: [begin, end]
    };
  }