mycelium_hyphae/lib.rs
1//! # mycelium-hyphae
2//!
3//! Hyphae — the CSS-selector-inspired query language for Mycelium.
4//!
5//! See [RFC-0003](https://github.com/aimasteracc/mycelium/blob/develop/rfcs/0003-hyphae-query-language.md)
6//! for the full grammar specification.
7//!
8//! ## Quick start
9//!
10//! ```
11//! use mycelium_hyphae::parser::parse;
12//! use mycelium_hyphae::ast::Ast;
13//!
14//! let ast = parse("#login").unwrap();
15//! if let Ast::SelectorList(selectors) = &ast {
16//! assert_eq!(selectors.len(), 1);
17//! }
18//! ```
19//!
20//! ## Modules
21//!
22//! - [`ast`] — AST types produced by the parser.
23//! - [`lexer`] — token types and the `tokenise` function.
24//! - [`parser`] — entry point: the `parse` function.
25
26#![doc(html_root_url = "https://docs.rs/mycelium-hyphae")]
27
28pub mod ast;
29pub mod evaluator;
30pub mod lexer;
31pub mod parser;
32
33/// Parse a Hyphae query string into an [`ast::Ast`].
34///
35/// This is a convenience re-export of [`parser::parse`].
36///
37/// # Errors
38///
39/// Returns [`parser::ParseError`] on invalid input.
40///
41/// # Examples
42///
43/// ```
44/// let ast = mycelium_hyphae::parse("#login").unwrap();
45/// # let _ = ast;
46/// ```
47pub fn parse(input: &str) -> Result<ast::Ast, parser::ParseError> {
48 parser::parse(input)
49}