emitMap()

in src/langs/swift/combinator.js [331:382]


  emitMap(emitter, gram) {
    let items = [];
    let expandItems = [];
    if (!Array.isArray(gram.value) && !(gram.value instanceof GrammerValue)) {
      this.grammer(emitter, gram.value, false, false);
      return;
    }
    items = gram.value.filter(i => !i.isExpand);
    expandItems = gram.value.filter(i => i.isExpand);
    if (!items.length && !expandItems.length) {
      emitter.emit('[:]');
      return;
    }
    if (expandItems.length) {
      emitter.emit(`${this.config.tea.converter.name}.${this.config.tea.converter.merge}(`);
    }
    if (items.length) {
      emitter.emitln('[');
      this.levelUp();
      items.forEach((item, index) => {
        let emit = new Emitter(this.config);
        if (item instanceof AnnotationItem) {
          this.emitAnnotation(emit, item, 0);
          return;
        }
        this.grammer(emit, item, false, false);
        emitter.emit(`"${item.key}": ${emit.output}`, this.level);
        if (index !== items.length - 1) {
          emitter.emit(',');
        }
        emitter.emitln();
      });
      this.levelDown();
      emitter.emit(']', this.level);
    } else {
      emitter.emit('[:]');
    }
    if (expandItems.length) {
      expandItems.forEach((item, index) => {
        let emit = new Emitter(this.config);
        if (item instanceof AnnotationItem) {
          this.emitAnnotation(emit, item, 0);
          return;
        }
        this.grammer(emit, item, false, false, true);
        emitter.emit(`, ${emit.output}`);
      });
    }
    if (expandItems.length) {
      emitter.emit(')');
    }
  }