parse method

GeneratedTreeSitterTree parse(
  1. String source, {
  2. GeneratedTreeSitterTree? oldTree,
  3. Iterable<TreeSitterInputEdit> edits = const [],
  4. List<TreeSitterTableRange> includedRanges = const [],
  5. TreeSitterParserRuntimeHooks? runtimeHooks,
})

Implementation

GeneratedTreeSitterTree parse(
  String source, {
  GeneratedTreeSitterTree? oldTree,
  Iterable<TreeSitterInputEdit> edits = const [],
  List<TreeSitterTableRange> includedRanges = const [],
  TreeSitterParserRuntimeHooks? runtimeHooks,
}) {
  final resuming = _activeParseSession != null;
  _runtimeHooks = runtimeHooks;
  _parseClock = runtimeHooks != null && runtimeHooks.timeout > Duration.zero
      ? (Stopwatch()..start())
      : null;
  _progressOperationCount = 0;
  _activeIncludedRanges = includedRanges;
  if (!resuming) {
    _initializeNewParse(oldTree, edits, includedRanges);
  }
  var halted = false;
  try {
    // Native Tree-sitter does not make a speculative clean parse followed
    // by no-reuse and recovery retries. Recovery is part of its one parser
    // pass and continues to reuse every unaffected old subtree. Apart from
    // wasting work, the old retry pipeline made ordinary incomplete typing
    // states parse the document as many as three times and then exposed
    // metrics for only the final attempt.
    return _parseWithRecovery(
      source,
      Uint8List.fromList(utf8.encode(source)),
    );
  } on GeneratedTreeSitterParseHalted {
    halted = true;
    rethrow;
  } finally {
    if (!halted) reset();
    _runtimeHooks = null;
    _parseClock = null;
  }
}