From 008a91c3cea7da09baf092c9be8b77c4d385141a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Fri, 21 Feb 2025 11:30:43 +0100 Subject: [PATCH 1/5] Fix clippy lints (#401) --- src/from_bytes.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/from_bytes.rs b/src/from_bytes.rs index 78a56d3e..7d9d2c76 100644 --- a/src/from_bytes.rs +++ b/src/from_bytes.rs @@ -24,9 +24,9 @@ pub trait EncodingSupport { /// /// * `css_bytes`: A byte string. /// * `protocol_encoding`: The encoding label, if any, defined by HTTP or equivalent protocol. -/// (e.g. via the `charset` parameter of the `Content-Type` header.) +/// (e.g. via the `charset` parameter of the `Content-Type` header.) /// * `environment_encoding`: An optional `Encoding` object for the [environment encoding] -/// (https://drafts.csswg.org/css-syntax/#environment-encoding), if any. +/// (https://drafts.csswg.org/css-syntax/#environment-encoding), if any. /// /// Returns the encoding to use. pub fn stylesheet_encoding( From 5e477ab8195f64ed9b22ab1cf7b08685347f3879 Mon Sep 17 00:00:00 2001 From: Nicolas Chevobbe Date: Fri, 21 Feb 2025 11:30:02 +0100 Subject: [PATCH 2/5] Add declaration_start parameter to DeclarationParser parse_value (#400) --- src/rules_and_declarations.rs | 6 ++++-- src/tests.rs | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/rules_and_declarations.rs b/src/rules_and_declarations.rs index 188e354e..bdaef077 100644 --- a/src/rules_and_declarations.rs +++ b/src/rules_and_declarations.rs @@ -49,6 +49,7 @@ pub trait DeclarationParser<'i> { &mut self, name: CowRcStr<'i>, input: &mut Parser<'i, 't>, + _declaration_start: &ParserState, ) -> Result> { Err(input.new_error(BasicParseErrorKind::UnexpectedToken(Token::Ident(name)))) } @@ -279,7 +280,7 @@ where error_behavior, |input| { input.expect_colon()?; - parser.parse_value(name, input) + parser.parse_value(name, input, &start) }, ) }; @@ -408,12 +409,13 @@ pub fn parse_one_declaration<'i, 't, P, E>( where P: DeclarationParser<'i, Error = E>, { + let start = input.state(); let start_position = input.position(); input .parse_entirely(|input| { let name = input.expect_ident()?.clone(); input.expect_colon()?; - parser.parse_value(name, input) + parser.parse_value(name, input, &start) }) .map_err(|e| (e, input.slice_from(start_position))) } diff --git a/src/tests.rs b/src/tests.rs index ec0fc517..3c122f0d 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -849,6 +849,7 @@ impl<'i> DeclarationParser<'i> for JsonParser { &mut self, name: CowRcStr<'i>, input: &mut Parser<'i, 't>, + _declaration_start: &ParserState, ) -> Result> { let mut value = vec![]; let mut important = false; From 0d800216303aa6586b1469cb948859fb1dbd6a2f Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Fri, 21 Feb 2025 23:31:11 +1300 Subject: [PATCH 3/5] Implement `MallocSizeOf` for cssparser types (#399) * Implement MallocSizeOf for cssparser types * Fix clippy lints Signed-off-by: Nico Burns --------- Signed-off-by: Nico Burns --- .github/workflows/main.yml | 1 + Cargo.toml | 3 ++- src/serializer.rs | 3 +++ src/tokenizer.rs | 6 ++++++ 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b08ddef7..a7be6aec 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -22,6 +22,7 @@ jobs: features: - - --features dummy_match_byte + - --features malloc_size_of include: - toolchain: nightly features: --features bench diff --git a/Cargo.toml b/Cargo.toml index f783f19f..f4e980fd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cssparser" -version = "0.34.0" +version = "0.34.1" authors = ["Simon Sapin "] description = "Rust implementation of CSS Syntax Level 3" @@ -25,6 +25,7 @@ dtoa-short = "0.3" itoa = "1.0" phf = { version = "0.11.2", features = ["macros"] } serde = { version = "1.0", features = ["derive"], optional = true } +malloc_size_of = { version = "0.1", default-features = false, optional = true } smallvec = "1.0" [profile.profiling] diff --git a/src/serializer.rs b/src/serializer.rs index 5df73954..6696a622 100644 --- a/src/serializer.rs +++ b/src/serializer.rs @@ -466,6 +466,9 @@ pub enum TokenSerializationType { Other, } +#[cfg(feature = "malloc_size_of")] +malloc_size_of::malloc_size_of_is_0!(TokenSerializationType); + impl TokenSerializationType { /// Return a value that represents the absence of a token, e.g. before the start of the input. #[deprecated( diff --git a/src/tokenizer.rs b/src/tokenizer.rs index 2e86c66a..892d10ae 100644 --- a/src/tokenizer.rs +++ b/src/tokenizer.rs @@ -533,6 +533,9 @@ impl<'a> Tokenizer<'a> { #[derive(PartialEq, Eq, PartialOrd, Ord, Debug, Clone, Copy)] pub struct SourcePosition(pub(crate) usize); +#[cfg(feature = "malloc_size_of")] +malloc_size_of::malloc_size_of_is_0!(SourcePosition); + impl SourcePosition { /// Returns the current byte index in the original input. #[inline] @@ -552,6 +555,9 @@ pub struct SourceLocation { pub column: u32, } +#[cfg(feature = "malloc_size_of")] +malloc_size_of::malloc_size_of_is_0!(SourceLocation); + fn next_token<'a>(tokenizer: &mut Tokenizer<'a>) -> Result, ()> { if tokenizer.is_eof() { return Err(()); From 958a3f098acb92ddacdce18a7ef2c4a87ac3326f Mon Sep 17 00:00:00 2001 From: Nicolas Chevobbe Date: Fri, 21 Feb 2025 14:28:55 +0100 Subject: [PATCH 4/5] Derive Default for SourceLocation (#402) --- src/tokenizer.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tokenizer.rs b/src/tokenizer.rs index 892d10ae..1c85e10a 100644 --- a/src/tokenizer.rs +++ b/src/tokenizer.rs @@ -545,7 +545,7 @@ impl SourcePosition { } /// The line and column number for a given position within the input. -#[derive(PartialEq, Eq, Debug, Clone, Copy)] +#[derive(PartialEq, Eq, Debug, Clone, Copy, Default)] pub struct SourceLocation { /// The line number, starting at 0 for the first line. pub line: u32, From 3dd4f63639925438d9932dafc0d81395847f9be4 Mon Sep 17 00:00:00 2001 From: Nico Burns Date: Fri, 21 Mar 2025 07:11:19 +1300 Subject: [PATCH 5/5] Bump version 0.35.0 (#404) Signed-off-by: Nico Burns --- Cargo.toml | 2 +- color/Cargo.toml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f4e980fd..6604f20e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cssparser" -version = "0.34.1" +version = "0.35.0" authors = ["Simon Sapin "] description = "Rust implementation of CSS Syntax Level 3" diff --git a/color/Cargo.toml b/color/Cargo.toml index d5cde913..5dd6aac7 100644 --- a/color/Cargo.toml +++ b/color/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cssparser-color" -version = "0.2.0" +version = "0.3.0" authors = ["Emilio Cobos Álvarez "] description = "Color implementation based on cssparser" documentation = "https://docs.rs/cssparser-color/" @@ -12,7 +12,7 @@ edition = "2021" path = "lib.rs" [dependencies] -cssparser = { path = "..", version = "0.34" } +cssparser = { path = "..", version = "0.35" } serde = { version = "1.0", features = ["derive"], optional = true } [features]