1mod error;
2mod extractor;
3mod lang;
4mod parser;
5mod text;
6
7pub use error::ParseError;
8pub use extractor::Extractor;
9pub use parser::{ParsedTree, SemtreeParser};
10pub use text::{chunk_text, is_text_file};
11
12use semtree_core::{Chunk, Language};
13
14pub fn parse_and_extract(source: &str, language: Language) -> Result<Vec<Chunk>, ParseError> {
15 let tree = SemtreeParser::parse(source, language)?;
16 lang::extract(&tree).map_err(|e| ParseError::Extract(e.to_string()))
17}
18
19pub fn parse_and_extract_file(path: &std::path::Path) -> Result<Vec<Chunk>, ParseError> {
20 let tree = SemtreeParser::parse_file(path)?;
21 lang::extract(&tree).map_err(|e| ParseError::Extract(e.to_string()))
22}
23
24pub fn extract_file(path: &std::path::Path) -> Result<Vec<Chunk>, ParseError> {
26 if is_text_file(path) {
27 let source = std::fs::read_to_string(path)?;
28 return Ok(chunk_text(path, &source, 40, 5));
29 }
30 parse_and_extract_file(path)
31}