Lex and parse negative numbers

This commit is contained in:
ConnorSkees 2020-02-09 15:08:23 -05:00
parent 2f54de15c5
commit b8d8824db9
2 changed files with 31 additions and 2 deletions

View File

@ -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) {

View File

@ -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(),
'.' => {