| Crates.io | css-parser-project |
| lib.rs | css-parser-project |
| version | 0.3.0 |
| created_at | 2024-11-12 01:51:49.986771+00 |
| updated_at | 2024-11-13 23:54:28.272387+00 |
| description | This is a parser, developed on Rust, that will take CSS code and parse it, based on adjusted rules. |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1444447 |
| size | 41,977 |
crates.io: https://crates.io/crates/css-parser-project
docs.rs: https://docs.rs/css-parser-project/0.2.0/css_parser_project/
This is a parser program, developed on Rust, that will parse the CSS code (its structure, selectors, properties and basic values).
This parser processes the CSS rules and breaks it into selectors and structures. The grammar includes selectors, values, properties. Parser takes the input CSS code, and on the base of rules creates structure, and saves it to the output like "selector -> declaration" (like the table key:value).
.header {
color: blue;
color: #765abc;
margin: 10px;
padding: 20px;
}

css_block = { selector ~ WHITESPACE* ~ "{" ~ WHITESPACE* ~ properties ~ WHITESPACE* ~ "}" }
selector = { ("#" ~ ASCII_ALPHANUMERIC+ | "." ~ ASCII_ALPHANUMERIC+ | ASCII_ALPHANUMERIC+) }
property = { identifier ~ ": " ~ value ~ ";" }
properties = { property+ }
value = { color | dimension | identifier }
dimension = { DIGIT+ ~ ("." ~ DIGIT+)? ~ (("px" | "em" | "%" | "pt")) }
DIGIT = { '0'..'9' }
hex_color = { "#" ~ hex_digit ~ hex_digit ~ hex_digit ~ hex_digit ~ hex_digit ~ hex_digit }
hex_digit = { "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "a" | "b" | "c" | "d" | "e" | "f" }
color = { "blue" | "red" | "green" | "yellow" | "black" | "white" | hex_color }
identifier = { ASCII_ALPHANUMERIC+ }
WHITESPACE = _{ " " | "\t" | "\n" | "\r" }