forked from parcel-bundler/lightningcss
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathident.rs
More file actions
31 lines (26 loc) · 950 Bytes
/
ident.rs
File metadata and controls
31 lines (26 loc) · 950 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use cssparser::*;
use crate::traits::{Parse, ToCss};
use crate::printer::Printer;
use crate::error::{ParserError, PrinterError};
/// https://www.w3.org/TR/css-values-4/#custom-idents
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct CustomIdent(pub String);
impl Parse for CustomIdent {
fn parse<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i, ParserError<'i>>> {
let location = input.current_source_location();
let ident = input.expect_ident()?;
let valid = match_ignore_ascii_case! { ident,
"initial" | "inherit" | "unset" | "default" | "revert" => false,
_ => true
};
if !valid {
return Err(location.new_unexpected_token_error(Token::Ident(ident.clone())))
}
Ok(CustomIdent(ident.as_ref().into()))
}
}
impl ToCss for CustomIdent {
fn to_css<W>(&self, dest: &mut Printer<W>) -> Result<(), PrinterError> where W: std::fmt::Write {
dest.write_ident(&self.0)
}
}