“newnewnewcss”, the port of Servo to the recently refactored
rust-cssparser, has landed: https://github.com/servo/servo/pull/4689
Please let me know if you find any regression.
If you’re writing or modifying CSS parsing code in Servo (e.g. adding a
new CSS property), you should be aware of and follow the conventions
documented here:
http://servo.github.io/rust-cssparser/cssparser/index.html
Previously, parsing was based on "component values" that were either
tokens, or blocks/function that contained a vector of more component
values, forming a tree. Parsing functions would take a `&ComponentValue`
or `&[ComponentValue]` parameter as their input.
Now the input is represented by a `&mut Parser` that tracks its own
position within the input and yields tokens. When encountering a
function token on block-opening token, you can get another `Parser`
object for the arguments/contents. Otherwise the block is just skipped.
Alternatives can be expressed by saving and restoring the internal state
of the parser. (This is cheap, just copying 16 bytes. However some
tokenization work may be duplicated.) Everything relies heavily on
`Result<_, ()>` types and the `try!` macro (which returns early on
`Err`) to make the code easier to read and maintain. (For what it’s
worth, the diff stat is +1,949/-2,319 lines.)
Finally, string components of tokens now use the `CowString` type to
borrow from the input when possible and avoid many allocations and lots
of copying.
--
Simon Sapin
_______________________________________________
dev-servo mailing list
dev-servo@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-servo