use crate::lex::lexing::Token;
use crate::lex::token::LineToken;
use std::ops::Range;
pub type TokenLocation = (Token, Range<usize>);
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum NodeType {
Document,
DocumentStart,
DocumentTitle,
DocumentSubtitle,
Paragraph,
Session,
ListItem,
List,
Definition,
Annotation,
VerbatimBlock,
Table,
BlankLineGroup,
}
#[derive(Debug, Clone)]
pub enum ParseNodePayload {
VerbatimBlock {
subject: LineToken,
content_lines: Vec<LineToken>,
closing_data_tokens: Vec<TokenLocation>,
},
Table {
subject: LineToken,
content_lines: Vec<LineToken>,
config_annotation_tokens: Option<Vec<TokenLocation>>,
},
}
#[derive(Debug, Clone)]
pub struct ParseNode {
pub node_type: NodeType,
pub tokens: Vec<TokenLocation>,
pub children: Vec<ParseNode>,
pub payload: Option<ParseNodePayload>,
}
impl ParseNode {
pub fn new(node_type: NodeType, tokens: Vec<TokenLocation>, children: Vec<ParseNode>) -> Self {
Self {
node_type,
tokens,
children,
payload: None,
}
}
pub fn with_payload(mut self, payload: ParseNodePayload) -> Self {
self.payload = Some(payload);
self
}
}