parse method

List<Declaration> parse()

Implementation

List<Declaration> parse() {
  final body = <Declaration>[];

  while (_isNotAtEnd) {
    final declaration = _declaration();

    if (declaration != null) {
      if (body.isNotEmpty && declaration is ImportDeclaration && body[body.length - 1] is! ImportDeclaration) {
        final error = ExpectAfterError(
          syntacticEntity: declaration,
          expectation: ExpectationType.token(token: TokenType.typeKeyword),
          after: ExpectationType.declaration(declaration: declaration),
        );

        _errorHandler?.emit(error);
      }

      body.add(declaration);
    }
  }

  return body;
}