class TreeSitter::Parser

Overview

A Parser is a stateful object that can be assigned a Language and used to produce a Tree based on some source code.

Defined in:

tree_sitter/parser.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(language_name : String) #

[View source]
def self.new(*, language : Language | Nil = nil) #

Create a new parser.


[View source]

Instance Method Detail

def language : Language #

Get the parser's current language.


[View source]
def language=(language : Language) : Language #

Set the language that the parser should use for parsing.

Raises Error if the language version is incompatible with treesitter library.


[View source]
def parse(old_tree : Tree | Nil, io : IO) : Tree | Nil #

[View source]
def parse(old_tree : Tree | Nil, string : String) : Tree #

[View source]
def parse(old_tree : Tree | Nil, &block : ReadProc) : Tree #

[View source]
def parse?(old_tree : Tree | Nil, io : IO) : Tree | Nil #

[View source]
def parse?(old_tree : Tree | Nil, string : String) : Tree | Nil #

[View source]
def parse?(old_tree : Tree | Nil, &block : ReadProc) : Tree | Nil #

[View source]
def print_dot_graphs(io : IO::FileDescriptor | Nil) : Nil #

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 nil.


[View source]
def reset #

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 #parse or other parsing methods. If you don't want to resume, and instead intend to use this parser to parse some other document, you must call #reset first.


[View source]