fromString static method

Document fromString(
  1. String body, {
  2. ParserErrorHandler? onErrors,
  3. List<Extensions> xtends = const [],
})

Given a body of text and a list of YES spec extensions xtends, parse and return Document.

If a custom onErrors implementation is provided, then errors will be fed to it.

By default, no extensions are selected.

Implementation

static Document fromString(
  String body, {
  ParserErrorHandler? onErrors,
  List<Extensions> xtends = const [],
}) {
  final DocumentReader reader = DocumentReader._();
  if (onErrors != null) {
    reader._handleErrors(onErrors);
  }
  String content = '';
  for (final s in body.split('\n')) {
    // XE 2026.1: Macros for repeating lines.
    if (xtends.contains(Extensions.macro2026)) {
      content += reader._preprocessMacros(s);
      continue;
    }
    content += '$s\n';
  }

  final YesParser yp = YesParser.fromString(content);
  reader._process(yp.elementInfoList, yp.errorInfoList, xtends);
  return reader._doc;
}