40 lines
889 B
Rust
40 lines
889 B
Rust
use crate::doc::{classify_document, ClassifiedLine};
|
|
use crate::eval::{evaluate_document, DocumentResult};
|
|
|
|
pub struct SwiftlyDoc {
|
|
pub text: String,
|
|
pub uuid: String,
|
|
lines: Vec<ClassifiedLine>,
|
|
}
|
|
|
|
impl SwiftlyDoc {
|
|
pub fn new() -> Self {
|
|
SwiftlyDoc {
|
|
text: String::new(),
|
|
uuid: uuid::Uuid::new_v4().to_string(),
|
|
lines: Vec::new(),
|
|
}
|
|
}
|
|
|
|
pub fn with_uuid(uuid: String) -> Self {
|
|
SwiftlyDoc {
|
|
text: String::new(),
|
|
uuid,
|
|
lines: Vec::new(),
|
|
}
|
|
}
|
|
|
|
pub fn set_text(&mut self, text: &str) {
|
|
self.text = text.to_string();
|
|
self.lines = classify_document(text);
|
|
}
|
|
|
|
pub fn classified_lines(&self) -> &[ClassifiedLine] {
|
|
&self.lines
|
|
}
|
|
|
|
pub fn evaluate(&self) -> DocumentResult {
|
|
evaluate_document(&self.text)
|
|
}
|
|
}
|