diff options
Diffstat (limited to 'src/lib.rs')
| -rw-r--r-- | src/lib.rs | 24 |
1 files changed, 21 insertions, 3 deletions
| @@ -8,6 +8,20 @@ use std::io::Read; | |||
| 8 | mod lexer; | 8 | mod lexer; |
| 9 | mod parser; | 9 | mod parser; |
| 10 | 10 | ||
| 11 | #[derive(Debug,Copy,Clone)] | ||
| 12 | pub struct Position { | ||
| 13 | pub line: u32, | ||
| 14 | pub column: u32, | ||
| 15 | } | ||
| 16 | |||
| 17 | impl Position { | ||
| 18 | pub fn new( line: u32, column: u32 ) -> Self { | ||
| 19 | Self { | ||
| 20 | line, column, | ||
| 21 | } | ||
| 22 | } | ||
| 23 | } | ||
| 24 | |||
| 11 | pub struct Crimtag { | 25 | pub struct Crimtag { |
| 12 | fragments: HashMap<String, Fragment>, | 26 | fragments: HashMap<String, Fragment>, |
| 13 | sources: Vec<FragmentSource>, | 27 | sources: Vec<FragmentSource>, |
| @@ -104,13 +118,15 @@ impl Crimtag { | |||
| 104 | mod tests { | 118 | mod tests { |
| 105 | use super::*; | 119 | use super::*; |
| 106 | 120 | ||
| 121 | use crate::lexer::*; | ||
| 122 | |||
| 107 | #[test] | 123 | #[test] |
| 108 | fn lexing() { | 124 | fn lexing() { |
| 109 | let data = r#"Leading comment: [|fragment "basic" something="yeup"|>Hello there <|fragment|] Trailing text"#; | 125 | let data = r#"Leading comment: [|fragment "basic" something="yeup"|>Hello there <|fragment|] Trailing text"#; |
| 110 | let ll = lexer::Lexer::new( &data ); | 126 | let ll = lexer::Lexer::new( &data ); |
| 111 | for sym in ll { | 127 | for sym in ll { |
| 112 | if let lexer::Symbol::Error{line,row,what} = sym { | 128 | if let SymbolType::Error{what} = sym.symbol() { |
| 113 | println!("Error {}:{}: {:?}", line, row, what ); | 129 | println!("Error {}:{}: {:?}", sym.start().line, sym.start().column, what ); |
| 114 | break; | 130 | break; |
| 115 | } else { | 131 | } else { |
| 116 | println!("Symbol: {:?}", sym ); | 132 | println!("Symbol: {:?}", sym ); |
| @@ -121,6 +137,8 @@ mod tests { | |||
| 121 | #[test] | 137 | #[test] |
| 122 | fn parsing() { | 138 | fn parsing() { |
| 123 | let mut ct = Crimtag::new(); | 139 | let mut ct = Crimtag::new(); |
| 124 | ct.load_static(r#"Here is a sample [|frament "index" theme="standard"|><html><body>Hi</body></html><|fragment|] That was fun!"#); | 140 | ct.load_static(r#"Here is a sample |
| 141 | [|frament "index" theme="standard"|><html><body>Hi</body></html><|fragment|] | ||
| 142 | That was fun!"#); | ||
| 125 | } | 143 | } |
| 126 | } | 144 | } |
