Skip to content
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): CSS Parser pseudo element selector #268 #883

Merged
merged 3 commits into from
Nov 28, 2023

Conversation

denbezrukov
Copy link
Contributor

@denbezrukov denbezrukov commented Nov 25, 2023

Summary

  • Improved error recovery and diagnostics for pseudo-class selectors. See snapshots.
  • Added test cases to ensure correct handling of a closing token within selector context, particularly for space combinators, e.g., :host-context(h1) .div {}.
  • Introduced eat_or_recover_selector_function_close_token, which attempts to consume a ) token; if unsuccessful, it recovers by consuming all tokens as bogus.
  • Introduced recover_selector_function_parameter to handle invalid parameters by consuming all tokens until ).
  • Noted code duplication across various selector kinds in checking identifiers and closing tokens. Suggest extracting common logic into a separate PR for better maintainability.

Test Plan

cargo test

- better error recovery and diagnostic for pseudo class selector
@github-actions github-actions bot added A-Parser Area: parser A-Tooling Area: internal tools L-CSS Language: CSS labels Nov 25, 2023
use biome_parser::prelude::ParsedSyntax;
use biome_parser::prelude::ParsedSyntax::{Absent, Present};
use biome_parser::{token_set, CompletedMarker, Parser, ParserProgress, TokenSet};

const SELECTOR_RECOVERY_SET: TokenSet<CssSyntaxKind> = RULE_RECOVERY_SET.union(token_set![T![,]]);
const SELECTOR_FUNCTION_RECOVERY_SET: TokenSet<CssSyntaxKind> = token_set![T![')'], T!['{']];

#[inline]
fn parse_selector_function_close_token(p: &mut CssParser) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed a way how we recover if we don't find a close token.
I think that it's okey to consume all tokens until we find a )or a }.
See snapshots for examples.

Copy link
Contributor

Parser conformance results on

js/262

Test result main count This PR count Difference
Total 49701 49701 0
Passed 48721 48721 0
Failed 980 980 0
Panics 0 0 0
Coverage 98.03% 98.03% 0.00%

jsx/babel

Test result main count This PR count Difference
Total 40 40 0
Passed 37 37 0
Failed 3 3 0
Panics 0 0 0
Coverage 92.50% 92.50% 0.00%

symbols/microsoft

Test result main count This PR count Difference
Total 6322 6322 0
Passed 2036 2036 0
Failed 4286 4286 0
Panics 0 0 0
Coverage 32.20% 32.20% 0.00%

ts/babel

Test result main count This PR count Difference
Total 662 662 0
Passed 592 592 0
Failed 70 70 0
Panics 0 0 0
Coverage 89.43% 89.43% 0.00%

ts/microsoft

Test result main count This PR count Difference
Total 17646 17646 0
Passed 13453 13453 0
Failed 4191 4191 0
Panics 2 2 0
Coverage 76.24% 76.24% 0.00%

- better error recovery and diagnostic for pseudo class selector
Present(m.complete(p, CSS_PSEUDO_CLASS_SELECTOR))
let kind = match parse_pseudo_class(p).or_add_diagnostic(p, expected_any_pseudo_class) {
Some(_) => CSS_PSEUDO_CLASS_SELECTOR,
None => CSS_BOGUS_SUB_SELECTOR,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It covers a case when we have only a double column token: :

@denbezrukov denbezrukov merged commit 04e6319 into main Nov 28, 2023
16 checks passed
@denbezrukov denbezrukov deleted the pseudo-class-error-recovery branch November 28, 2023 20:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Parser Area: parser A-Tooling Area: internal tools L-CSS Language: CSS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants