-
Notifications
You must be signed in to change notification settings - Fork 664
feat(rome_css_syntax): codegen for CSS grammar #2363
Conversation
1b25694
to
63cb336
Compare
Deploying with Cloudflare Pages
|
3526e09
to
dd0084d
Compare
Parser conformance results on ubuntu-latestjs/262
jsx/babel
ts/babel
ts/microsoft
|
8020b75
to
487970d
Compare
487970d
to
8bc7e80
Compare
|
||
impl From<u16> for CssSyntaxKind { | ||
fn from(d: u16) -> CssSyntaxKind { | ||
assert!(d <= (CssSyntaxKind::__LAST as u16)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Equals here make sense? Given that __LAST
is just a marker and not a node.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using equals ensures it's symmetric with the impl From<CssSyntaxKind> for u16
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a copy paste from rome_js_syntax
. I think it would make senses to keep debug_assert
, or remove it. Although the same change should be applied to the other crate too. I would leave it out of the scope for now, for this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should stay as an assert!
since it's guarding unsafe code, if something goes wrong with this conversion a panic will be a lot easier to debug than some random undefined behavior down the line when the code matches on an invalid enum
|
||
impl From<u16> for CssSyntaxKind { | ||
fn from(d: u16) -> CssSyntaxKind { | ||
assert!(d <= (CssSyntaxKind::__LAST as u16)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using equals ensures it's symmetric with the impl From<CssSyntaxKind> for u16
Summary
This PR is part of #2350
It starts to spin the ball around multi language support, by generating the code for the CSS grammar. The scope of this PR is exclusively having a code generation that works and emits code that compiles.
There are few things won't be tackled in this PR:
rome_js_syntax
androme_css_syntax
; forAstNode
is repeated at the moment and it's intentional for now;css.ungram
; it is still incomplete and it doesn't hold the grammar, the code was shown to Nicholas and Micha few weeks back to show them the differences from the JS grammar and if we can achieve that;What's been done:
rome_css_syntax
crate that contains the generated code and some other code related to the syntax. Some code is copied and repeated;LanguageKind
to generate different code accordingly to the value of the variant;$=
which causes issues inside Rust ($
is mistaken as a pattern of a macro), so I had to play withproc_macro2
to generate the correct code;rome_syntax
where we will have our shared syntax, such asAstNode
,AstSeparatedList
, etc.Test Plan
cargo check
should compile