parseNativeInput method

TreeSitterTree? parseNativeInput(
  1. TreeSitterNativeInput input, {
  2. TreeSitterParseOptions? options,
  3. TreeSitterTree? oldTree,
  4. Iterable<TreeSitterInputEdit> edits = const [],
  5. bool annotateLocals = true,
})

Parses the exact native TSInput value projection.

As in ts_parser_parse, a missing language or read callback fails before invoking the callback. The input encoding selects the corresponding byte decoder; custom input requires its native decode function.

Implementation

TreeSitterTree? parseNativeInput(
  TreeSitterNativeInput input, {
  TreeSitterParseOptions? options,
  TreeSitterTree? oldTree,
  Iterable<TreeSitterInputEdit> edits = const [],
  bool annotateLocals = true,
}) {
  _checkNotDisposed();
  if (_grammar == null || input.read == null) return null;
  switch (input.encoding) {
    case TreeSitterInputEncoding.utf8:
      if (grammar is GeneratedTreeSitterGrammar &&
          _includedRanges.length == 1 &&
          _includedRanges.single == fullDocumentRange) {
        return _parseNativeUtf8Input(
          input,
          options: options,
          oldTree: oldTree,
          edits: edits,
          annotateLocals: annotateLocals,
        );
      }
      final bytes = TreeSitterUtf8Input(
        (byteOffset, point) => input.readAt(byteOffset, point),
      ).collectBytes();
      return options == null
          ? parseUtf8Bytes(
              bytes,
              oldTree: oldTree,
              edits: edits,
              annotateLocals: annotateLocals,
            )
          : parseUtf8BytesWithOptions(
              bytes,
              options,
              oldTree: oldTree,
              edits: edits,
              annotateLocals: annotateLocals,
            );
    case TreeSitterInputEncoding.utf16LittleEndian:
    case TreeSitterInputEncoding.utf16BigEndian:
      return _parseNativeDecodedInput(
        input,
        options: options,
        oldTree: oldTree,
        edits: edits,
        annotateLocals: annotateLocals,
      );
    case TreeSitterInputEncoding.custom:
      if (input.decode == null) return null;
      return _parseNativeDecodedInput(
        input,
        options: options,
        oldTree: oldTree,
        edits: edits,
        annotateLocals: annotateLocals,
      );
  }
}