summaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 0f6d01d..7d0e7f2 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -8,6 +8,20 @@ use std::io::Read;
8mod lexer; 8mod lexer;
9mod parser; 9mod parser;
10 10
11#[derive(Debug,Copy,Clone)]
12pub struct Position {
13 pub line: u32,
14 pub column: u32,
15}
16
17impl Position {
18 pub fn new( line: u32, column: u32 ) -> Self {
19 Self {
20 line, column,
21 }
22 }
23}
24
11pub struct Crimtag { 25pub 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 {
104mod tests { 118mod 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|]
142That was fun!"#);
125 } 143 }
126} 144}