summaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorMike Buland <mike@xagasoft.com>2026-06-07 16:37:28 -0700
committerMike Buland <mike@xagasoft.com>2026-06-07 16:37:28 -0700
commit83ab8c67beecfc05684c9400e29f7d77225d3af9 (patch)
tree2ec5042814bfb8a485797672cfef66fea04fd85f /src/lib.rs
parent3dd9ca69340512e42867b43db689e494bada2000 (diff)
downloadcrimtag-83ab8c67beecfc05684c9400e29f7d77225d3af9.tar.gz
crimtag-83ab8c67beecfc05684c9400e29f7d77225d3af9.tar.bz2
crimtag-83ab8c67beecfc05684c9400e29f7d77225d3af9.tar.xz
crimtag-83ab8c67beecfc05684c9400e29f7d77225d3af9.zip
Cleaned up a lot of parsing code.
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 7d0e7f2..5e912cf 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -2,8 +2,6 @@ use std::path::{PathBuf,Path};
2use std::collections::HashMap; 2use std::collections::HashMap;
3use core::error::Error; 3use core::error::Error;
4use std::time::SystemTime; 4use std::time::SystemTime;
5use std::fs::File;
6use std::io::Read;
7 5
8mod lexer; 6mod lexer;
9mod parser; 7mod parser;
@@ -57,6 +55,14 @@ enum Token {
57 Fragment(String,Properties,Vec<Token>), 55 Fragment(String,Properties,Vec<Token>),
58 Section(String,Properties,Vec<Token>), 56 Section(String,Properties,Vec<Token>),
59 Text(String), 57 Text(String),
58 Literal(String),
59 /*
60 Tag{
61 name: String,
62 params: Vec<String>,
63 props: Properties,
64 children: Vec<Token>
65 },*/
60} 66}
61 67
62struct State { 68struct State {
@@ -97,14 +103,14 @@ impl Crimtag {
97 }; 103 };
98 104
99 let mut p = parser::Parser::new(); 105 let mut p = parser::Parser::new();
100 p.parse( self, &String::from_utf8( std::fs::read( path )? )? ); 106 p.parse( &String::from_utf8( std::fs::read( path )? )? );
101 107
102 Ok(()) 108 Ok(())
103 } 109 }
104 110
105 pub fn load_static(&mut self, data: &str) -> Result<(),Box::<dyn Error>> { 111 pub fn load_static(&mut self, data: &str) -> Result<(),Box::<dyn Error>> {
106 let mut p = parser::Parser::new(); 112 let mut p = parser::Parser::new();
107 p.parse( self, &data ); 113 p.parse( &data );
108 114
109 Ok(()) 115 Ok(())
110 } 116 }
@@ -137,8 +143,12 @@ mod tests {
137 #[test] 143 #[test]
138 fn parsing() { 144 fn parsing() {
139 let mut ct = Crimtag::new(); 145 let mut ct = Crimtag::new();
140 ct.load_static(r#"Here is a sample 146 if let Err(e) = ct.load_static(r#"Here is a sample
141[|frament "index" theme="standard"|><html><body>Hi</body></html><|fragment|] 147[|fragment "index" theme="standard"|><html><body>Hi</body></html><|fragment|]
142That was fun!"#); 148That was fun!"#) {
149 println!("Error: {:?}", e );
150 } else {
151 println!("It finished");
152 }
143 } 153 }
144} 154}