Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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."
Expand Down
12 changes: 4 additions & 8 deletions examples/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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()
};
Expand Down
3 changes: 3 additions & 0 deletions src/selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ pub enum PseudoClass<'a> {
Active,
Focus,
Lang(&'a str),
Root,
}

impl fmt::Display for PseudoClass<'_> {
Expand All @@ -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"),
}
}
}
Expand Down Expand Up @@ -314,6 +316,7 @@ pub(crate) fn parse(text: &str) -> (Option<Selector<'_>>, 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());
Expand Down
2 changes: 1 addition & 1 deletion src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
}
Expand Down
11 changes: 2 additions & 9 deletions tests/warnings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
Loading