Skip to main content

treesitter_types_yaml/
lib.rs

1//! Strongly-typed AST types for YAML, auto-generated from
2//! [`tree-sitter-yaml`](https://docs.rs/tree-sitter-yaml)'s `node-types.json`.
3//!
4//! This crate is generated by [`treesitter-types`](https://docs.rs/treesitter-types) and is
5//! automatically kept up to date when a new version of the grammar crate is released.
6//!
7//! See the [Tree-sitter](https://tree-sitter.github.io/tree-sitter/) project for more
8//! information about the underlying parser framework.
9//!
10//! # Example
11//!
12//! ```
13//! use treesitter_types_yaml::*;
14//!
15//! // A small YAML document.
16//! let src = b"\
17//! name: hello
18//! version: 1.0.0
19//! dependencies:
20//!   - foo
21//!   - bar
22//! ";
23//!
24//! // Parse the source with tree-sitter and convert into typed AST.
25//! let mut parser = tree_sitter::Parser::new();
26//! parser.set_language(&tree_sitter_yaml::LANGUAGE.into()).unwrap();
27//! let tree = parser.parse(src, None).unwrap();
28//! let stream = Stream::from_node(tree.root_node(), src).unwrap();
29//!
30//! // A YAML stream contains one or more documents.
31//! assert_eq!(stream.children.len(), 1);
32//!
33//! // The document contains the top-level mapping.
34//! let doc = &stream.children[0];
35//! assert!(!doc.children.is_empty());
36//! assert_eq!(doc.span.start.row, 0);
37//! ```
38
39pub use tree_sitter_yaml;
40pub use treesitter_types::tree_sitter;
41pub use treesitter_types::{FromNode, LeafNode, ParseError, Span, Spanned};
42
43mod generated;
44pub use generated::*;