tawasuyu

tawasuyu/brahman

Rust 582TOML 222Markdown 83JSON 198635 Definitions

⎇ 53dbdf0f1deea10d6fc567ea2b43e1e75d6d60cd crates/modules/semantic_dht/minga-core/src/parse.rs Rust · 25 lines · 957 B History Who touched what raw

chore: monorepo inicial con arje + minga + yahweh absorbidos 53dbdf0f1 · Sergio ·

1//! Adaptadores de parsing por dialecto. Hoy: Rust vía tree-sitter-rust.
2//!
3//! `parse::rust` produce un `SemanticNode` normalizado a partir de una
4//! cadena de código fuente. El error es opaco a propósito: el caller no
5//! necesita distinguir "gramática inválida" de "fallo del parser".
6
7use crate::ast::SemanticNode;
8use thiserror::Error;
9use tree_sitter::{Language, Parser};
10
11#[derive(Debug, Error)]
12pub enum ParseError {
13    #[error("tree-sitter no pudo configurar el lenguaje")]
14    Language,
15    #[error("tree-sitter no produjo árbol para la entrada")]
16    NoTree,
17}
18
19pub fn rust(source: &str) -> Result<SemanticNode, ParseError> {
20    let lang: Language = tree_sitter_rust::LANGUAGE.into();
21    let mut parser = Parser::new();
22    parser.set_language(&lang).map_err(|_| ParseError::Language)?;
23    let tree = parser.parse(source, None).ok_or(ParseError::NoTree)?;
24    Ok(SemanticNode::from_tree_sitter(tree.root_node(), source.as_bytes()))
25}