bodyStmt method

List<Stmt> bodyStmt({
  1. TokenType? terminal,
  2. List<TokenType>? terminals,
})

Implementation

List<Stmt> bodyStmt({TokenType? terminal, List<TokenType>? terminals}) {
  assert(
    (terminal != null) ^ (terminals != null),
    'Expected a single terminal or list of terminals.',
  );

  if (terminal != null) {
    terminals = [terminal];
  }
  // B/c of the steps above, it must be the case
  // that the list is not null.
  terminals!;

  final List<Stmt> stmts = [];
  while (!eof() && !terminals.contains(peek().type)) {
    try {
      final s = stmt();
      if (s == null) continue;
      stmts.add(s);
    } catch (e) {
      addError(e.toString());
      advance();
    }
  }

  return stmts;
}