| [ Web Proxy ] |
| Viewing: https://docs.rs/cssparser | [Back] [Original] |
Implementation of CSS Syntax Module Level 3 for Rust.
Everything is based on Parser objects, which borrow a &str input.
If you have bytes (from a file, the network, or something)
and want to support character encodings other than UTF-8,
see the stylesheet_encoding function,
which can be used together with rust-encoding or encoding-rs.
input: &mut cssparser::Parser parameterResult<_, ()>Ok(_),
the function must have consumed exactly the amount of input that represents the parsed value.Err(()), any amount of input may have been consumed.As a consequence, when calling another parsing function, either:
Err(()) return value must be propagated.
This happens by definition for tail calls,
and can otherwise be done with the ? operator.Parser::try call.
try takes a closure that takes a Parser and returns a Result,
calls it once,
and returns itself that same result.
If the result is Err,
it restores the position inside the input to the one saved before calling the closure.Examples:
// 'none' | <image>
fn parse_background_image(context: &ParserContext, input: &mut Parser)
-> Result<Option<Image>, ()> {
if input.try_parse(|input| input.expect_ident_matching("none")).is_ok() {
Ok(None)
} else {
Image::parse(context, input).map(Some) // tail call
}
}// [ <length> | <percentage> ] [ <length> | <percentage> ]?
fn parse_border_spacing(_context: &ParserContext, input: &mut Parser)
-> Result<(LengthOrPercentage, LengthOrPercentage), ()> {
let first = LengthOrPercentage::parse?;
let second = input.try_parse(LengthOrPercentage::parse).unwrap_or(first);
(first, second)
}Delimiters constants.$name(&str) -> Option<&'static $ValueType>ascii_case_insensitive_map! using a phf map.
See ascii_case_insensitive_map! above for docsmatch_byte macro.match expression with string patterns,
matching case-insensitively in the ASCII range.fmt::Write adapter that escapes text for writing as a double-quoted CSS string.
Quotes are not included.Parser::parse_until* methods.&str input,
yields Tokens,
and keeps track of nested blocks and functions.Parser (including the position within the input),
obtained from the Parser::position method.BasicParseErrorParseErrorneeds_separator_when_before method.!important.:nth-child() selector.
The input is typically the arguments of a function,
in which case the caller needs to check if the arguments parser is exhausted.
Return Ok((A, B)), or an Err(..) for a syntax error.( /* ... */ ) parenthesis in an @supports prelude.CSSStyleSheet.insertRule.| Web Proxy Viewer | New URL | Original Page |