parseDocument function Null safety

Document? parseDocument(
  1. String text,
  2. {dynamic sourceUrl,
  3. bool asDSX = false,
  4. void onError(
    1. JaelError error
    )?}
)

Parses a Jael document.

Implementation

Document? parseDocument(String text,
    {sourceUrl, bool asDSX = false, void Function(JaelError error)? onError}) {
  var scanner = scan(text, sourceUrl: sourceUrl, asDSX: asDSX);

  //scanner.tokens.forEach(print);

  if (scanner.errors.isNotEmpty && onError != null) {
    scanner.errors.forEach(onError);
  } else if (scanner.errors.isNotEmpty) {
    throw scanner.errors.first;
  }

  var parser = Parser(scanner, asDSX: asDSX);
  var doc = parser.parseDocument();

  if (parser.errors.isNotEmpty && onError != null) {
    parser.errors.forEach(onError);
  } else if (parser.errors.isNotEmpty) {
    throw parser.errors.first;
  }

  return doc;
}