handle backticks and control characters

This commit is contained in:
ConnorSkees 2020-03-21 17:29:12 -04:00
parent 502da79d42
commit 5914a07d22
4 changed files with 26 additions and 3 deletions

View File

@ -61,6 +61,8 @@ pub enum Symbol {
QuestionMark,
/// \
BackSlash,
/// `
BackTick
}
impl Display for Symbol {
@ -95,6 +97,7 @@ impl Display for Symbol {
Self::SingleQuote => write!(f, "'"),
Self::QuestionMark => write!(f, "?"),
Self::BackSlash => write!(f, "\\"),
Self::BackTick => write!(f, "`"),
}
}
}
@ -133,6 +136,7 @@ impl TryFrom<char> for Symbol {
'\'' => Ok(Self::SingleQuote),
'?' => Ok(Self::QuestionMark),
'\\' => Ok(Self::BackSlash),
'`' => Ok(Self::BackTick),
_ => Err("invalid symbol"),
}
}

View File

@ -133,7 +133,12 @@ impl<'a> Iterator for Lexer<'a> {
'<' => symbol!(self, Lt),
'>' => symbol!(self, Gt),
'^' => symbol!(self, Xor),
'`' => symbol!(self, BackTick),
'\0' => return None,
c if c.is_control() => {
self.buf.next();
TokenKind::Error("Expected expression.".into())
},
_ => self.lex_ident(),
};
self.pos.next_char();

View File

@ -5,5 +5,9 @@ mod macros;
error!(
nothing_after_decimal,
"a {\n color: 1.;\n}\n", "Error: Expected digit."
"a {color: 1.;}", "Error: Expected digit."
);
error!(
ascii_control_character,
"a {color: ;}", "Error: Expected expression."
);

View File

@ -47,12 +47,22 @@ test!(
"a {\n color: red;\n}\n"
);
test!(
utf8_ident_before,
utf8_ident_before_len,
"a {\n color: length(😀red);\n}\n",
"@charset \"UTF-8\";\na {\n color: 1;\n}\n"
);
test!(
utf8_ident_after,
utf8_ident_before,
"a {\n color: 😀red;\n}\n",
"@charset \"UTF-8\";\na {\n color: 😀red;\n}\n"
);
test!(
utf8_ident_after_len,
"a {\n color: length(red😁)\n}\n",
"@charset \"UTF-8\";\na {\n color: 1;\n}\n"
);
test!(
utf8_ident_after,
"a {\n color: red😁\n}\n",
"@charset \"UTF-8\";\na {\n color: red😁;\n}\n"
);