summaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs75
1 files changed, 75 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
new file mode 100644
index 0000000..57f777e
--- /dev/null
+++ b/src/lib.rs
@@ -0,0 +1,75 @@
1use std::path::{PathBuf,Path};
2use std::collections::HashMap;
3use core::error::Error;
4
5mod lexer;
6
7pub struct Tx {
8 fragments: HashMap<String, Fragment>,
9}
10
11enum FragmentSource {
12 File {
13 path: PathBuf,
14 loaded: usize,
15 }
16}
17
18struct Fragment {
19 name: String,
20 source: FragmentSource,
21 sections: HashMap<String, Section>,
22}
23
24struct Section {
25 name: String,
26 ast_root: Token,
27}
28
29type Properties = HashMap<String, String>;
30
31enum Token {
32 Root(Vec<Token>),
33 Fragment(String,Properties,Vec<Token>),
34 Section(String,Properties,Vec<Token>),
35 Text(String),
36
37}
38
39struct State {
40}
41
42impl Tx {
43 pub fn new() -> Self {
44 Self {
45 fragments: HashMap::new(),
46 }
47 }
48
49 pub fn load(path: &Path) -> Result<(),Box::<dyn Error>> {
50 Ok(())
51 }
52
53 pub fn parse(data: String) -> Result<(),Box::<dyn Error>> {
54 Ok(())
55 }
56}
57
58#[cfg(test)]
59mod tests {
60 use super::*;
61
62 #[test]
63 fn lexing() {
64 let data = r#"Leading comment: [|fragment "basic"|>Hello there <|fragment|] Trailing text"#;
65 let ll = lexer::Lexer::new( &data );
66 for sym in ll {
67 if let lexer::Symbol::Error{line,row,what} = sym {
68 println!("Error {}:{}: {}", line, row, what );
69 break;
70 } else {
71 println!("Symbol: {:?}", sym );
72 }
73 }
74 }
75}