mirror of
https://github.com/gorules/zen.git
synced 2026-10-04 08:02:28 +00:00
* local: fault tolerant parser * fix tests * add intellisense * fix minor issues * improve support * fix fmt * fix * fix: improve error messages * improve error handling and ast * fix lint * fix tests * exclude zen-nodejs from rust tests
29 lines
705 B
Rust
29 lines
705 B
Rust
use crate::parser::{Node, ParserError};
|
|
use nohash_hasher::BuildNoHashHasher;
|
|
use std::collections::HashMap;
|
|
|
|
#[derive(Debug)]
|
|
pub struct ParserResult<'a> {
|
|
pub root: &'a Node<'a>,
|
|
pub is_complete: bool,
|
|
pub metadata: Option<HashMap<usize, NodeMetadata, BuildNoHashHasher<usize>>>,
|
|
}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct NodeMetadata {
|
|
pub span: (u32, u32),
|
|
}
|
|
|
|
impl<'a> ParserResult<'a> {
|
|
pub fn error(&self) -> Result<(), ParserError> {
|
|
if !self.is_complete {
|
|
return Err(ParserError::Incomplete);
|
|
}
|
|
|
|
match self.root.first_error() {
|
|
None => Ok(()),
|
|
Some(err) => Err(ParserError::NodeError(err.to_string())),
|
|
}
|
|
}
|
|
}
|