Skip to main content

treesitter_types_haskell/
lib.rs

1//! Strongly-typed AST types for Haskell, auto-generated from
2//! [`tree-sitter-haskell`](https://docs.rs/tree-sitter-haskell)'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//! These types have been tested by parsing the
8//! [Cabal](https://github.com/haskell/cabal) source code.
9//!
10//! See the [Tree-sitter](https://tree-sitter.github.io/tree-sitter/) project for more
11//! information about the underlying parser framework.
12//!
13//! # Example
14//!
15//! ```
16//! use treesitter_types_haskell::*;
17//!
18//! // A minimal Haskell hello-world program.
19//! let src = b"\
20//! module Main where
21//!
22//! main :: IO ()
23//! main = putStrLn \"Hello, World!\"
24//! ";
25//!
26//! // Parse the source with tree-sitter and convert into typed AST.
27//! let mut parser = tree_sitter::Parser::new();
28//! parser.set_language(&tree_sitter_haskell::LANGUAGE.into()).unwrap();
29//! let tree = parser.parse(src, None).unwrap();
30//! let haskell = Haskell::from_node(tree.root_node(), src).unwrap();
31//!
32//! // The module has a header (`module Main where`), no imports, and declarations.
33//! assert!(haskell.children.is_some()); // the module header
34//! assert!(haskell.imports.is_none());  // no import statements
35//! assert!(haskell.declarations.is_some());
36//!
37//! // The declarations section contains the type signature and the binding.
38//! let decls = haskell.declarations.as_ref().unwrap();
39//! assert!(!decls.children.is_empty());
40//! ```
41
42pub use tree_sitter_haskell;
43pub use treesitter_types::tree_sitter;
44pub use treesitter_types::{FromNode, LeafNode, ParseError, Span, Spanned};
45
46mod generated;
47pub use generated::*;