Skip to content

Commit

Permalink
feat(biome_css_parser): parser should recognize multiple semicolons a…
Browse files Browse the repository at this point in the history
…fter a declaration
  • Loading branch information
fireairforce committed Oct 17, 2024
1 parent ea7d35c commit cb7164e
Show file tree
Hide file tree
Showing 11 changed files with 142 additions and 3 deletions.
6 changes: 6 additions & 0 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.

19 changes: 19 additions & 0 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.

Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use biome_css_syntax::CssSyntaxKind::*;
use biome_css_syntax::{CssSyntaxKind, T};
use biome_parser::parse_lists::ParseNodeList;
use biome_parser::parse_recovery::{ParseRecovery, RecoveryResult};
use biome_parser::parsed_syntax::ParsedSyntax;
use biome_parser::parsed_syntax::ParsedSyntax::Absent;
use biome_parser::prelude::ParsedSyntax;
use biome_parser::prelude::ParsedSyntax::{Absent, Present};
use biome_parser::{CompletedMarker, Parser};

#[inline]
Expand Down Expand Up @@ -88,6 +88,10 @@ impl ParseNodeList for DeclarationOrRuleList {
// If either condition is true, the declaration is considered valid.
if matches!(p.last(), Some(T![;])) || p.at(T!['}']) {
Ok(declaration)
}
let marker = p.start();
if p.eat(T![;]) {
Ok(Present(marker.complete(p, CSS_EMPTY_DECLARATION)))
} else {
// If neither condition is met, return an error to indicate parsing failure.
// And rewind the parser to the start of the declaration.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ a {
prop1: --custom;
}

a {
prop1: 1px;
prop2: 2px;;;
}

a {
prop1: 1px;;;
}

div {
flex: 1 1 auto !important;
}
Expand Down
5 changes: 4 additions & 1 deletion crates/biome_css_parser/tests/spec_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,10 @@ pub fn run(test_case: &str, _snapshot_name: &str, test_directory: &str, outcome_
#[test]
pub fn quick_test() {
let code = r#"
µ... {}
.foo {
color: red;
color: blue;;
}
"#;

let root = parse_css(
Expand Down
1 change: 1 addition & 0 deletions crates/biome_css_syntax/src/generated/kind.rs

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

4 changes: 4 additions & 0 deletions crates/biome_css_syntax/src/generated/macros.rs

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

81 changes: 81 additions & 0 deletions crates/biome_css_syntax/src/generated/nodes.rs

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

8 changes: 8 additions & 0 deletions crates/biome_css_syntax/src/generated/nodes_mut.rs

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

3 changes: 3 additions & 0 deletions xtask/codegen/css.ungram
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,9 @@ CssDeclarationWithSemicolon =
declaration: CssDeclaration
';'?

CssEmptyDeclaration =
';'

AnyCssDeclarationBlock =
CssDeclarationBlock
| CssBogusBlock
Expand Down
1 change: 1 addition & 0 deletions xtask/codegen/src/css_kinds_src.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ pub const CSS_KINDS_SRC: KindsSrc = KindsSrc {
"CSS_DECLARATION_OR_AT_RULE_LIST",
"CSS_DECLARATION_WITH_SEMICOLON",
"CSS_DECLARATION",
"CSS_EMPTY_DECLARATION",
"CSS_IDENTIFIER",
"CSS_NUMBER",
"CSS_PARAMETER",
Expand Down

0 comments on commit cb7164e

Please sign in to comment.