object()

in lib/parser.js [1104:1155]


  object() {
    // object = "{" [ objectFields ] "}"
    // objectFields = objectField { "," objectField } [","]
    const begin = this.getIndex();
    var start = this.lexer.loc();
    this.match('{');

    var fields = [];
    if (this.look.tag === '}') {
      const end = this.getIndex();
      this.move();
      return {
        type: 'object',
        fields: fields,
        loc: {
          start: start,
          end: this.lexer.loc()
        },
        tokenRange: [begin, end]
      };
    }

    var field = this.objectField();
    fields.push(field);

    while (this.look.tag !== '}') {
      if (this.look.tag === ',') {
        this.move();

        if (this.look.tag === '}') {
          // only one fields
          break;
        }
        let field = this.objectField();
        fields.push(field);
      } else {
        this.error('expect ","');
      }
    }
    const end = this.getIndex();
    this.match('}');

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