-
-
Notifications
You must be signed in to change notification settings - Fork 514
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(css_parser):simple block #976
Conversation
…nto feat-css-block
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.
Great start with the CSS block! I have some questions and proposals to discuss.
✅ Deploy Preview for rad-torte-839a59 ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Hello, I have finished the review of the todo, can you help me to review again @denbezrukov |
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.
Thank you for your contribution! We need to address several issues, but overall, it looks good and is a valuable addition to the project.
|
||
#[inline] | ||
fn is_unit_str(unit: &str) -> bool { | ||
is_length_unit(unit) |
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.
I'm wondering if we need to have "em", "rem" as keywords.
See
biome/xtask/codegen/src/css_kinds_src.rs
Line 47 in 6739a51
keywords: &[ |
biome/xtask/codegen/css.ungram
Line 223 in 6739a51
name: ('matches' | 'not' | 'is' | 'where') |
biome/crates/biome_css_parser/src/lexer/mod.rs
Lines 727 to 770 in 6739a51
b"media" => MEDIA_KW, | |
b"keyframes" => KEYFRAMES_KW, | |
b"and" => AND_KW, | |
b"only" => ONLY_KW, | |
b"or" => OR_KW, | |
b"i" => I_KW, | |
b"s" => S_KW, | |
b"important" => IMPORTANT_KW, | |
b"from" => FROM_KW, | |
b"to" => TO_KW, | |
b"var" => VAR_KW, | |
b"highlight" => HIGHLIGHT_KW, | |
b"part" => PART_KW, | |
b"has" => HAS_KW, | |
b"dir" => DIR_KW, | |
b"global" => GLOBAL_KW, | |
b"local" => LOCAL_KW, | |
b"-moz-any" => _MOZ_ANY_KW, | |
b"-webkit-any" => _WEBKIT_ANY_KW, | |
b"past" => PAST_KW, | |
b"current" => CURRENT_KW, | |
b"future" => FUTURE_KW, | |
b"host" => HOST_KW, | |
b"host-context" => HOST_CONTEXT_KW, | |
b"not" => NOT_KW, | |
b"matches" => MATCHES_KW, | |
b"is" => IS_KW, | |
b"where" => WHERE_KW, | |
b"lang" => LANG_KW, | |
b"of" => OF_KW, | |
b"n" => N_KW, | |
b"even" => EVEN_KW, | |
b"odd" => ODD_KW, | |
b"nth-child" => NTH_CHILD_KW, | |
b"nth-last-child" => NTH_LAST_CHILD_KW, | |
b"nth-of-type" => NTH_OF_TYPE_KW, | |
b"nth-last-of-type" => NTH_LAST_OF_TYPE_KW, | |
b"nth-col" => NTH_COL_KW, | |
b"nth-last-col" => NTH_LAST_COL_KW, | |
b"ltr" => LTR_KW, | |
b"rtl" => RTL_KW, | |
b"charset" => CHARSET_KW, | |
b"color-profile" => COLOR_PROFILE_KW, | |
b"counter-style" => COUNTER_STYLE_KW, |
We can move them to keywords in another 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.
I tried but got the following error, we can fix it in the next pr.
-> biome\crates\biome_parser\src\token_set.rs:46:18
|
46 | _ => [0, 1u128 << (num - 127)],
| ^^^^^^^^^^^^^^^^^^^^ attempt to shift left by `170_usize`, which would overflow
We may need a modification such as the following
--- a/crates/biome_parser/src/token_set.rs
+++ b/crates/biome_parser/src/token_set.rs
@@ -2,10 +2,10 @@ use biome_rowan::SyntaxKind;
use std::marker::PhantomData;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
-pub struct TokenSet<K: SyntaxKind>([u128; 2], PhantomData<K>);
+pub struct TokenSet<K: SyntaxKind>([u128; 3], PhantomData<K>);
impl<K: SyntaxKind> TokenSet<K> {
- pub const EMPTY: TokenSet<K> = TokenSet([0; 2], PhantomData);
+ pub const EMPTY: TokenSet<K> = TokenSet([0; 3], PhantomData);
pub fn singleton(kind: K) -> Self {
unsafe { TokenSet::from_raw(kind.to_raw().0) }
@@ -13,7 +13,7 @@ impl<K: SyntaxKind> TokenSet<K> {
pub const fn union(self, other: TokenSet<K>) -> Self {
TokenSet(
- [self.0[0] | other.0[0], self.0[1] | other.0[1]],
+ [self.0[0] | other.0[0], self.0[1] | other.0[1],self.0[2] | other.0[2]],
PhantomData,
)
}
@@ -23,7 +23,8 @@ impl<K: SyntaxKind> TokenSet<K> {
let num = kind as usize;
match num {
0..=127 => self.0[0] & mask(kind)[0] != 0,
- _ => self.0[1] & mask(kind)[1] != 0,
+ 128..=255 => self.0[1] & mask(kind)[1] != 0,
+ _ => self.0[2] & mask(kind)[2] != 0,
}
}
@@ -39,11 +40,12 @@ impl<K: SyntaxKind> TokenSet<K> {
}
}
-const fn mask(kind: u16) -> [u128; 2] {
+const fn mask(kind: u16) -> [u128; 3] {
let num = kind as usize;
match num {
- 0..=127 => [1u128 << num, 0],
- _ => [0, 1u128 << (num - 127)],
+ 0..=127 => [1u128 << num, 0,0],
+ 128..=255 => [0,1u128 << (num - 127), 0],
+ _ => [0,0, 1u128 << (num - 255)],
}
}
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.
Oh, I see..
Maybe we can remove all colours from keywords for now.
Anyway we can do it in another PR.
use super::{parse_regular_identifier, parse_regular_number}; | ||
|
||
#[inline] | ||
pub(crate) fn is_at_css_dimension(p: &mut CssParser) -> bool { |
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.
I guess that it's better to remove css
prefix. What do you think?
I believe that we need the prefix only for public functions.
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.
done
@suxin2017 Thank you sincerely for your valuable contribution. |
you are welcome |
#268
Summary
Supports simple css block implementation
support simple func
support declaration list
Support the content
! // is not supported
Test Plan
cargo test -p biome_css_parser -- --test spec_test::quick_test --ignored