Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Rust implementation of CSS Syntax Level 3

License

NotificationsYou must be signed in to change notification settings

servo/rust-cssparser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

Documentation

Rust implementation ofCSS 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 aContent-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 oftokens.Tokenization never fails, although the output may containerror tokens.

  • This flat stream of tokens is then transformed into a tree ofcomponent values,which are eitherpreserved 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 declarationsare still just lists of component values at this point.SeetheToken enum for the data structure.

  • The last step of a full CSS parser isparsing the remaining component valuesintoSelectors,specific CSS properties, etc.

    By design, rust-cssparser does not do this last stepwhich 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 parseCSS colorsandAn+B (the argument to:nth-child() and related selectors.

    SeeServo’sstyle cratefor an example of a parser based on rust-cssparser.

About

Rust implementation of CSS Syntax Level 3

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors61


[8]ページ先頭

©2009-2025 Movatter.jp