src/hmisc/wrappers/treesitter_core

    Dark Mode
Search:
Group by:
  Source   Edit

Types

HtsRegex[K] = ref object
  Source   Edit
HtsRegexKind[K] = enum
  hrxAlt
  Source   Edit
HtsRule[K] = ref object
  case kind*: HtsRuleKind
  of hrkString:
      strVal*: string

  of hrkSymbol:
      symbol*: K

  of hrkRepeat, hrkRepeat1:
      content*: HtsRule[K]

  of hrkBlank:
      nil

  of hrkRegex:
      rxValue*: string

  of hrkChoice, hrkSeq:
      members*: seq[HtsRule[K]]

  
  Source   Edit
HtsRuleKind = enum
  hrkBlank, hrkSeq, hrkRepeat, hrkRepeat1, hrkString, hrkRegex, hrkChoice,
  hrkSymbol
  Source   Edit
PtsInput = ptr TSInput
  Source   Edit
PtsParser = ptr TSParser
  Source   Edit
PtsRange = ptr TSRange
  Source   Edit
PtsTree = ptr TSTree
  Source   Edit
TSFieldId = distinct uint16
  Source   Edit
TSFieldMapEntry {.importc, incompleteStruct, header: "<tree_sitter/parser.h>".} = object
  field_id*: TSFieldId
  child_index*: uint8
  inherited*: bool
  Source   Edit
TSFieldMapSlice {.importc, incompleteStruct, header: "<tree_sitter/parser.h>".} = object
  index*: uint16
  length*: uint16
  Source   Edit
TSInput {.importc, incompleteStruct, header: "<tree_sitter/api.h>".} = object
  Source   Edit
TSInputEdit {.importc, incompleteStruct, header: "<tree_sitter/api.h>".} = object
  start_byte*: uint32
  old_end_byte*: uint32
  new_end_byte*: uint32
  start_point*: TSPoint
  old_end_point*: TSPoint
  new_end_point*: TSPoint
  Source   Edit
TSInputEncoding {.importc, header: "<tree_sitter/api.h>".} = enum
  TSInputEncodingUTF8, TSInputEncodingUTF16
  Source   Edit
TSLanguage {.importc, incompleteStruct, header: "<tree_sitter/api.h>".} = object
  version*: uint32
  symbol_count*: uint32
  alias_count*: uint32
  token_count*: uint32
  external_token_count*: uint32
  state_count*: uint32
  large_state_count*: uint32
  production_id_count*: uint32
  field_count*: uint32
  max_alias_sequence_length*: uint16
  parse_table*: ptr uint16
  small_parse_table*: ptr uint16
  small_parse_table_map*: ptr uint32
  symbol_names*: cstringArray
  field_names*: cstringArray
  field_map_slices*: ptr UncheckedArray[TSFieldMapSlice]
  field_map_entries*: ptr UncheckedArray[TSFieldMapEntry]
  symbol_metadata*: ptr TSSymbolMetadata
  public_symbol_map*: ptr TSSymbol
  alias_map*: ptr uint16
  alias_sequences*: ptr TSSymbol
  Source   Edit
TSLexer {.importc, incompleteStruct, header: "<tree_sitter/parser.h>".} = object
  lookahead*: cint
  result_symbol*: TSSymbol
  advance*: proc (lex: ptr TSLexer; skip: bool) {.cdecl.}
  mark_end*: proc (lex: ptr TSLexer) {.cdecl.}
  get_column*: proc (lex: ptr TSLexer): cuint {.cdecl.}
  is_at_included_range_start*: proc (lex: ptr TSLexer) {.cdecl.}
  Source   Edit
TSLogger {.importc, incompleteStruct, header: "<tree_sitter/api.h>".} = object
  payload*: pointer
  log*: proc (payload: pointer; logType: TSLogType; text: cstring) {.cdecl.}
  Source   Edit
TSNode {.importc, incompleteStruct, header: "<tree_sitter/api.h>".} = object
  context*: array[4, uint32]
  id*: pointer
  tree*: PtsTree
  Source   Edit
TSParser {.importc, incompleteStruct, header: "<tree_sitter/api.h>".} = object
  Source   Edit
TSPoint {.importc, incompleteStruct, header: "<tree_sitter/api.h>".} = object
  row*: uint32
  column*: uint32
  Source   Edit
TSQuery {.importc, incompleteStruct, header: "<tree_sitter/api.h>".} = object
  Source   Edit
TSQueryCapture {.importc, incompleteStruct, header: "<tree_sitter/api.h>".} = object
  node*: TSNode
  index*: uint32
  Source   Edit
TSQueryCursor {.importc, incompleteStruct, header: "<tree_sitter/api.h>".} = object
  Source   Edit
TSQueryError {.importc, header: "<tree_sitter/api.h>".} = enum
  TSQueryErrorNone, TSQueryErrorSyntax, TSQueryErrorNodeType, TSQueryErrorField,
  TSQueryErrorCapture, TSQueryErrorStructure
  Source   Edit
TSQueryMatch {.importc, incompleteStruct, header: "<tree_sitter/api.h>".} = object
  id*: uint32
  pattern_index*: uint16
  capture_count*: uint16
  captures*: UncheckedArray[TSQueryCapture]
  Source   Edit
TSQueryPredicateStep {.importc, incompleteStruct, header: "<tree_sitter/api.h>".} = object
  stepType* {.importc: "type".}: TSQueryPredicateStepType
  value_id*: uint32
  Source   Edit
TSQueryPredicateStepType {.importc, header: "<tree_sitter/api.h>".} = enum
  TSQueryPredicateStepTypeDone, TSQueryPredicateStepTypeCapture,
  TSQueryPredicateStepTypeString
  Source   Edit
TSRange {.importc, incompleteStruct, header: "<tree_sitter/api.h>".} = object
  start_point*: TSPoint
  end_point*: TSPoint
  start_byte*: uint32
  end_byte*: uint32
  Source   Edit
TSSymbol = distinct uint16
  Source   Edit
TSSymbolMetadata {.importc, incompleteStruct, header: "<tree_sitter/parser.h>".} = object
  visible*: bool
  named*: bool
  supertype*: bool
  Source   Edit
TSSymbolType {.importc, header: "<tree_sitter/api.h>".} = enum
  TSSymbolTypeRegular, TSSymbolTypeAnonymous, TSSymbolTypeAuxiliary
  Source   Edit
TSTree {.importc, incompleteStruct, header: "<tree_sitter/api.h>".} = object
  Source   Edit
TSTreeCursor {.importc, incompleteStruct, header: "<tree_sitter/api.h>",
               importc: "TSTreeCursor".} = object
  tree*: pointer
  id*: pointer
  context*: array[2, uint32]
  Source   Edit

Procs

func `[]`[N: distinct](node: N; idx: int | BackwardsIndex; unnamed: bool = false): N
  Source   Edit
func `[]`[N: distinct](node: N; name: string; check: bool = true): N
  Source   Edit
func `[]`[N: distinct](node: N; slice: HSlice[int, BackwardsIndex];
                       unnamed: bool = false): seq[N]
  Source   Edit
func `[]`[N: distinct](node: N; slice: Slice[int]; unnamed: bool = false): seq[N]
  Source   Edit
func `[]`[N: distinct](s: string; node: N): string
  Source   Edit
func `{}`[N: distinct](node: N; idx: int): N
Retun node positioned at idx - count includes unnamed (token) subnodes.   Source   Edit
func child[N: distinct](node: N; a2: int): N
  Source   Edit
func childByFieldName[N: distinct](self: N; fieldName: string;
                                   fieldNameLength: int): TSNode
  Source   Edit
func childCount[N: distinct](node: N): int
Number of subnodes (including tokens) for a tree   Source   Edit
proc childName[N: distinct](node: N; idx: int): string
  Source   Edit
func contains[N: distinct](node: N; name: string): bool
Check if node contains field with name   Source   Edit
func endByte[N: distinct](node: N): int
Return start point for AST node (line and column)   Source   Edit
func endColumn[N: distinct](node: N): int
  Source   Edit
func endLine[N: distinct](node: N): int
  Source   Edit
func endPoint[N: distinct](node: N): TSPoint
Return end point for AST node (line and column)   Source   Edit
proc fieldNames[N: distinct](node: N): seq[string]
  Source   Edit
func has[N: distinct](node: N; name: string): bool
Check if node contains field with name   Source   Edit
func hasChanges[N: distinct](node: N): bool
  Source   Edit
func hasError[N: distinct](node: N): bool
  Source   Edit
func isExtra[N: distinct](node: N): bool
  Source   Edit
func isMissing[N: distinct](node: N): bool
  Source   Edit
func isNamed[N: distinct](node: N): bool
  Source   Edit
func isNil(node: TSNode): bool {....raises: [], tags: [].}
  Source   Edit
func namedChild[N: distinct](node: N; a2: int): N
named child at index   Source   Edit
func namedChildCount[N: distinct](node: N): int
Number of named (non-token) subnodes for a triee   Source   Edit
func nodeString[N: distinct](node: N): string
  Source   Edit
func parent[N: distinct](node: N): N
  Source   Edit
func slice[N: distinct](node: N): Slice[int]
  Source   Edit
func startByte[N: distinct](node: N): int
Return start point for AST node (line and column)   Source   Edit
func startColumn[N: distinct](node: N): int
  Source   Edit
func startLine[N: distinct](node: N): int
  Source   Edit
func startPoint[N: distinct](node: N): TSPoint
Return start point for AST node (line and column)   Source   Edit
proc ts_language_field_count(a1: ptr TSLanguage): uint32 {.importc, cdecl,
    header: "<tree_sitter/api.h>", ...raises: [], tags: [].}
Get the number of distinct field names in the language.   Source   Edit
proc ts_language_field_id_for_name(a1: ptr TSLanguage; a2: cstring; a3: uint32): TSFieldId {.
    importc, cdecl, header: "<tree_sitter/api.h>", ...raises: [], tags: [].}
Get the numerical id for the given field name string.   Source   Edit
proc ts_language_field_name_for_id(a1: ptr TSLanguage; a2: TSFieldId): cstring {.
    importc, cdecl, header: "<tree_sitter/api.h>", ...raises: [], tags: [].}
Get the field name string for the given numerical id.   Source   Edit
proc ts_language_symbol_count(a1: ptr TSLanguage): uint32 {.importc, cdecl,
    header: "<tree_sitter/api.h>", ...raises: [], tags: [].}
Get the number of distinct node types in the language.   Source   Edit
proc ts_language_symbol_for_name(self: ptr TSLanguage; string: cstring;
                                 length: uint32; is_named: bool): TSSymbol {.
    importc, cdecl, header: "<tree_sitter/api.h>", ...raises: [], tags: [].}
Get the numerical id for the given node type string.   Source   Edit
proc ts_language_symbol_name(a1: ptr TSLanguage; a2: TSSymbol): cstring {.
    importc, cdecl, header: "<tree_sitter/api.h>", ...raises: [], tags: [].}
Get a node type string for the given numerical id.   Source   Edit
proc ts_language_symbol_type(a1: ptr TSLanguage; a2: TSSymbol): TSSymbolType {.
    importc, cdecl, header: "<tree_sitter/api.h>", ...raises: [], tags: [].}

Check whether the given node type id belongs to named nodes, anonymous nodes, or a hidden nodes.

See also ts_node_is_named. Hidden nodes are never returned from the API.

  Source   Edit
proc ts_language_version(a1: ptr TSLanguage): uint32 {.importc, cdecl,
    header: "<tree_sitter/api.h>", ...raises: [], tags: [].}

Get the ABI version number for this language. This version number is used to ensure that languages were generated by a compatible version of Tree-sitter.

See also ts_parser_set_language.

  Source   Edit
proc ts_node_child(a1: TSNode; a2: uint32): TSNode {.importc, cdecl,
    header: "<tree_sitter/api.h>", ...raises: [], tags: [].}
Get the node's child at the given index, where zero represents the first child.   Source   Edit
proc ts_node_child_by_field_id(a1: TSNode; a2: TSFieldId): TSNode {.importc,
    cdecl, header: "<tree_sitter/api.h>", ...raises: [], tags: [].}

Get the node's child with the given numerical field id.

You can convert a field name to an id using the ts_language_field_id_for_name function.

  Source   Edit
proc ts_node_child_by_field_name(self: TSNode; field_name: cstring;
                                 field_name_length: uint32): TSNode {.importc,
    cdecl, header: "<tree_sitter/api.h>", ...raises: [], tags: [].}
Get the node's child with the given field name.   Source   Edit
proc ts_node_child_count(a1: TSNode): uint32 {.importc, cdecl,
    header: "<tree_sitter/api.h>", ...raises: [], tags: [].}
Get the node's number of children.   Source   Edit
proc ts_node_descendant_for_byte_range(a1: TSNode; a2: uint32; a3: uint32): TSNode {.
    importc, cdecl, header: "<tree_sitter/api.h>", ...raises: [], tags: [].}
Get the smallest node within this node that spans the given range of bytes or (row, column) positions.   Source   Edit
proc ts_node_descendant_for_point_range(a1: TSNode; a2: TSPoint; a3: TSPoint): TSNode {.
    importc, cdecl, header: "<tree_sitter/api.h>", ...raises: [], tags: [].}
Get the smallest node within this node that spans the given range of bytes or (row, column) positions.   Source   Edit
proc ts_node_edit(a1: ptr TSNode; a2: ptr TSInputEdit) {.importc, cdecl,
    header: "<tree_sitter/api.h>", ...raises: [], tags: [].}

Edit the node to keep it in-sync with source code that has been edited.

This function is only rarely needed. When you edit a syntax tree with the ts_tree_edit function, all of the nodes that you retrieve from the tree afterward will already reflect the edit. You only need to use ts_node_edit when you have a TSNode instance that you want to keep and continue to use after an edit.

  Source   Edit
proc ts_node_end_byte(a1: TSNode): uint32 {.importc, cdecl,
    header: "<tree_sitter/api.h>", ...raises: [], tags: [].}
Get the node's end byte.   Source   Edit
proc ts_node_end_point(a1: TSNode): TSPoint {.importc, cdecl,
    header: "<tree_sitter/api.h>", ...raises: [], tags: [].}
Get the node's end position in terms of rows and columns.   Source   Edit
proc ts_node_eq(a1: TSNode; a2: TSNode): bool {.importc, cdecl,
    header: "<tree_sitter/api.h>", ...raises: [], tags: [].}
Check if two nodes are identical.   Source   Edit
proc ts_node_field_name_for_child(node: TSNode; idx: uint32): cstring {.importc,
    cdecl, header: "<tree_sitter/api.h>", ...raises: [], tags: [].}
  Source   Edit
proc ts_node_first_child_for_byte(a1: TSNode; a2: uint32): TSNode {.importc,
    cdecl, header: "<tree_sitter/api.h>", ...raises: [], tags: [].}
Get the node's first child that extends beyond the given byte offset.   Source   Edit
proc ts_node_first_named_child_for_byte(a1: TSNode; a2: uint32): TSNode {.
    importc, cdecl, header: "<tree_sitter/api.h>", ...raises: [], tags: [].}
Get the node's first named child that extends beyond the given byte offset.   Source   Edit
proc ts_node_has_changes(a1: TSNode): bool {.importc, cdecl,
    header: "<tree_sitter/api.h>", ...raises: [], tags: [].}
Check if a syntax node has been edited.   Source   Edit
proc ts_node_has_error(a1: TSNode): bool {.importc, cdecl,
    header: "<tree_sitter/api.h>", ...raises: [], tags: [].}
Check if the node is a syntax error or contains any syntax errors.   Source   Edit
proc ts_node_is_extra(a1: TSNode): bool {.importc, cdecl,
    header: "<tree_sitter/api.h>", ...raises: [], tags: [].}
Check if the node is extra. Extra nodes represent things like comments, which are not required the grammar, but can appear anywhere.   Source   Edit
proc ts_node_is_missing(a1: TSNode): bool {.importc, cdecl,
    header: "<tree_sitter/api.h>", ...raises: [], tags: [].}
Check if the node is missing. Missing nodes are inserted by the parser in order to recover from certain kinds of syntax errors.   Source   Edit
proc ts_node_is_named(a1: TSNode): bool {.importc, cdecl,
    header: "<tree_sitter/api.h>", ...raises: [], tags: [].}
Check if the node is named. Named nodes correspond to named rules in the grammar, whereas anonymous nodes correspond to string literals in the grammar.   Source   Edit
proc ts_node_is_null(a1: TSNode): bool {.importc, cdecl,
    header: "<tree_sitter/api.h>", ...raises: [], tags: [].}
Check if the node is null. Functions like ts_node_child and ts_node_next_sibling will return a null node to indicate that no such node was found.   Source   Edit
proc ts_node_named_child(a1: TSNode; a2: uint32): TSNode {.importc, cdecl,
    header: "<tree_sitter/api.h>", ...raises: [], tags: [].}

Get the node's named child at the given index.

See also ts_node_is_named.

  Source   Edit
proc ts_node_named_child_count(a1: TSNode): uint32 {.importc, cdecl,
    header: "<tree_sitter/api.h>", ...raises: [], tags: [].}

Get the node's number of named children.

See also ts_node_is_named.

  Source   Edit
proc ts_node_named_descendant_for_byte_range(a1: TSNode; a2: uint32; a3: uint32): TSNode {.
    importc, cdecl, header: "<tree_sitter/api.h>", ...raises: [], tags: [].}
Get the smallest named node within this node that spans the given range of bytes or (row, column) positions.   Source   Edit
proc ts_node_named_descendant_for_point_range(a1: TSNode; a2: TSPoint;
    a3: TSPoint): TSNode {.importc, cdecl, header: "<tree_sitter/api.h>",
                           ...raises: [], tags: [].}
Get the smallest named node within this node that spans the given range of bytes or (row, column) positions.   Source   Edit
proc ts_node_next_named_sibling(a1: TSNode): TSNode {.importc, cdecl,
    header: "<tree_sitter/api.h>", ...raises: [], tags: [].}
Get the node's next / previous named sibling.   Source   Edit
proc ts_node_next_sibling(a1: TSNode): TSNode {.importc, cdecl,
    header: "<tree_sitter/api.h>", ...raises: [], tags: [].}
Get the node's next / previous sibling.   Source   Edit
proc ts_node_parent(a1: TSNode): TSNode {.importc, cdecl,
    header: "<tree_sitter/api.h>", ...raises: [], tags: [].}
Get the node's immediate parent.   Source   Edit
proc ts_node_prev_named_sibling(a1: TSNode): TSNode {.importc, cdecl,
    header: "<tree_sitter/api.h>", ...raises: [], tags: [].}
Get the node's next / previous named sibling.   Source   Edit
proc ts_node_prev_sibling(a1: TSNode): TSNode {.importc, cdecl,
    header: "<tree_sitter/api.h>", ...raises: [], tags: [].}
Get the node's next / previous sibling.   Source   Edit
proc ts_node_start_byte(a1: TSNode): uint32 {.importc, cdecl,
    header: "<tree_sitter/api.h>", ...raises: [], tags: [].}
Get the node's start byte.   Source   Edit
proc ts_node_start_point(a1: TSNode): TSPoint {.importc, cdecl,
    header: "<tree_sitter/api.h>", ...raises: [], tags: [].}
Get the node's start position in terms of rows and columns.   Source   Edit
proc ts_node_string(a1: TSNode): cstring {.importc, cdecl,
    header: "<tree_sitter/api.h>", ...raises: [], tags: [].}

Get an S-expression representing the node as a string.

This string is allocated with malloc and the caller is responsible for freeing it using free.

  Source   Edit
proc ts_node_symbol(a1: TSNode): TSSymbol {.importc, cdecl,
    header: "<tree_sitter/api.h>", ...raises: [], tags: [].}
Get the node's type as a numerical id.   Source   Edit
proc ts_node_type(a1: TSNode): cstring {.importc, cdecl,
    header: "<tree_sitter/api.h>", ...raises: [], tags: [].}
Get the node's type as a null-terminated string.   Source   Edit
proc ts_parser_cancellation_flag(self: PtsParser): ptr uint {.importc, cdecl,
    header: "<tree_sitter/api.h>", ...raises: [], tags: [].}

Set the parser's current cancellation flag pointer.

If a non-null pointer is assigned, then the parser will periodically read from this pointer during parsing. If it reads a non-zero value, it will halt early, returning NULL. See ts_parser_parse for more information.

  Source   Edit
proc ts_parser_delete(parser: PtsParser) {.importc, cdecl,
    header: "<tree_sitter/api.h>", ...raises: [], tags: [].}
Delete the parser, freeing all of the memory that it used.   Source   Edit
proc ts_parser_halt_on_error(self: PtsParser; halt: bool) {.importc, cdecl,
    header: "<tree_sitter/api.h>", ...raises: [], tags: [].}
Set the file descriptor to which the parser should write debugging graphs during parsing. The graphs are formatted in the DOT language. You may want to pipe these graphs directly to a dot(1) process in order to generate SVG output. You can turn off this logging by passing a negative number.   Source   Edit
proc ts_parser_included_ranges(self: PtsParser; length: ptr uint32): ptr TSRange {.
    importc, cdecl, header: "<tree_sitter/api.h>", ...raises: [], tags: [].}

Get the ranges of text that the parser will include when parsing.

The returned pointer is owned by the parser. The caller should not free it or write to it. The length of the array will be written to the given length pointer.

  Source   Edit
proc ts_parser_language(self: PtsParser): PtsLanguage {.importc, cdecl,
    header: "<tree_sitter/api.h>", ...raises: [], tags: [].}
Get the parser's current language.   Source   Edit
proc ts_parser_logger(self: PtsParser): TSLogger {.importc, cdecl,
    header: "<tree_sitter/api.h>", ...raises: [], tags: [].}

Set the logger that a parser should use during parsing.

The parser does not take ownership over the logger payload. If a logger was previously assigned, the caller is responsible for releasing any memory owned by the previous logger.

  Source   Edit
proc ts_parser_new(): PtsParser {.importc, cdecl, header: "<tree_sitter/api.h>",
                                  ...raises: [], tags: [].}
Create a new parser.   Source   Edit
proc ts_parser_parse(self: PtsParser; oldTree: PtsTree; input: PtsInput): PtsTree {.
    importc, cdecl, header: "<tree_sitter/api.h>", ...raises: [], tags: [].}

Use the parser to parse some source code and create a syntax tree.

If you are parsing this document for the first time, pass NULL for the old_tree parameter. Otherwise, if you have already parsed an earlier version of this document and the document has since been edited, pass the previous syntax tree so that the unchanged parts of it can be reused. This will save time and memory. For this to work correctly, you must have already edited the old syntax tree using the ts_tree_edit function in a way that exactly matches the source code changes.

The TSInput parameter lets you specify how to read the text. It has the following three fields:

  1. read: A function to retrieve a chunk of text at a given byte offset and (row, column) position. The function should return a pointer to the text and write its length to the bytes_read pointer. The parser does not take ownership of this buffer; it just borrows it until it has finished reading it. The function should write a zero value to the bytes_read pointer to indicate the end of the document.
  2. payload: An arbitrary pointer that will be passed to each invocation of the read function.
  3. encoding: An indication of how the text is encoded. Either TSInputEncodingUTF8 or TSInputEncodingUTF16.

This function returns a syntax tree on success, and NULL on failure. There are three possible reasons for failure:

  1. The parser does not have a language assigned. Check for this using the
    ts_parser_language function.
  2. Parsing was cancelled due to a timeout that was set by an earlier call to the ts_parser_set_timeout_micros function. You can resume parsing from where the parser left out by calling ts_parser_parse again with the same arguments. Or you can start parsing from scratch by first calling ts_parser_reset.
  3. Parsing was cancelled using a cancellation flag that was set by an earlier call to ts_parser_set_cancellation_flag. You can resume parsing from where the parser left out by calling ts_parser_parse again with the same arguments.
  Source   Edit
proc ts_parser_parse_string(self: PtsParser; old_tree: PtsTree;
                            inString: cstring; length: uint32): PtsTree {.
    importc, cdecl, header: "<tree_sitter/api.h>", ...raises: [], tags: [].}
Use the parser to parse some source code stored in one contiguous buffer. The first two parameters are the same as in the ts_parser_parse function above. The second two parameters indicate the location of the buffer and its length in bytes.   Source   Edit
proc ts_parser_parse_string_encoding(self: PtsParser; old_tree: PtsTree;
                                     string: cstring; length: uint32;
                                     encoding: TSInputEncoding): PtsTree {.
    importc, cdecl, header: "<tree_sitter/api.h>", ...raises: [], tags: [].}
Use the parser to parse some source code stored in one contiguous buffer with a given encoding. The first four parameters work the same as in the ts_parser_parse_string method above. The final parameter indicates whether the text is encoded as UTF8 or UTF16.   Source   Edit
proc ts_parser_print_dot_graphs(self: PtsParser; file: cint) {.importc, cdecl,
    header: "<tree_sitter/api.h>", ...raises: [], tags: [].}
Get the parser's current logger.   Source   Edit
proc ts_parser_reset(self: PtsParser) {.importc, cdecl,
                                        header: "<tree_sitter/api.h>",
                                        ...raises: [], tags: [].}

Instruct the parser to start the next parse from the beginning.

If the parser previously failed because of a timeout or a cancellation, then by default, it will resume where it left off on the next call to ts_parser_parse or other parsing functions. If you don't want to resume, and instead intend to use this parser to parse some other document, you must call ts_parser_reset first.

  Source   Edit
proc ts_parser_set_included_ranges(self: PtsParser; ranges: PtsRange;
                                   length: uint32) {.importc, cdecl,
    header: "<tree_sitter/api.h>", ...raises: [], tags: [].}

Set the ranges of text that the parser should include when parsing.

By default, the parser will always include entire documents. This function allows you to parse only a portion of a document but still return a syntax tree whose ranges match up with the document as a whole. You can also pass multiple disjoint ranges.

The second and third parameters specify the location and length of an array of ranges. The parser does not take ownership of these ranges; it copies the data, so it doesn't matter how these ranges are allocated.

If length is zero, then the entire document will be parsed. Otherwise, the given ranges must be ordered from earliest to latest in the document, and they must not overlap. That is, the following must hold for all i < length - 1:

ranges[i].end_byte <= ranges[i + 1].start_byte

If this requirement is not satisfied, the operation will fail, the ranges will not be assigned, and this function will return false. On success, this function returns true

  Source   Edit
proc ts_parser_set_language(self: PtsParser; language: PtsLanguage): bool {.
    importc, cdecl, header: "<tree_sitter/api.h>", ...raises: [], tags: [].}

Set the language that the parser should use for parsing.

Returns a boolean indicating whether or not the language was successfully assigned. True means assignment succeeded. False means there was a version mismatch: the language was generated with an incompatible version of the Tree-sitter CLI. Check the language's version using ts_language_version and compare it to this library's TREE_SITTER_LANGUAGE_VERSION and TREE_SITTER_MIN_COMPATIBLE_LANGUAGE_VERSION constants.

  Source   Edit
proc ts_parser_set_logger(self: PtsParser; logger: TSLogger) {.importc, cdecl,
    header: "<tree_sitter/api.h>", ...raises: [], tags: [].}
Get the parser's current cancellation flag pointer.   Source   Edit
proc ts_parser_set_timeout_micros(self: PtsParser; timeout: uint64) {.importc,
    cdecl, header: "<tree_sitter/api.h>", ...raises: [], tags: [].}

Set the maximum duration in microseconds that parsing should be allowed to take before halting.

If parsing takes longer than this, it will halt early, returning NULL. See ts_parser_parse for more information.

  Source   Edit
proc ts_parser_timeout_micros(self: PtsParser): uint64 {.importc, cdecl,
    header: "<tree_sitter/api.h>", ...raises: [], tags: [].}
Get the duration in microseconds that parsing is allowed to take.   Source   Edit
proc ts_query_capture_count(a1: ptr TSQuery): uint32 {.importc, cdecl,
    header: "<tree_sitter/api.h>", ...raises: [], tags: [].}
Get the number of captures in the query.   Source   Edit
proc ts_query_capture_name_for_id(a1: ptr TSQuery; id: uint32;
                                  length: ptr uint32): cstring {.importc, cdecl,
    header: "<tree_sitter/api.h>", ...raises: [], tags: [].}
Get the name and length of one of the query's captures, or one of the query's string literals. Each capture and string is associated with a numeric id based on the order that it appeared in the query's source.   Source   Edit
proc ts_query_cursor_delete(a1: ptr TSQueryCursor) {.importc, cdecl,
    header: "<tree_sitter/api.h>", ...raises: [], tags: [].}
Delete a query cursor, freeing all of the memory that it used.   Source   Edit
proc ts_query_cursor_exec(a1: ptr TSQueryCursor; a2: ptr TSQuery; a3: TSNode) {.
    importc, cdecl, header: "<tree_sitter/api.h>", ...raises: [], tags: [].}
Start running a given query on a given node.   Source   Edit
proc ts_query_cursor_new(): ptr TSQueryCursor {.importc, cdecl,
    header: "<tree_sitter/api.h>", ...raises: [], tags: [].}

Create a new cursor for executing a given query.

The cursor stores the state that is needed to iteratively search for matches. To use the query cursor, first call ts_query_cursor_exec to start running a given query on a given syntax node. Then, there are two options for consuming the results of the query:

  1. Repeatedly call ts_query_cursor_next_match to iterate over all of the matches in the order that they were found. Each match contains the index of the pattern that matched, and an array of captures. Because multiple patterns can match the same set of nodes, one match may contain captures that appear before some of the captures from a previous match.
  2. Repeatedly call ts_query_cursor_next_capture to iterate over all of the individual captures in the order that they appear. This is useful if don't care about which pattern matched, and just want a single ordered sequence of captures.

If you don't care about consuming all of the results, you can stop calling

ts_query_cursor_next_match or ts_query_cursor_next_capture at any point.
You can then start executing another query on another node by calling ts_query_cursor_exec again.
  Source   Edit
proc ts_query_cursor_next_capture(a1: ptr TSQueryCursor;
                                  match: ptr TSQueryMatch;
                                  capture_index: ptr uint32): bool {.importc,
    cdecl, header: "<tree_sitter/api.h>", ...raises: [], tags: [].}

Advance to the next capture of the currently running query.

If there is a capture, write its match to *match and its index within the matche's capture list to *capture_index. Otherwise, return false.

  Source   Edit
proc ts_query_cursor_next_match(a1: ptr TSQueryCursor; match: ptr TSQueryMatch): bool {.
    importc, cdecl, header: "<tree_sitter/api.h>", ...raises: [], tags: [].}

Advance to the next match of the currently running query.

If there is a match, write it to *match and return true. Otherwise, return false.

  Source   Edit
proc ts_query_cursor_remove_match(a1: ptr TSQueryCursor; id: uint32) {.importc,
    cdecl, header: "<tree_sitter/api.h>", ...raises: [], tags: [].}
  Source   Edit
proc ts_query_cursor_set_byte_range(a1: ptr TSQueryCursor; a2: uint32;
                                    a3: uint32) {.importc, cdecl,
    header: "<tree_sitter/api.h>", ...raises: [], tags: [].}
Set the range of bytes or (row, column) positions in which the query will be executed.   Source   Edit
proc ts_query_cursor_set_point_range(a1: ptr TSQueryCursor; a2: TSPoint;
                                     a3: TSPoint) {.importc, cdecl,
    header: "<tree_sitter/api.h>", ...raises: [], tags: [].}
Set the range of bytes or (row, column) positions in which the query will be executed.   Source   Edit
proc ts_query_delete(a1: ptr TSQuery) {.importc, cdecl,
                                        header: "<tree_sitter/api.h>",
                                        ...raises: [], tags: [].}
Delete a query, freeing all of the memory that it used.   Source   Edit
proc ts_query_disable_capture(a1: ptr TSQuery; a2: cstring; a3: uint32) {.
    importc, cdecl, header: "<tree_sitter/api.h>", ...raises: [], tags: [].}

Disable a certain capture within a query.

This prevents the capture from being returned in matches, and also avoids any resource usage associated with recording the capture. Currently, there is no way to undo this.

  Source   Edit
proc ts_query_disable_pattern(a1: ptr TSQuery; a3: uint32) {.importc, cdecl,
    header: "<tree_sitter/api.h>", ...raises: [], tags: [].}

Disable a certain pattern within a query.

This prevents the pattern from matching and removes most of the overhead associated with the pattern. Currently, there is no way to undo this.

  Source   Edit
proc ts_query_new(language: ptr TSLanguage; source: cstring; source_len: uint32;
                  error_offset: ptr uint32; error_type: ptr TSQueryError): ptr TSQuery {.
    importc, cdecl, header: "<tree_sitter/api.h>", ...raises: [], tags: [].}

Create a new query from a string containing one or more S-expression patterns. The query is associated with a particular language, and can only be run on syntax nodes parsed with that language.

If all of the given patterns are valid, this returns a TSQuery. If a pattern is invalid, this returns NULL, and provides two pieces of information about the problem:

  1. The byte offset of the error is written to the error_offset parameter.
  2. The type of error is written to the error_type parameter.
  Source   Edit
proc ts_query_pattern_count(a1: ptr TSQuery): uint32 {.importc, cdecl,
    header: "<tree_sitter/api.h>", ...raises: [], tags: [].}
Get the number of patternsliterals in the query.   Source   Edit
proc ts_query_predicates_for_pattern(self: ptr TSQuery; pattern_index: uint32;
                                     length: ptr uint32): ptr TSQueryPredicateStep {.
    importc, cdecl, header: "<tree_sitter/api.h>", ...raises: [], tags: [].}

Get all of the predicates for the given pattern in the query.

The predicates are represented as a single array of steps. There are three types of steps in this array, which correspond to the three legal values for the type field:

  • TSQueryPredicateStepTypeCapture - Steps with this type represent names
    of captures. Their value_id can be used with the

    ts_query_capture_name_for_id function to obtain the name of the capture.

  • TSQueryPredicateStepTypeString - Steps with this type represent literal
    strings. Their value_id can be used with the ts_query_string_value_for_id function to obtain their string value.
  • TSQueryPredicateStepTypeDone - Steps with this type are sentinels
    that represent the end of an individual predicate. If a pattern has two predicates, then there will be two steps with this type in the array.
  Source   Edit
proc ts_query_start_byte_for_pattern(a1: ptr TSQuery; a2: uint32): uint32 {.
    importc, cdecl, header: "<tree_sitter/api.h>", ...raises: [], tags: [].}

Get the byte offset where the given pattern starts in the query's source.

This can be useful when combining queries by concatenating their source code strings.

  Source   Edit
proc ts_query_string_count(a1: ptr TSQuery): uint32 {.importc, cdecl,
    header: "<tree_sitter/api.h>", ...raises: [], tags: [].}
Get the number of string literals in the query.   Source   Edit
proc ts_query_string_value_for_id(a1: ptr TSQuery; id: uint32;
                                  length: ptr uint32): cstring {.importc, cdecl,
    header: "<tree_sitter/api.h>", ...raises: [], tags: [].}
Get the name and length of one of the query's captures, or one of the query's string literals. Each capture and string is associated with a numeric id based on the order that it appeared in the query's source.   Source   Edit
proc ts_tree_copy(self: PtsTree): PtsTree {.importc, cdecl,
    header: "<tree_sitter/api.h>", ...raises: [], tags: [].}

Create a shallow copy of the syntax tree. This is very fast.

You need to copy a syntax tree in order to use it on more than one thread at a time, as syntax trees are not thread safe.

  Source   Edit
proc ts_tree_cursor_copy(a1: PTsTreeCursor): TSTreeCursor {.importc, cdecl,
    header: "<tree_sitter/api.h>", ...raises: [], tags: [].}
  Source   Edit
proc ts_tree_cursor_current_field_id(a1: PTsTreeCursor): TSFieldId {.importc,
    cdecl, header: "<tree_sitter/api.h>", ...raises: [], tags: [].}

Get the field name of the tree cursor's current node.

This returns zero if the current node doesn't have a field. See also ts_node_child_by_field_id, ts_language_field_id_for_name.

  Source   Edit
proc ts_tree_cursor_current_field_name(a1: PTsTreeCursor): cstring {.importc,
    cdecl, header: "<tree_sitter/api.h>", ...raises: [], tags: [].}

Get the field name of the tree cursor's current node.

This returns NULL if the current node doesn't have a field. See also ts_node_child_by_field_name.

  Source   Edit
proc ts_tree_cursor_current_node(a1: PTsTreeCursor): TSNode {.importc, cdecl,
    header: "<tree_sitter/api.h>", ...raises: [], tags: [].}
Get the tree cursor's current node.   Source   Edit
proc ts_tree_cursor_delete(a1: PTsTreeCursor) {.importc, cdecl,
    header: "<tree_sitter/api.h>", ...raises: [], tags: [].}
Delete a tree cursor, freeing all of the memory that it used.   Source   Edit
proc ts_tree_cursor_goto_first_child(a1: PTsTreeCursor): bool {.importc, cdecl,
    header: "<tree_sitter/api.h>", ...raises: [], tags: [].}

Move the cursor to the first child of its current node.

This returns true if the cursor successfully moved, and returns false if there were no children.

  Source   Edit
proc ts_tree_cursor_goto_first_child_for_byte(a1: PTsTreeCursor; a2: uint32): int64 {.
    importc, cdecl, header: "<tree_sitter/api.h>", ...raises: [], tags: [].}

Move the cursor to the first child of its current node that extends beyond the given byte offset or point.

This returns the index of the child node if one was found, and returns -1 if no such child was found.

  Source   Edit
proc ts_tree_cursor_goto_next_sibling(a1: PTsTreeCursor): bool {.importc, cdecl,
    header: "<tree_sitter/api.h>", ...raises: [], tags: [].}

Move the cursor to the next sibling of its current node.

This returns true if the cursor successfully moved, and returns false if there was no next sibling node.

  Source   Edit
proc ts_tree_cursor_goto_parent(a1: PTsTreeCursor): bool {.importc, cdecl,
    header: "<tree_sitter/api.h>", ...raises: [], tags: [].}

Move the cursor to the parent of its current node.

This returns true if the cursor successfully moved, and returns false if there was no parent node (the cursor was already on the root node).

  Source   Edit
proc ts_tree_cursor_new(a1: TSNode): TSTreeCursor {.importc, cdecl,
    header: "<tree_sitter/api.h>", ...raises: [], tags: [].}

Create a new tree cursor starting from the given node.

A tree cursor allows you to walk a syntax tree more efficiently than is possible using the TSNode functions. It is a mutable object that is always on a certain syntax node, and can be moved imperatively to different nodes.

  Source   Edit
proc ts_tree_cursor_reset(a1: PTsTreeCursor; a2: TSNode) {.importc, cdecl,
    header: "<tree_sitter/api.h>", ...raises: [], tags: [].}
Re-initialize a tree cursor to start at a different node.   Source   Edit
proc ts_tree_delete(self: PtsTree) {.importc, cdecl,
                                     header: "<tree_sitter/api.h>", ...raises: [],
                                     tags: [].}
Delete the syntax tree, freeing all of the memory that it used.   Source   Edit
proc ts_tree_edit(self: PtsTree; edit: ptr TSInputEdit) {.importc, cdecl,
    header: "<tree_sitter/api.h>", ...raises: [], tags: [].}

Edit the syntax tree to keep it in sync with source code that has been edited.

You must describe the edit both in terms of byte offsets and in terms of (row, column) coordinates.

  Source   Edit
proc ts_tree_get_changed_ranges(old_tree: PtsTree; new_tree: PtsTree;
                                length: ptr uint32): ptr TSRange {.importc,
    cdecl, header: "<tree_sitter/api.h>", ...raises: [], tags: [].}

Compare an old edited syntax tree to a new syntax tree representing the same document, returning an array of ranges whose syntactic structure has changed.

For this to work correctly, the old syntax tree must have been edited such that its ranges match up to the new tree. Generally, you'll want to call this function right after calling one of the ts_parser_parse functions. You need to pass the old tree that was passed to parse, as well as the new tree that was returned from that function.

The returned array is allocated using malloc and the caller is responsible for freeing it using free. The length of the array will be written to the given length pointer.

  Source   Edit
proc ts_tree_language(a1: PtsTree): ptr TSLanguage {.importc, cdecl,
    header: "<tree_sitter/api.h>", ...raises: [], tags: [].}
Get the language that was used to parse the syntax tree.   Source   Edit
proc ts_tree_print_dot_graph(a1: PtsTree; a2: File) {.importc, cdecl,
    header: "<tree_sitter/api.h>", ...raises: [], tags: [].}
Write a DOT graph describing the syntax tree to the given file.   Source   Edit
proc ts_tree_root_node(self: PtsTree): TSNode {.importc, cdecl,
    header: "<tree_sitter/api.h>", ...raises: [], tags: [].}
Get the root node of the syntax tree.   Source   Edit
func tsBlank[K](): HtsRule[K]
  Source   Edit
func tsChoice[K](args: varargs[HtsRule[K]]): HtsRule[K]
  Source   Edit
func tsRegex[K](arg: string): HtsRule[K]
  Source   Edit
func tsRepeat1[K](arg: HtsRule[K]): HtsRule[K]
  Source   Edit
func tsRepeat[K](arg: HtsRule[K]): HtsRule[K]
  Source   Edit
func tsSeq[K](args: varargs[HtsRule[K]]): HtsRule[K]
  Source   Edit
func tsString[K](arg: string): HtsRule[K]
  Source   Edit
func tsSymbol[K](arg: K): HtsRule[K]
  Source   Edit

Iterators

iterator items[N: distinct](node: N; unnamed: bool = false): N
Iterate over subnodes. unnamed - also iterate over unnamed nodes (usually things like punctuation, braces and so on).   Source   Edit
iterator pairs[N: distinct](node: N; unnamed: bool = false): (int, N)
Iterate over subnodes. unnamed - also iterate over unnamed nodes.   Source   Edit