-
-
Notifications
You must be signed in to change notification settings - Fork 501
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
3556aa7
commit 5999c74
Showing
23 changed files
with
2,953 additions
and
2,039 deletions.
There are no files selected for viewing
507 changes: 268 additions & 239 deletions
507
crates/biome_css_factory/src/generated/node_factory.rs
Large diffs are not rendered by default.
Oops, something went wrong.
562 changes: 304 additions & 258 deletions
562
crates/biome_css_factory/src/generated/syntax_factory.rs
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
use crate::parser::CssParser; | ||
use crate::syntax::parse_error::expected_string; | ||
use crate::syntax::parse_string; | ||
use biome_css_syntax::CssSyntaxKind::*; | ||
use biome_css_syntax::{CssSyntaxKind, TextRange, T}; | ||
use biome_parser::parse_recovery::ParseRecovery; | ||
use biome_parser::parsed_syntax::ParsedSyntax::Present; | ||
use biome_parser::prelude::ParsedSyntax::Absent; | ||
use biome_parser::prelude::*; | ||
use biome_rowan::SyntaxKind; | ||
|
||
#[inline] | ||
pub(crate) fn is_at_charset_rule(p: &mut CssParser) -> bool { | ||
p.at(T![charset]) | ||
} | ||
|
||
#[inline] | ||
pub(crate) fn parse_at_charset_rule(p: &mut CssParser) -> ParsedSyntax { | ||
if !is_at_charset_rule(p) { | ||
return Absent; | ||
} | ||
|
||
let m = p.start(); | ||
|
||
p.bump(T![charset]); | ||
|
||
let kind = match parse_string(p).or_recover( | ||
p, | ||
&ParseRecovery::new(CSS_BOGUS, CHARTSET_RECOVERY_SET).enable_recovery_on_line_break(), | ||
expected_string, | ||
) { | ||
Ok(encoding) if !encoding.kind(p).is_bogus() => { | ||
if eat_or_recover_close_token(p, encoding) { | ||
CSS_CHARSET_AT_RULE | ||
} else { | ||
CSS_BOGUS_AT_RULE | ||
} | ||
} | ||
_ => { | ||
p.expect(T![;]); | ||
CSS_BOGUS_AT_RULE | ||
} | ||
}; | ||
|
||
Present(m.complete(p, kind)) | ||
} | ||
|
||
const CHARTSET_RECOVERY_SET: TokenSet<CssSyntaxKind> = token_set![T![;]]; | ||
|
||
#[inline] | ||
fn eat_or_recover_close_token(p: &mut CssParser, encoding: CompletedMarker) -> bool { | ||
if p.eat(T![;]) { | ||
true | ||
} else { | ||
if let Ok(m) = ParseRecovery::new(CSS_BOGUS, CHARTSET_RECOVERY_SET) | ||
.enable_recovery_on_line_break() | ||
.recover(p) | ||
{ | ||
let diagnostic = expected_string( | ||
p, | ||
TextRange::new(encoding.range(p).start(), m.range(p).end()), | ||
); | ||
p.error(diagnostic); | ||
} | ||
|
||
p.expect(T![;]); | ||
|
||
false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
mod charset; | ||
|
||
use crate::parser::CssParser; | ||
use crate::syntax::at_rule::charset::{is_at_charset_rule, parse_at_charset_rule}; | ||
use crate::syntax::parse_error::expected_any_at_rule; | ||
use biome_css_syntax::CssSyntaxKind::*; | ||
use biome_css_syntax::T; | ||
use biome_parser::prelude::ParsedSyntax::{Absent, Present}; | ||
use biome_parser::prelude::*; | ||
|
||
#[inline] | ||
pub(crate) fn at_at_rule(p: &mut CssParser) -> bool { | ||
p.at(T![@]) | ||
} | ||
|
||
#[inline] | ||
pub(crate) fn parse_at_rule(p: &mut CssParser) -> ParsedSyntax { | ||
if !at_at_rule(p) { | ||
return Absent; | ||
} | ||
|
||
let m = p.start(); | ||
|
||
p.bump(T![@]); | ||
|
||
let kind = if parse_any_at_rule(p) | ||
.or_add_diagnostic(p, expected_any_at_rule) | ||
.is_some() | ||
{ | ||
CSS_AT_RULE | ||
} else { | ||
CSS_BOGUS_RULE | ||
}; | ||
|
||
Present(m.complete(p, kind)) | ||
} | ||
|
||
#[inline] | ||
pub(crate) fn parse_any_at_rule(p: &mut CssParser) -> ParsedSyntax { | ||
if is_at_charset_rule(p) { | ||
parse_at_charset_rule(p) | ||
} else { | ||
Absent | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
crates/biome_css_parser/tests/css_test_suite/error/at_rule/at_rule_charset_error.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
@charset dsadsa; | ||
@charset ; | ||
@charset "iso-8859-15" | ||
@charset "UTF-8" 12321321; | ||
@charset "UTF-8" 12321321 | ||
@charset | ||
|
Oops, something went wrong.