Parser is a stateful object used to produce a Tree from source code.
Constructor
new
Configuration
set_language
&Language
required
The language to use for parsing
Ok(()) if the language was successfully assigned, or Err(LanguageError) if there was a version mismatch.
language
Some(LanguageRef) if a language is set, or None if no language has been assigned.
set_included_ranges
&[Range]
required
The ranges to parse. Must be ordered from earliest to latest and non-overlapping.
Ok(()) if the ranges were valid, or Err(IncludedRangesError) with the index of the first invalid range.
included_ranges
Parsing Methods
parse
impl AsRef<[u8]>
required
The UTF8-encoded text to parse
Option<&Tree>
A previous syntax tree parsed from the same document. If the text has changed since
old_tree was created, you must edit old_tree to match the new text using Tree::edit.Tree if parsing succeeded, or None if the parser has not yet had a language assigned.
parse_with_options
&mut F
required
A function that takes a byte offset and position and returns a slice of UTF8-encoded text starting at that byte offset and position
Option<&Tree>
A previous syntax tree parsed from the same document
Option<ParseOptions>
Options for parsing, such as a progress callback
parse_utf16_le
impl AsRef<[u16]>
required
The UTF16-encoded text to parse
Option<&Tree>
A previous syntax tree parsed from the same document
parse_utf16_be
impl AsRef<[u16]>
required
The UTF16-encoded text to parse
Option<&Tree>
A previous syntax tree parsed from the same document
parse_custom_encoding
Decode
required
A type that implements the
Decode trait to decode the custom encoding&mut F
required
A function that takes a byte offset and position and returns a slice of text
Option<&Tree>
A previous syntax tree parsed from the same document
Option<ParseOptions>
Options for parsing
State Management
reset
parse. If you don’t want to resume, and instead intend to use this parser to parse some other document, you must call reset first.
Logging and Debugging
set_logger
Option<Logger>
A boxed closure that receives log messages. Set to
None to disable logging.logger
print_dot_graphs
dot(1) process in order to generate SVG output.
This method is only available on Unix platforms with the
std feature enabled.stop_printing_dot_graphs
Parse Options
ParseOptions
new
progress_callback
&'a mut F
required
A callback that receives the current parse state and returns
ControlFlow::Continue(()) to continue parsing or ControlFlow::Break(()) to abort