From 3dd9ca69340512e42867b43db689e494bada2000 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Fri, 5 Jun 2026 14:46:35 -0700 Subject: Symbols have a wrapper with positional data now. It required some weird changes, I'm not sure I'm happy with them all yet, but I"m getting closer. It parses all basics, now we need to build an AST so it's actually useful :-P --- src/lib.rs | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'src/lib.rs') 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; mod lexer; mod parser; +#[derive(Debug,Copy,Clone)] +pub struct Position { + pub line: u32, + pub column: u32, +} + +impl Position { + pub fn new( line: u32, column: u32 ) -> Self { + Self { + line, column, + } + } +} + pub struct Crimtag { fragments: HashMap, sources: Vec, @@ -104,13 +118,15 @@ impl Crimtag { mod tests { use super::*; + use crate::lexer::*; + #[test] fn lexing() { let data = r#"Leading comment: [|fragment "basic" something="yeup"|>Hello there <|fragment|] Trailing text"#; let ll = lexer::Lexer::new( &data ); for sym in ll { - if let lexer::Symbol::Error{line,row,what} = sym { - println!("Error {}:{}: {:?}", line, row, what ); + if let SymbolType::Error{what} = sym.symbol() { + println!("Error {}:{}: {:?}", sym.start().line, sym.start().column, what ); break; } else { println!("Symbol: {:?}", sym ); @@ -121,6 +137,8 @@ mod tests { #[test] fn parsing() { let mut ct = Crimtag::new(); - ct.load_static(r#"Here is a sample [|frament "index" theme="standard"|>Hi<|fragment|] That was fun!"#); + ct.load_static(r#"Here is a sample +[|frament "index" theme="standard"|>Hi<|fragment|] +That was fun!"#); } } -- cgit v1.2.3