diff --git a/src/color/mod.rs b/src/color/mod.rs index e5d0bab..6dee515 100644 --- a/src/color/mod.rs +++ b/src/color/mod.rs @@ -112,7 +112,7 @@ impl Color { mut hue: Number, mut saturation: Number, mut luminance: Number, - alpha: Number, + mut alpha: Number, ) -> Self { macro_rules! clamp { @@ -128,6 +128,7 @@ impl Color { clamp!(hue, 0, 360); clamp!(saturation, 0, 1); clamp!(luminance, 0, 1); + clamp!(alpha, 0, 1); if saturation.clone() == Number::from(0) { let luminance = if luminance > Number::from(100) { diff --git a/src/lexer.rs b/src/lexer.rs index 11882eb..f256c13 100644 --- a/src/lexer.rs +++ b/src/lexer.rs @@ -35,7 +35,35 @@ impl<'a> Iterator for Lexer<'a> { }}; } let kind: TokenKind = match self.buf.peek().unwrap_or(&'\0') { - 'a'..='z' | 'A'..='Z' | '-' | '_' => self.lex_ident(), + 'a'..='z' | 'A'..='Z' | '_' => self.lex_ident(), + '-' => { + self.buf.next(); + self.pos.next_char(); + match self.buf.peek().unwrap() { + '0'..='9' => match self.lex_num() { + TokenKind::Number(n) => { + let mut s = String::from("-"); + s.push_str(&n); + TokenKind::Number(s) + } + _ => unsafe { std::hint::unreachable_unchecked() }, + }, + 'a'..='z' | 'A'..='Z' | '_' | '-' => match self.lex_ident() { + TokenKind::Ident(i) => { + let mut s = String::from("-"); + s.push_str(&i); + TokenKind::Ident(s) + } + TokenKind::Keyword(kw) => { + let mut s = String::from("-"); + s.push_str(&kw.to_string()); + TokenKind::Ident(s) + } + _ => unsafe { std::hint::unreachable_unchecked() }, + } + _ => TokenKind::Symbol(Symbol::Minus), + } + } '@' => self.lex_at_rule(), '0'..='9' => self.lex_num(), '.' => {