diff --git a/crates/simplexpr/src/parser/lexer.rs b/crates/simplexpr/src/parser/lexer.rs index 66ba6f5..166befc 100644 --- a/crates/simplexpr/src/parser/lexer.rs +++ b/crates/simplexpr/src/parser/lexer.rs @@ -97,4 +97,5 @@ impl<'input> Iterator for Lexer<'input> { fn test_simplexpr_lexer() { use itertools::Itertools; insta::assert_debug_snapshot!(Lexer::new(0, 0, r#"(foo + - "()" "a\"b" true false [] 12.2)"#).collect_vec()); + insta::assert_debug_snapshot!(Lexer::new(0, 0, r#"" " + music"#).collect_vec()); } diff --git a/crates/simplexpr/src/parser/snapshots/simplexpr__parser__lexer__simplexpr_lexer-2.snap b/crates/simplexpr/src/parser/snapshots/simplexpr__parser__lexer__simplexpr_lexer-2.snap new file mode 100644 index 0000000..0b21e4b --- /dev/null +++ b/crates/simplexpr/src/parser/snapshots/simplexpr__parser__lexer__simplexpr_lexer-2.snap @@ -0,0 +1,32 @@ +--- +source: crates/simplexpr/src/parser/lexer.rs +expression: "Lexer::new(0, 0, r#\"\" \" + music\"#).collect_vec()" + +--- +[ + Ok( + ( + 0, + StrLit( + "\"\u{f001} \"", + ), + 8, + ), + ), + Ok( + ( + 9, + Plus, + 10, + ), + ), + Ok( + ( + 11, + Ident( + "music", + ), + 16, + ), + ), +] diff --git a/crates/yuck/src/parser/lexer.rs b/crates/yuck/src/parser/lexer.rs index 804dbfa..1d7dac5 100644 --- a/crates/yuck/src/parser/lexer.rs +++ b/crates/yuck/src/parser/lexer.rs @@ -101,13 +101,15 @@ impl Iterator for Lexer { let string = &self.source[self.pos..]; if string.starts_with('{') { - // self.pos += 1; let expr_start = self.pos; let mut in_string = false; loop { if self.pos >= self.source.len() { return None; } + while !self.source.is_char_boundary(self.pos) { + self.pos += 1; + } let string = &self.source[self.pos..]; if string.starts_with('}') && !in_string { @@ -137,7 +139,6 @@ impl Iterator for Lexer { Some(x) => x, None => { self.failed = true; - dbg!(&string); return Some(Err(parse_error::ParseError::LexicalError(Span(self.pos, self.pos, self.file_id)))); } }; @@ -163,4 +164,5 @@ fn test_yuck_lexer() { insta::assert_debug_snapshot!(Lexer::new(0, r#"(foo + - "text" )"#.to_string()).collect_vec()); insta::assert_debug_snapshot!(Lexer::new(0, r#"{ bla "} \" }" " \" "}"#.to_string()).collect_vec()); insta::assert_debug_snapshot!(Lexer::new(0, r#""< \" >""#.to_string()).collect_vec()); + insta::assert_debug_snapshot!(Lexer::new(0, r#"{ " " + music}"#.to_string()).collect_vec()); } diff --git a/crates/yuck/src/parser/snapshots/yuck__parser__lexer__yuck_lexer-4.snap b/crates/yuck/src/parser/snapshots/yuck__parser__lexer__yuck_lexer-4.snap new file mode 100644 index 0000000..558fd17 --- /dev/null +++ b/crates/yuck/src/parser/snapshots/yuck__parser__lexer__yuck_lexer-4.snap @@ -0,0 +1,16 @@ +--- +source: crates/yuck/src/parser/lexer.rs +expression: "Lexer::new(0, r#\"{ \" \" + music}\"#.to_string()).collect_vec()" + +--- +[ + Ok( + ( + 0, + SimplExpr( + "{ \"\u{f001} \" + music}", + ), + 18, + ), + ), +] diff --git a/examples/eww-bar/eww.yuck b/examples/eww-bar/eww.yuck index 8b203ed..1c769f0 100644 --- a/examples/eww-bar/eww.yuck +++ b/examples/eww-bar/eww.yuck @@ -24,8 +24,7 @@ (defwidget music [] (box :class "music" :orientation "h" :space-evenly false :halign "center" - ;{ " " + music})) - {music})) + { " " + music})) (defwidget slider-vol [] (box :class "slider-vol" :orientation "h" :space-evenly "false"