const AstNode = require('./ast-node');

class FilterChain extends AstNode {
  type() {
    return 'filter_chain';
  }

  /**
   * @param {ParseContext} context
   * @return {boolean}
   */
  read(context) {
    return true;
  }

  /**
   * @param {ParseContext} context
   * @return {AstNodeParseResult}
   */
  parse(context) {
    const config = context.config();
    const tm = context.sourceTextManager();
    const filters = [];

    while (!tm.eof()) {
      tm.whitespace();

      if (!tm.charIs('|')) {
        break;
      }

      tm.next('|');
      tm.whitespace();

      filters.push(context.parse('filter'));

      if (tm.charIs(config.closeDelimiter())) {
        break;
      }
    }

    return {
      type: this.type(),
      filters: filters,
    };
  }
}

module.exports = FilterChain;

const AstNode = require('./ast-node');

class FilterChain extends AstNode {
  type() {
    return 'filter_chain';
  }

  /**
   * @param {ParseContext} context
   * @return {boolean}
   */
  read(context) {
    return true;
  }

  /**
   * @param {ParseContext} context
   * @return {AstNodeParseResult}
   */
  parse(context) {
    const config = context.config();
    const tm = context.sourceTextManager();
    const filters = [];

    tm.whitespace();

    while (tm.charIs('|')) {
      tm.next('|');
      tm.whitespace();
      filters.push(context.parse('filter'));
      tm.whitespace();

      if (tm.charIs(config.closeDelimiter())) {
        break;
      }
    }

    return {
      type: this.type(),
      filters: filters,
    };
  }
}

module.exports = FilterChain;

Modify main loop code of FilterChain.parse()