baseType()

in lib/parser.js [245:346]


  baseType() {
    if (this.look.tag === '[') {
      const start = this.look;
      this.move();
      const t = this.baseType();
      const end = this.look;
      this.match(']');
      return {
        type: 'array',
        subType: t,
        loc: {
          start: start.loc.start,
          end: end.loc.end
        },
      };
    }

    if (this.isWord(Tag.TYPE, 'map')) {
      let t = this.look;
      this.move();
      this.match('[');
      const keyType = this.baseType();
      this.match(']');
      const valueType = this.baseType();
      return {
        loc: {
          start: t.loc.start,
          end: valueType.loc.end
        },
        type: 'map',
        keyType: keyType,
        valueType: valueType
      };
    }

    if (this.isWord(Tag.TYPE, 'entry')) {
      let t = this.look;
      this.move();
      this.match('[');
      const valueType = this.baseType();
      this.match(']');
      return {
        loc: {
          start: t.loc.start,
          end: valueType.loc.end
        },
        type: 'entry',
        valueType: valueType
      };
    }

    if (this.isWord(Tag.TYPE, 'iterator') || this.isWord(Tag.TYPE, 'asyncIterator')) {
      let t = this.look;
      this.move();
      this.match('[');
      const valueType = this.baseType();
      this.match(']');
      return {
        loc: {
          start: t.loc.start,
          end: valueType.loc.end
        },
        type: t.lexeme,
        valueType: valueType
      };
    }

    if (this.is(Tag.ID)) {
      var t = this.look;
      this.move();
      // for A.B
      if (this.look.tag === '.') {
        const path = [t];
        let id;
        while (this.look.tag === '.') {
          this.move();
          id = this.look;
          path.push(id);
          this.match(Tag.ID);
        }

        return {
          type: 'subModel_or_moduleModel',
          path: path,
          loc: {
            start: t.loc.start,
            end: id.loc.end
          },
        };
      }

      return t;
    }

    if (this.is(Tag.TYPE)) {
      let t = this.look;
      this.move();
      return t;
    }

    this.error(`expect base type, model id or array form`);
  }