futursolo / stylist-rs

A CSS-in-Rust styling solution for WebAssembly Applications
https://crates.io/crates/stylist
MIT License
376 stars 22 forks source link

Unified Parser #40

Open futursolo opened 3 years ago

futursolo commented 3 years ago

This issue aims to implement a unified parser that replaces nom and syn::parse:

  1. Accepts both proc_macro2::TokenStream and String as input
  2. Preserves location information in both proc_macro2::Span and string cursor
  3. Emits a custom format with nice error message for string literal and native compile_error! for proc_macro2::TokenStream

Minimum Requirement:

  1. When runtime parser is enabled, it needs to be not bigger than current nom based parser (~70KB before gzipped)
  2. Passes all test cases (feature parity)

Good to Have:

  1. Performance (whilst some performance degradation is acceptable / expected (due to more intermediate steps), the new parser should still have solid performance)
  2. Advanced Diagnostic Information / parser tolerance (The parser should either tolerant any error (like browser) or provide helpful diagnostic information when encountering an error)

Flow: Input(String or proc_macro2::TokenStream) -> Tokenise(stylist::parser::TokenStream) -> Parse(stylist::parser::ast) -> Output(stylist::ast)

There's no ETA for this issue and it will land when the work completes.

futursolo commented 3 years ago

In addition, with the new parser only rely on std and arcstr(which maybe removed if a customised ArcStr is smaller) when parsing string literals, I think it makes sense to make parser available to everyone for debug_assertions in Style and GlobalStyle in debug mode.