Skip to content

Commit

Permalink
Refactor CSS Parser to rename CssRule to CssQualifiedRule (#1546)
Browse files Browse the repository at this point in the history
  • Loading branch information
denbezrukov authored Jan 12, 2024
1 parent 3bd7a9c commit a6caba8
Show file tree
Hide file tree
Showing 91 changed files with 1,300 additions and 1,281 deletions.
21 changes: 12 additions & 9 deletions crates/biome_css_factory/src/generated/node_factory.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 26 additions & 23 deletions crates/biome_css_factory/src/generated/syntax_factory.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/biome_css_formatter/src/css/any/rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ impl FormatRule<AnyCssRule> for FormatAnyCssRule {
type Context = CssFormatContext;
fn fmt(&self, node: &AnyCssRule, f: &mut CssFormatter) -> FormatResult<()> {
match node {
AnyCssRule::CssRule(node) => node.format().fmt(f),
AnyCssRule::CssQualifiedRule(node) => node.format().fmt(f),
AnyCssRule::CssAtRule(node) => node.format().fmt(f),
AnyCssRule::CssBogusRule(node) => node.format().fmt(f),
}
Expand Down
2 changes: 1 addition & 1 deletion crates/biome_css_formatter/src/css/auxiliary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ pub(crate) mod nth_offset;
pub(crate) mod page_at_rule_block;
pub(crate) mod parameter;
pub(crate) mod parenthesized_expression;
pub(crate) mod qualified_rule;
pub(crate) mod query_feature_boolean;
pub(crate) mod query_feature_plain;
pub(crate) mod query_feature_range;
pub(crate) mod query_feature_range_comparison;
pub(crate) mod query_feature_range_interval;
pub(crate) mod query_feature_reverse_range;
pub(crate) mod root;
pub(crate) mod rule;
pub(crate) mod rule_list_block;
pub(crate) mod scope_edge;
pub(crate) mod scope_range_end;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use crate::prelude::*;
use biome_css_syntax::{CssRule, CssRuleFields};
use biome_css_syntax::{CssQualifiedRule, CssQualifiedRuleFields};
use biome_formatter::write;

#[derive(Debug, Clone, Default)]
pub(crate) struct FormatCssRule;
impl FormatNodeRule<CssRule> for FormatCssRule {
fn fmt_fields(&self, node: &CssRule, f: &mut CssFormatter) -> FormatResult<()> {
let CssRuleFields { prelude, block } = node.as_fields();
pub(crate) struct FormatCssQualifiedRule;
impl FormatNodeRule<CssQualifiedRule> for FormatCssQualifiedRule {
fn fmt_fields(&self, node: &CssQualifiedRule, f: &mut CssFormatter) -> FormatResult<()> {
let CssQualifiedRuleFields { prelude, block } = node.as_fields();

write!(
f,
Expand Down
36 changes: 25 additions & 11 deletions crates/biome_css_formatter/src/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,44 @@ impl IntoFormat<CssFormatContext> for biome_css_syntax::CssRoot {
FormatOwnedWithRule::new(self, crate::css::auxiliary::root::FormatCssRoot::default())
}
}
impl FormatRule<biome_css_syntax::CssRule> for crate::css::auxiliary::rule::FormatCssRule {
impl FormatRule<biome_css_syntax::CssQualifiedRule>
for crate::css::auxiliary::qualified_rule::FormatCssQualifiedRule
{
type Context = CssFormatContext;
#[inline(always)]
fn fmt(&self, node: &biome_css_syntax::CssRule, f: &mut CssFormatter) -> FormatResult<()> {
FormatNodeRule::<biome_css_syntax::CssRule>::fmt(self, node, f)
fn fmt(
&self,
node: &biome_css_syntax::CssQualifiedRule,
f: &mut CssFormatter,
) -> FormatResult<()> {
FormatNodeRule::<biome_css_syntax::CssQualifiedRule>::fmt(self, node, f)
}
}
impl AsFormat<CssFormatContext> for biome_css_syntax::CssRule {
impl AsFormat<CssFormatContext> for biome_css_syntax::CssQualifiedRule {
type Format<'a> = FormatRefWithRule<
'a,
biome_css_syntax::CssRule,
crate::css::auxiliary::rule::FormatCssRule,
biome_css_syntax::CssQualifiedRule,
crate::css::auxiliary::qualified_rule::FormatCssQualifiedRule,
>;
fn format(&self) -> Self::Format<'_> {
#![allow(clippy::default_constructed_unit_structs)]
FormatRefWithRule::new(self, crate::css::auxiliary::rule::FormatCssRule::default())
FormatRefWithRule::new(
self,
crate::css::auxiliary::qualified_rule::FormatCssQualifiedRule::default(),
)
}
}
impl IntoFormat<CssFormatContext> for biome_css_syntax::CssRule {
type Format =
FormatOwnedWithRule<biome_css_syntax::CssRule, crate::css::auxiliary::rule::FormatCssRule>;
impl IntoFormat<CssFormatContext> for biome_css_syntax::CssQualifiedRule {
type Format = FormatOwnedWithRule<
biome_css_syntax::CssQualifiedRule,
crate::css::auxiliary::qualified_rule::FormatCssQualifiedRule,
>;
fn into_format(self) -> Self::Format {
#![allow(clippy::default_constructed_unit_structs)]
FormatOwnedWithRule::new(self, crate::css::auxiliary::rule::FormatCssRule::default())
FormatOwnedWithRule::new(
self,
crate::css::auxiliary::qualified_rule::FormatCssQualifiedRule::default(),
)
}
}
impl FormatRule<biome_css_syntax::CssAtRule> for crate::css::statements::at_rule::FormatCssAtRule {
Expand Down
14 changes: 7 additions & 7 deletions crates/biome_css_parser/src/syntax/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl ParseRecovery for RuleListParseRecovery {
const RECOVERED_KIND: Self::Kind = CSS_BOGUS_RULE;

fn is_at_recovered(&self, p: &mut Self::Parser<'_>) -> bool {
is_at_at_rule(p) || is_at_rule(p)
is_at_at_rule(p) || is_at_qualified_rule(p)
}
}

Expand All @@ -82,8 +82,8 @@ impl ParseNodeList for RuleList {
fn parse_element(&mut self, p: &mut Self::Parser<'_>) -> ParsedSyntax {
if is_at_at_rule(p) {
parse_at_rule(p)
} else if is_at_rule(p) {
parse_rule(p)
} else if is_at_qualified_rule(p) {
parse_qualified_rule(p)
} else {
Absent
}
Expand All @@ -103,13 +103,13 @@ impl ParseNodeList for RuleList {
}

#[inline]
pub(crate) fn is_at_rule(p: &mut CssParser) -> bool {
pub(crate) fn is_at_qualified_rule(p: &mut CssParser) -> bool {
is_at_selector(p)
}

#[inline]
pub(crate) fn parse_rule(p: &mut CssParser) -> ParsedSyntax {
if !is_at_rule(p) {
pub(crate) fn parse_qualified_rule(p: &mut CssParser) -> ParsedSyntax {
if !is_at_qualified_rule(p) {
return Absent;
}

Expand All @@ -118,7 +118,7 @@ pub(crate) fn parse_rule(p: &mut CssParser) -> ParsedSyntax {
SelectorList::default().parse_list(p);

let kind = if parse_or_recover_declaration_list_block(p).is_ok() {
CSS_RULE
CSS_QUALIFIED_RULE
} else {
CSS_BOGUS_RULE
};
Expand Down
2 changes: 1 addition & 1 deletion crates/biome_css_parser/src/syntax/parse_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub(crate) fn expected_selector(p: &CssParser, range: TextRange) -> ParseDiagnos
}

pub(crate) fn expected_any_rule(p: &CssParser, range: TextRange) -> ParseDiagnostic {
expected_any(&["rule", "at rule"], range, p)
expected_any(&["qualified rule", "at rule"], range, p)
}

pub(crate) fn expected_any_declaration_or_at_rule(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ CssRoot {
],
},
},
CssRule {
CssQualifiedRule {
prelude: CssSelectorList [
CssComplexSelector {
left: CssCompoundSelector {
Expand Down Expand Up @@ -263,7 +263,7 @@ CssRoot {
],
},
},
CssRule {
CssQualifiedRule {
prelude: CssSelectorList [
CssComplexSelector {
left: CssCompoundSelector {
Expand Down Expand Up @@ -612,7 +612,7 @@ CssRoot {
0: CONTAINER_KW@203..213 "container" [] [Whitespace(" ")]
1: CSS_BOGUS@213..221
0: INHERIT_KW@213..221 "inherit" [] [Whitespace(" ")]
6: CSS_RULE@221..240
6: CSS_QUALIFIED_RULE@221..240
0: CSS_SELECTOR_LIST@221..237
0: CSS_COMPLEX_SELECTOR@221..227
0: CSS_COMPOUND_SELECTOR@221..226
Expand Down Expand Up @@ -640,7 +640,7 @@ CssRoot {
0: CONTAINER_KW@243..253 "container" [] [Whitespace(" ")]
1: CSS_CUSTOM_IDENTIFIER@253..257
0: IDENT@253..257 "not" [] [Whitespace(" ")]
8: CSS_RULE@257..277
8: CSS_QUALIFIED_RULE@257..277
0: CSS_SELECTOR_LIST@257..273
0: CSS_COMPLEX_SELECTOR@257..263
0: CSS_COMPOUND_SELECTOR@257..262
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ CssRoot {
],
},
},
CssRule {
CssQualifiedRule {
prelude: CssSelectorList [
CssCompoundSelector {
nesting_selector_token: missing (optional),
Expand Down Expand Up @@ -101,7 +101,7 @@ CssRoot {
0: [email protected] "@" [] []
1: [email protected]
0: [email protected] "font-face" [] [Whitespace(" ")]
1: CSS_RULE@11..17
1: CSS_QUALIFIED_RULE@11..17
0: [email protected]
0: [email protected]
0: (empty)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ CssRoot {
},
},
},
CssRule {
CssQualifiedRule {
prelude: CssSelectorList [
CssCompoundSelector {
nesting_selector_token: missing (optional),
Expand Down Expand Up @@ -1122,7 +1122,7 @@ CssRoot {
0: R_PAREN@446..447 ")" [] []
1: SEMICOLON@447..448 ";" [] []
2: R_CURLY@448..451 "}" [Newline("\n"), Whitespace("\t")] []
6: CSS_RULE@451..492
6: CSS_QUALIFIED_RULE@451..492
0: CSS_SELECTOR_LIST@451..457
0: CSS_COMPOUND_SELECTOR@451..457
0: (empty)
Expand Down Expand Up @@ -1481,7 +1481,7 @@ at_rule_keyframes.css:42:2 parse ━━━━━━━━━━━━━━━
at_rule_keyframes.css:47:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× Expected a rule, or an at rule but instead found '}'.
× Expected a qualified rule, or an at rule but instead found '}'.
45transform: translateX(100%);
46}
Expand All @@ -1490,7 +1490,7 @@ at_rule_keyframes.css:47:1 parse ━━━━━━━━━━━━━━━
48 │
49 │ @keyframes slidein {
i Expected a rule, or an at rule here.
i Expected a qualified rule, or an at rule here.
45transform: translateX(100%);
46}
Expand Down Expand Up @@ -1551,7 +1551,7 @@ at_rule_keyframes.css:56:2 parse ━━━━━━━━━━━━━━━
at_rule_keyframes.css:57:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× Expected a rule, or an at rule but instead found '}'.
× Expected a qualified rule, or an at rule but instead found '}'.
55 │ transform: translateX(100%);
56 │ }
Expand All @@ -1560,7 +1560,7 @@ at_rule_keyframes.css:57:1 parse ━━━━━━━━━━━━━━━
58 │
59 │ @keyframes slidein {
i Expected a rule, or an at rule here.
i Expected a qualified rule, or an at rule here.
55transform: translateX(100%);
56}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ CssRoot {
},
},
},
CssRule {
CssQualifiedRule {
prelude: CssSelectorList [
CssCompoundSelector {
nesting_selector_token: missing (optional),
Expand Down Expand Up @@ -417,7 +417,7 @@ CssRoot {
0: CSS_KEYFRAMES_IDENT_SELECTOR@87..93
0: FROM_KW@87..93 "from" [Newline("\n"), Whitespace("\t")] []
2: R_CURLY@93..96 "}" [Newline("\n"), Whitespace("\t")] []
2: CSS_RULE@96..120
2: CSS_QUALIFIED_RULE@96..120
0: CSS_SELECTOR_LIST@96..101
0: CSS_COMPOUND_SELECTOR@96..101
0: (empty)
Expand Down Expand Up @@ -601,7 +601,7 @@ at_rule_keyframes_1.css:12:2 parse ━━━━━━━━━━━━━━━
at_rule_keyframes_1.css:16:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× Expected a rule, or an at rule but instead found '}'.
× Expected a qualified rule, or an at rule but instead found '}'.
14color: blue;
15 │ }
Expand All @@ -610,7 +610,7 @@ at_rule_keyframes_1.css:16:1 parse ━━━━━━━━━━━━━━━
17
18 │ @keyframes name2 {
i Expected a rule, or an at rule here.
i Expected a qualified rule, or an at rule here.
14 │ color: blue;
15 │ }
Expand Down
Loading

0 comments on commit a6caba8

Please sign in to comment.