seq method

  1. @useResult
Parser<List> seq(
  1. Parser other
)

Returns a parser that accepts the receiver followed by other.

The resulting parser produces a flattened List containing the result of the receiver followed by the result of other. If called on an existing SequenceParser, this flattens other into the sequence rather than nesting a new sequence within it.

For example, the parser letter().seq(digit().map(int.parse)).seq(letter()) accepts a letter followed by a digit and another letter. For the input 'a1b', it evaluates to <dynamic>['a', 1, 'b'].

The resulting list element type is dynamic. For compile-time type safety, prefer using then, seq2, or seq3.

Implementation

@useResult
Parser<List<dynamic>> seq(Parser other) => switch (this) {
  SequenceParser(children: final children) => [
    ...children,
    other,
  ].toSequenceParser(),
  _ => [this, other].toSequenceParser(),
};