Debian Codegraph @

examples/parse.rs

raw symbols SCIP
1 // Copyright 2019 the SimpleCSS Authors
2 // SPDX-License-Identifier: Apache-2.0 OR MIT
3
4 //! Parse
5
6 use std::io::{Read, Write};
7
8 fn main() {
9 let args: Vec<_> = std::env::args().collect();
10 if args.len() != 2 {
11 println!("Usage:\n\tparse style.css\n\tparse - 'p {{ color:red }}'");
12 std::process::exit(1);
13 }
14
15 std::env::set_var("RUST_LOG", "simplecss=warn");
16 env_logger::builder()
17 .format(|buf, record| writeln!(buf, "{}: {}", record.level(), record.args()))
18 .init();
19
20 let text = if args[1] == "-" {
21 let mut buffer = String::new();
22 let stdin = std::io::stdin();
23 let mut handle = stdin.lock();
24 handle.read_to_string(&mut buffer).unwrap();
25 buffer
26 } else {
27 std::fs::read_to_string(&args[1]).unwrap()
28 };
29
30 let style = simplecss::StyleSheet::parse(&text);
31 println!("{:#?}", style);
32 }