Skip to content

Rust cssparser code walk 2013 08 02

Josh Matthews edited this page Aug 2, 2013 · 5 revisions

Notes were not taken during the meeting, but here is a summary of what was discussed.

Architecture

  • rust-cssparser is based on the CSS3 Syntax Module.
  • Currently rust-cssparser consumes a ~str and returns a tree of ComponentValue. The tokenizer and the component value parser are intertwined, in that when a (, [, or { token is encountered, it parses the block and then continues tokenizing.
  • The unit of Dimension component values (eg. em in 1.4em) is stored as a ~str. It could be an enum of known units.
  • Component values can be parsed into generic rules and declarations that contain component values themselves.
  • Further parsing is required by a style system to parse specific rules and properties from the ComponentValue parts. Each property will need a custom parser. For example font-family and font-weight accept very different things.

Discussion on Architecture

  • It would be good to move from expecting ~str as input to using a Reader. The tokenizer/parser need 2 characters of lookahead. This seems reasonably easy to do.
  • There is no string interning, but this will need to be in place later for performance reasons.
  • There is a desire to make the CSS parser and selector matching system usable by other projects, but it's not quite clear how to do this yet, since selector matching is a pretty core component of the browser.
  • Parallelism: if subparsers are needed for the ComponentValues then we could run these in parallel. This will need testing to see if it is a win.
  • Numeric literals can be stored as i32 and f32.

Further Work Needed

  • Style system including parsers for properties, etc.
  • String interning
  • Performance comparison against netsurfcss - suggestion of jQuery UI and bootstrap.
Clone this wiki locally