2 releases

Uses old Rust 2015

0.1.1 Jul 7, 2019
0.1.0 Jul 7, 2019

#29 in #css-parser

Download history 28/week @ 2024-03-11 35/week @ 2024-03-18 60/week @ 2024-03-25 63/week @ 2024-04-01 21/week @ 2024-04-08 27/week @ 2024-04-15 35/week @ 2024-04-22 40/week @ 2024-04-29 27/week @ 2024-05-06 54/week @ 2024-05-13 42/week @ 2024-05-20 69/week @ 2024-05-27 29/week @ 2024-06-03 23/week @ 2024-06-10 30/week @ 2024-06-17 43/week @ 2024-06-24

128 downloads per month
Used in 6 crates (via azul-css-parser)

MPL-2.0 license

30KB
552 lines

azul-simplecss

Fork of https://github.com/RazrFalcon/simplecss (because lack of maintainer). Added @rules + better parsing on top of original parser.

----aa

A very simple streaming parser/tokenizer for CSS 2.1 data format without heap allocations.

Since it's very simple we will start with limitations:

Limitations

  • At-rules are not supported.

    @import, @media, etc. will lead to a parsing error.

  • The ident token must be ASCII only.

    CSS like #аттр { имя:значение } will lead to a parsing error.

  • Property values are not parsed.

    In CSS like * { width: 5px } you will get width property with 5px values as a string.

  • Attribute selector rule is not parsed.

    [foo~="warning"] will be parsed as Token::AttributeSelector("foo~=\"warning\"").

  • There are no data validation.

    • Pseudo-class tokens can contain any text, language pseudo-class can contain any text or even none.
    • Declarations can contain any kind of names and values.
  • All comments will be ignored.

    They didn't have it's own Token item.

  • CDO/CDC comments are not supported.

  • Parser is case sensitive. All keywords should be lowercase.

  • Unicode escape, like \26, is not supported.

  • No spec-defined error handling.

    If something will go wrong you will get an error. Parser will not recover an invalid input. Details.

Where to use

simplecss can be useful for parsing a very simple or predefined CSS.

It's tiny, dependency free and pretty fast.

Examples

Simple

* { color : red }
| | |           ||
| | |           |+- Token::EndOfStream
| | |           +- Token::BlockEnd
| | +- Token::Declaration("color", "red")
| +- Token::BlockStart
+- Token::UniversalSelector

Complex

div#x:first-letter em[id] + .hh1 { color : red }
|  | |            || |    | |    | |           ||
|  | |            || |    | |    | |           |+- Token::EndOfStream
|  | |            || |    | |    | |           +- Token::BlockEnd
|  | |            || |    | |    | +- Token::Declaration("color", "red")
|  | |            || |    | |    +- Token::BlockStart
|  | |            || |    | +- Token::ClassSelector("hh1")
|  | |            || |    +- Token::Combinator(Combinator::Plus)
|  | |            || +- Token::AttributeSelector("id")
|  | |            |+- Token::TypeSelector("em")
|  | |            +- Token::Combinator(Combinator::Space)
|  | +- Token::PseudoClass("first-letter")
|  +- Token::IdSelector("x")
+- Token::TypeSelector("div")

No runtime deps