Skip to main content

Crate treesitter_types_toml

Crate treesitter_types_toml 

Source
Expand description

Strongly-typed AST types for TOML, auto-generated from tree-sitter-toml-ng’s node-types.json.

This crate is generated by treesitter-types and is automatically kept up to date when a new version of the grammar crate is released.

See the Tree-sitter project for more information about the underlying parser framework.

§Example

use treesitter_types_toml::*;

// A small TOML document.
let src = b"\
[package]
name = \"hello\"
version = \"1.0.0\"
";

// Parse the source with tree-sitter and convert into typed AST.
let mut parser = tree_sitter::Parser::new();
parser.set_language(&tree_sitter_toml_ng::LANGUAGE.into()).unwrap();
let tree = parser.parse(src, None).unwrap();
let document = Document::from_node(tree.root_node(), src).unwrap();

// The document has one top-level child: a [package] table.
assert_eq!(document.children.len(), 1);

let DocumentChildren::Table(table) = &document.children[0] else {
    panic!("expected a table");
};
// The table contains the key-value pairs: `name` and `version`.
assert!(!table.children.is_empty());
assert_eq!(table.span.start.row, 0);

Re-exports§

pub use tree_sitter_toml_ng;
pub use treesitter_types::tree_sitter;

Structs§

Array
BareKey
Boolean
Comment
Document
DottedKey
EscapeSequence
Float
InlineTable
Integer
LocalDate
LocalDateTime
LocalTime
OffsetDateTime
Pair
QuotedKey
Span
String
Table
TableArrayElement

Enums§

AnyNode
ArrayChildren
DocumentChildren
DottedKeyChildren
PairChildren
ParseError
TableArrayElementChildren
TableChildren

Traits§

FromNode
Every generated struct and enum implements this.
LeafNode
Implemented by every generated leaf type (identifiers, literals, etc.)
Spanned
Implemented by every generated type that has a source location.