mod command;
mod highlighter;
mod link;
mod list;
use std::fmt::{self, Debug, Display, Formatter};
pub use crate::Value;
pub use command::{Command, CommandKind};
pub use highlighter::Highlighter;
pub use link::SmartLink;
pub use list::ListView;
use std::collections::HashMap;
pub use url::Url;
#[derive(Clone, Eq, PartialEq)]
pub struct TextRange {
pub start: (u64, u64),
pub end: (u64, u64),
}
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum AST {
None,
Statements(Vec<AST>),
Header {
level: usize,
children: Vec<AST>,
r: TextRange,
},
HorizontalRule {
r: TextRange,
},
Paragraph {
children: Vec<AST>,
r: TextRange,
},
Highlight {
lang: String,
code: String,
inline: bool,
high_line: Vec<usize>,
r: TextRange,
},
MathBlock {
inner: String,
r: TextRange,
},
TableView {
head: Vec<AST>,
align: Vec<Option<bool>>,
terms: Vec<Vec<AST>>,
column: usize,
r: TextRange,
},
List {
inner: ListView,
r: TextRange,
},
Normal {
inner: String,
r: TextRange,
},
Raw {
inner: String,
r: TextRange,
},
Code {
inner: String,
r: TextRange,
},
Italic {
children: Vec<AST>,
r: TextRange,
},
Bold {
children: Vec<AST>,
r: TextRange,
},
Emphasis {
children: Vec<AST>,
r: TextRange,
},
Underline {
children: Vec<AST>,
r: TextRange,
},
Strikethrough {
children: Vec<AST>,
r: TextRange,
},
Undercover {
children: Vec<AST>,
r: TextRange,
},
MathInline {
inner: String,
r: TextRange,
},
MathDisplay {
inner: String,
r: TextRange,
},
Link {
inner: SmartLink,
r: TextRange,
},
Escaped {
inner: char,
r: TextRange,
},
Command {
cmd: String,
args: Vec<Value>,
kvs: HashMap<String, Value>,
kind: CommandKind,
r: TextRange,
},
String {
inner: String,
r: TextRange,
},
Integer {
inner: String,
r: TextRange,
},
Decimal {
inner: String,
r: TextRange,
},
Boolean {
inner: bool,
r: TextRange,
},
Array {
inner: Vec<AST>,
r: TextRange,
},
}
impl Default for TextRange {
fn default() -> Self {
Self {
start: (0, 0),
end: (0, 0),
}
}
}
impl Default for AST {
fn default() -> Self {
Self::None
}
}
impl Debug for TextRange {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
write!(f, "({}, {}) → ({}, {})", self.start.0, self.start.1, self.end.0, self.end.1)
}
}
impl Display for AST {
fn fmt(&self, _: &mut Formatter) -> fmt::Result {
unimplemented!()
}
}
impl AST {
pub fn to_vec(self)-> Vec<AST> {
match self {
AST::Statements(v) => {v}
AST::Paragraph { children, .. } => {children}
_ => vec![]
}
}
}