Skip to content

Commit

Permalink
feat(css_parser): Add css bench parser (#497)
Browse files Browse the repository at this point in the history
  • Loading branch information
denbezrukov authored Oct 7, 2023
1 parent 9264c09 commit 608e0fa
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions xtask/bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ version = "0.0.0"
[dependencies]
biome_analyze = { workspace = true }
biome_console = { workspace = true }
biome_css_parser = { workspace = true }
biome_css_syntax = { workspace = true }
biome_diagnostics = { workspace = true }
biome_formatter = { workspace = true }
biome_js_analyze = { workspace = true }
Expand Down
16 changes: 16 additions & 0 deletions xtask/bench/src/language.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::test_case::TestCase;
use biome_analyze::{AnalysisFilter, AnalyzerOptions, ControlFlow, Never, RuleCategories};
use biome_css_parser::CssParserOptions;
use biome_formatter::{FormatResult, Formatted, PrintResult, Printed};
use biome_js_analyze::analyze;
use biome_js_formatter::context::{JsFormatContext, JsFormatOptions};
Expand All @@ -15,6 +16,7 @@ use criterion::black_box;
pub enum Parse<'a> {
JavaScript(JsFileSource, &'a str),
Json(&'a str),
Css(&'a str),
}

impl<'a> Parse<'a> {
Expand All @@ -23,6 +25,7 @@ impl<'a> Parse<'a> {
Ok(source_type) => Some(Parse::JavaScript(source_type, case.code())),
Err(_) => match case.extension() {
"json" => Some(Parse::Json(case.code())),
"css" => Some(Parse::Css(case.code())),
_ => None,
},
}
Expand All @@ -38,6 +41,10 @@ impl<'a> Parse<'a> {
code,
JsonParserOptions::default(),
)),
Parse::Css(code) => Parsed::Css(biome_css_parser::parse_css(
code,
CssParserOptions::default().with_allow_single_line_comments(),
)),
}
}

Expand All @@ -57,13 +64,19 @@ impl<'a> Parse<'a> {
cache,
JsonParserOptions::default(),
)),
Parse::Css(code) => Parsed::Css(biome_css_parser::parse_css_with_cache(
code,
cache,
CssParserOptions::default().with_allow_single_line_comments(),
)),
}
}
}

pub enum Parsed {
JavaScript(biome_js_parser::Parse<AnyJsRoot>, JsFileSource),
Json(biome_json_parser::JsonParse),
Css(biome_css_parser::CssParse),
}

impl Parsed {
Expand All @@ -73,20 +86,23 @@ impl Parsed {
Some(FormatNode::JavaScript(parse.syntax(), *source_type))
}
Parsed::Json(parse) => Some(FormatNode::Json(parse.syntax())),
Parsed::Css(_) => None,
}
}

pub fn analyze(&self) -> Option<Analyze> {
match self {
Parsed::JavaScript(parse, _) => Some(Analyze::JavaScript(parse.tree())),
Parsed::Json(_) => None,
Parsed::Css(_) => None,
}
}

pub fn into_diagnostics(self) -> Vec<ParseDiagnostic> {
match self {
Parsed::JavaScript(parse, _) => parse.into_diagnostics(),
Parsed::Json(parse) => parse.into_diagnostics(),
Parsed::Css(parse) => parse.into_diagnostics(),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions xtask/bench/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ pub fn run(args: RunArgs) {
all_suites.insert("js", include_str!("libs-js.txt"));
all_suites.insert("ts", include_str!("libs-ts.txt"));
all_suites.insert("json", include_str!("libs-json.txt"));
all_suites.insert("css", include_str!("libs-css.txt"));
}

let mut libs = vec![];
Expand Down
8 changes: 8 additions & 0 deletions xtask/bench/src/libs-css.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css
https://cdn.jsdelivr.net/npm/[email protected]/dist/full.css
https://cdn.jsdelivr.net/npm/[email protected]/build/pure-min.css
https://raw.githubusercontent.com/Dogfalo/materialize/v1-dev/dist/css/materialize.css
https://raw.githubusercontent.com/jgthms/bulma/master/css/bulma.css
https://raw.githubusercontent.com/foundation/foundation-sites/develop/dist/css/foundation.css
https://raw.githubusercontent.com/Semantic-Org/Semantic-UI/master/dist/semantic.css
https://raw.githubusercontent.com/tachyons-css/tachyons/main/css/tachyons.css

0 comments on commit 608e0fa

Please sign in to comment.