diff --git a/Cargo.lock b/Cargo.lock index 31d9749..58c87ba 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -35,7 +35,7 @@ checksum = "6c20b6793b5c2fa6553b250154b78d6d0db37e72700ae35fad9387a46f487c97" [[package]] name = "simplecss" -version = "0.2.2" +version = "0.2.3" dependencies = [ "env_logger", "log", diff --git a/Cargo.toml b/Cargo.toml index 275d0a7..dcb474f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "simplecss" -version = "0.2.2" +version = "0.2.3" license = "Apache-2.0 OR MIT" edition = "2021" description = "A simple CSS 2 parser and selector." diff --git a/examples/parse.rs b/examples/parse.rs index c355d17..464c30c 100644 --- a/examples/parse.rs +++ b/examples/parse.rs @@ -3,11 +3,11 @@ //! Parse -use std::io::{Read, Write}; +use std::io::Write; fn main() { let args: Vec<_> = std::env::args().collect(); - if args.len() != 2 { + if args.len() < 2 || 3 < args.len() { println!("Usage:\n\tparse style.css\n\tparse - 'p {{ color:red }}'"); std::process::exit(1); } @@ -17,12 +17,8 @@ fn main() { .format(|buf, record| writeln!(buf, "{}: {}", record.level(), record.args())) .init(); - let text = if args[1] == "-" { - let mut buffer = String::new(); - let stdin = std::io::stdin(); - let mut handle = stdin.lock(); - handle.read_to_string(&mut buffer).unwrap(); - buffer + let text = if args[1] == "-" && args.len() == 3 { + args[2].clone() } else { std::fs::read_to_string(&args[1]).unwrap() }; diff --git a/src/selector.rs b/src/selector.rs index e902933..d7e9e77 100644 --- a/src/selector.rs +++ b/src/selector.rs @@ -54,6 +54,7 @@ pub enum PseudoClass<'a> { Active, Focus, Lang(&'a str), + Root, } impl fmt::Display for PseudoClass<'_> { @@ -66,6 +67,7 @@ impl fmt::Display for PseudoClass<'_> { PseudoClass::Active => write!(f, "active"), PseudoClass::Focus => write!(f, "focus"), PseudoClass::Lang(lang) => write!(f, "lang({lang})"), + PseudoClass::Root => write!(f, "root"), } } } @@ -314,6 +316,7 @@ pub(crate) fn parse(text: &str) -> (Option>, usize) { "hover" => PseudoClass::Hover, "active" => PseudoClass::Active, "focus" => PseudoClass::Focus, + "root" => PseudoClass::Root, _ => { warn!("':{}' is not supported. Selector skipped.", ident); return (None, tokenizer.stream.pos()); diff --git a/src/stream.rs b/src/stream.rs index ce49901..d918dd1 100644 --- a/src/stream.rs +++ b/src/stream.rs @@ -16,7 +16,7 @@ impl CssCharExt for char { #[inline] fn is_name_start(&self) -> bool { match *self { - '_' | 'a'..='z' | 'A'..='Z' => true, + '-' | '_' | 'a'..='z' | 'A'..='Z' => true, _ => self.is_non_ascii() || self.is_escape(), } } diff --git a/tests/warnings.rs b/tests/warnings.rs index f160ddb..a2fef48 100644 --- a/tests/warnings.rs +++ b/tests/warnings.rs @@ -4,24 +4,17 @@ //! Warnings fn run_process(input: &str) -> String { - use std::io::Write; use std::process::Stdio; - let mut child = std::process::Command::new("target/debug/examples/parse") + let child = std::process::Command::new("target/debug/examples/parse") .arg("-") + .arg(input) .stdin(Stdio::piped()) .stdout(Stdio::null()) .stderr(Stdio::piped()) .spawn() .unwrap(); - child - .stdin - .as_mut() - .unwrap() - .write_all(input.as_bytes()) - .unwrap(); - let output = child.wait_with_output().expect("Failed to read stdout"); String::from_utf8(output.stderr).unwrap() }