Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

feat(rome_css_parser): CSS parser #4682 #4724

Merged
merged 1 commit into from
Jul 26, 2023
Merged

Conversation

denbezrukov
Copy link
Contributor

@denbezrukov denbezrukov commented Jul 24, 2023

Summary

Initial implementation of CssTokenSource and CssParser for the CSS parser.
Added CssParserOptions which has an allow_single_line_comments option. This allows the writing of single line comments in CSS syntax.

Test Plan

cargo test

@netlify
Copy link

netlify bot commented Jul 24, 2023

Deploy Preview for docs-rometools canceled.

Name Link
🔨 Latest commit 190ed1c
🔍 Latest deploy log https://app.netlify.com/sites/docs-rometools/deploys/64bedeb1dfda2a0008514efd

@github-actions github-actions bot added A-Core Area: core L-CSS Language: CSS A-Parser Area: parser A-Tooling Area: our own build, development, and release tooling L-JSON Language: JSON labels Jul 24, 2023
@github-actions
Copy link

Parser conformance results on ubuntu-latest

js/262

Test result main count This PR count Difference
Total 48863 48863 0
Passed 47810 47810 0
Failed 1053 1053 0
Panics 0 0 0
Coverage 97.84% 97.84% 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 6212 6212 0
Passed 1764 1764 0
Failed 4448 4448 0
Panics 0 0 0
Coverage 28.40% 28.40% 0.00%

ts/babel

Test result main count This PR count Difference
Total 639 639 0
Passed 573 573 0
Failed 66 66 0
Panics 0 0 0
Coverage 89.67% 89.67% 0.00%

ts/microsoft

Test result main count This PR count Difference
Total 17224 17224 0
Passed 13121 13121 0
Failed 4103 4103 0
Panics 0 0 0
Coverage 76.18% 76.18% 0.00%

@denbezrukov denbezrukov changed the title feat(rome_js_parser): CSS lexer #4682 feat(rome_js_parser): CSS parser #4682 Jul 25, 2023
use rome_css_syntax::CssSyntaxKind::*;
use rome_parser::Parser;

pub(crate) fn parse_root(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.

It's the entry point for syntax parsing.

Undefined,
}

pub fn run(test_case: &str, _snapshot_name: &str, test_directory: &str, outcome_str: &str) {
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's a copy of the JSON test spec.

I'd like to write tests the same way we use in the JS parser. But I'm unsure what is the best way. I think that we can combine both approaches.

Copy link
Contributor

Choose a reason for hiding this comment

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

Personally, I don't like the test suite of the JS parser:

  • we have to run two commands in order to run the tests
  • we always need to tweak the test generator parser to accommodate new things - like parser options, which is becoming quite difficult

The best way, personally, would be just to write a file to test and then check the snapshot with insta; of course the testing suite will do much more, but that's the gist of it.

@@ -68,26 +66,4 @@ impl<'source> Parser for JsonParser<'source> {
fn source_mut(&mut self) -> &mut Self::Source {
&mut self.source
}

/// Try to eat a specific token kind, if the kind is not there then adds an error to the events stack.
fn expect(&mut self, kind: Self::Kind) -> bool {
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 seems that we don't need any special behavior for comments here. When allow_comments is true, it implies that COMMENT and MULTILINE_COMMENT kinds are considered as trivia.

Ok(trivia_kind) => {
if trivia_kind.is_newline() {
trailing = false;
self.preceding_line_break = true;
}
self.trivia
.push(Trivia::new(trivia_kind, token.range(), trailing));
}
}

@denbezrukov denbezrukov changed the title feat(rome_js_parser): CSS parser #4682 feat(rome_css_parser): CSS parser #4682 Jul 26, 2023
@denbezrukov denbezrukov merged commit a3a13d7 into main Jul 26, 2023
18 checks passed
@denbezrukov denbezrukov deleted the feat/css-parser-crate branch July 26, 2023 20:32
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-Core Area: core A-Parser Area: parser A-Tooling Area: our own build, development, and release tooling L-CSS Language: CSS L-JSON Language: JSON
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants