mod error;
mod lang;
mod parser;
mod text;
pub use error::ParseError;
pub use parser::{ParsedTree, SemtreeParser};
pub use text::{chunk_text, is_text_file};
use semtree_core::{Chunk, Language};
pub fn parse_and_extract(source: &str, language: Language) -> Result<Vec<Chunk>, ParseError> {
let tree = SemtreeParser::parse(source, language)?;
Ok(lang::extract(&tree))
}
pub fn parse_and_extract_file(path: &std::path::Path) -> Result<Vec<Chunk>, ParseError> {
let tree = SemtreeParser::parse_file(path)?;
let mut chunks = lang::extract(&tree);
lang::shared::finalize_paths(&mut chunks, path);
Ok(chunks)
}
pub fn extract_file(path: &std::path::Path) -> Result<Vec<Chunk>, ParseError> {
if is_text_file(path) {
let source = std::fs::read_to_string(path)?;
return Ok(chunk_text(path, &source, 40, 5));
}
parse_and_extract_file(path)
}