gecko-dev/third_party/rust/cssparser
Emilio Cobos Álvarez d28fef937a Bug 1563892 - Update cssparser to fix correctness issue with serialization. r=heycam
This issue was also exposed via CSS variables, and I've added a test for that
since it's how it was originally found in bug 1498188.

See https://github.com/w3c/csswg-drafts/issues/4088 and https://github.com/servo/rust-cssparser/pull/251

Differential Revision: https://phabricator.services.mozilla.com/D37148

--HG--
extra : moz-landing-system : lando
2019-07-08 04:51:08 +00:00
..
build Bug 1552695 - Part 2: Revendor dependencies. r=froydnj 2019-05-20 12:22:04 +00:00
docs Bug 1502964 - part 2 - update winapi to froydnj/winapi-rs#aarch64; r=ted.mielczarek 2018-11-02 10:56:08 -04:00
src Bug 1563892 - Update cssparser to fix correctness issue with serialization. r=heycam 2019-07-08 04:51:08 +00:00
.cargo-checksum.json Bug 1563892 - Update cssparser to fix correctness issue with serialization. r=heycam 2019-07-08 04:51:08 +00:00
Cargo.toml Bug 1563892 - Update cssparser to fix correctness issue with serialization. r=heycam 2019-07-08 04:51:08 +00:00
LICENSE
README.md Bug 1563892 - Update cssparser to fix correctness issue with serialization. r=heycam 2019-07-08 04:51:08 +00:00
build.rs Bug 1552695 - Part 2: Revendor dependencies. r=froydnj 2019-05-20 12:22:04 +00:00

README.md

rust-cssparser

Build Status

Documentation

Rust implementation of CSS Syntax Module Level 3

Overview

Parsing CSS involves a series of steps:

  • When parsing from bytes, (e.g. reading a file or fetching an URL from the network,) detect the character encoding (based on a Content-Type HTTP header, an @charset rule, a BOM, etc.) and decode to Unicode text.

    rust-cssparser does not do this yet and just assumes UTF-8.

    This step is skipped when parsing from Unicode, e.g. in an HTML <style> element.

  • Tokenization, a.k.a. lexing. The input, a stream of Unicode text, is transformed into a stream of tokens. Tokenization never fails, although the output may contain error tokens.

  • This flat stream of tokens is then transformed into a tree of component values, which are either preserved tokens, or blocks/functions ({ … }, [ … ], ( … ), foo( … )) that contain more component values.

    rust-cssparser does this at the same time as tokenization: raw tokens are never materialized, you only get component values.

  • Component values can then be parsed into generic rules or declarations. The header and body of rules as well as the value of declarations are still just lists of component values at this point. See the Token enum for the data structure.

  • The last step of a full CSS parser is parsing the remaining component values into Selectors, specific CSS properties, etc.

    By design, rust-cssparser does not do this last step which depends a lot on what you want to do: which properties you want to support, what you want to do with selectors, etc.

    It does however provide some helper functions to parse CSS colors and An+B (the argument to :nth-child() and related selectors.

    See Servos style crate for an example of a parser based on rust-cssparser.