Skip to content

Minor rules and declaration cleanups. #331

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

Merged
merged 3 commits into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- nightly
- beta
- stable
- 1.56.0
- 1.63.0
features:
-
- --features dummy_match_byte
Expand All @@ -35,10 +35,6 @@ jobs:
toolchain: ${{ matrix.toolchain }}
override: true

- name: Downgrade phf to a version compatible with the MSRV
run: cargo update --package phf --precise 0.10.1
if: matrix.toolchain == '1.40.0'

- name: Cargo build
run: cargo build ${{ matrix.features }}

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ keywords = ["css", "syntax", "parser"]
license = "MPL-2.0"
build = "build.rs"
edition = "2018"
rust-version = "1.56"
rust-version = "1.63"

exclude = ["src/css-parsing-tests/**", "src/big-data-url.css"]

Expand Down
65 changes: 26 additions & 39 deletions src/rules_and_declarations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,14 @@ pub trait AtRuleParser<'i> {

/// A trait to provide various parsing of qualified rules.
///
/// For example, there could be different implementations
/// for top-level qualified rules (i.e. style rules with Selectors as prelude)
/// and for qualified rules inside `@keyframes` (keyframe rules with keyframe selectors as prelude).
/// For example, there could be different implementations for top-level qualified rules (i.e. style
/// rules with Selectors as prelude) and for qualified rules inside `@keyframes` (keyframe rules
/// with keyframe selectors as prelude).
///
/// Default implementations that reject all qualified rules are provided,
/// so that `impl QualifiedRuleParser<(), ()> for ... {}` can be used
/// for example for using `RuleListParser` to parse a rule list with only at-rules
/// (such as inside `@font-feature-values`).
/// Default implementations that reject all qualified rules are provided, so that
/// `impl QualifiedRuleParser<(), ()> for ... {}` can be used for example for using
/// `RuleListParser` to parse a rule list with only at-rules (such as inside
/// `@font-feature-values`).
pub trait QualifiedRuleParser<'i> {
/// The intermediate representation of a qualified rule prelude.
type Prelude;
Expand Down Expand Up @@ -223,10 +223,7 @@ where
/// since `<DeclarationListParser as Iterator>::next` can return either.
/// It could be a custom enum.
pub fn new(input: &'a mut Parser<'i, 't>, parser: P) -> Self {
DeclarationListParser {
input: input,
parser: parser,
}
DeclarationListParser { input, parser }
}
}

Expand All @@ -249,12 +246,10 @@ where
let name = name.clone();
let result = {
let parser = &mut self.parser;
// FIXME: https://github.com/servo/rust-cssparser/issues/254
let callback = |input: &mut Parser<'i, '_>| {
parse_until_after(self.input, Delimiter::Semicolon, |input| {
input.expect_colon()?;
parser.parse_value(name, input)
};
parse_until_after(self.input, Delimiter::Semicolon, callback)
})
};
return Some(result.map_err(|e| (e, self.input.slice_from(start.position()))));
}
Expand Down Expand Up @@ -304,8 +299,8 @@ where
/// It could be a custom enum.
pub fn new_for_stylesheet(input: &'a mut Parser<'i, 't>, parser: P) -> Self {
RuleListParser {
input: input,
parser: parser,
input,
parser,
is_stylesheet: true,
any_rule_so_far: false,
}
Expand All @@ -319,8 +314,8 @@ where
/// (This is to deal with legacy workarounds for `<style>` HTML element parsing.)
pub fn new_for_nested_rule(input: &'a mut Parser<'i, 't>, parser: P) -> Self {
RuleListParser {
input: input,
parser: parser,
input,
parser,
is_stylesheet: false,
any_rule_so_far: false,
}
Expand Down Expand Up @@ -439,34 +434,28 @@ where
P: AtRuleParser<'i, Error = E>,
{
let delimiters = Delimiter::Semicolon | Delimiter::CurlyBracketBlock;
// FIXME: https://github.com/servo/rust-cssparser/issues/254
let callback = |input: &mut Parser<'i, '_>| parser.parse_prelude(name, input);
let result = parse_until_before(input, delimiters, callback);
let result = parse_until_before(input, delimiters, |input| parser.parse_prelude(name, input));
match result {
Ok(prelude) => {
let result = match input.next() {
Ok(&Token::Semicolon) | Err(_) => {
parser.rule_without_block(prelude, start)
.map_err(|()| input.new_unexpected_token_error(Token::Semicolon))
},
Ok(&Token::Semicolon) | Err(_) => parser
.rule_without_block(prelude, start)
.map_err(|()| input.new_unexpected_token_error(Token::Semicolon)),
Ok(&Token::CurlyBracketBlock) => {
// FIXME: https://github.com/servo/rust-cssparser/issues/254
let callback =
|input: &mut Parser<'i, '_>| parser.parse_block(prelude, start, input);
parse_nested_block(input, callback)
},
parse_nested_block(input, |input| parser.parse_block(prelude, start, input))
}
Ok(_) => unreachable!(),
};
result.map_err(|e| (e, input.slice_from(start.position())))
},
}
Err(error) => {
let end_position = input.position();
match input.next() {
Ok(&Token::CurlyBracketBlock) | Ok(&Token::Semicolon) | Err(_) => {}
_ => unreachable!(),
};
Err((error, input.slice(start.position()..end_position)))
},
}
}
}

Expand All @@ -478,16 +467,14 @@ where
P: QualifiedRuleParser<'i, Error = E>,
{
let start = input.state();
// FIXME: https://github.com/servo/rust-cssparser/issues/254
let callback = |input: &mut Parser<'i, '_>| parser.parse_prelude(input);
let prelude = parse_until_before(input, Delimiter::CurlyBracketBlock, callback);
let prelude = parse_until_before(input, Delimiter::CurlyBracketBlock, |input| {
parser.parse_prelude(input)
});
match *input.next()? {
Token::CurlyBracketBlock => {
// Do this here so that we consume the `{` even if the prelude is `Err`.
let prelude = prelude?;
// FIXME: https://github.com/servo/rust-cssparser/issues/254
let callback = |input: &mut Parser<'i, '_>| parser.parse_block(prelude, &start, input);
parse_nested_block(input, callback)
parse_nested_block(input, |input| parser.parse_block(prelude, &start, input))
}
_ => unreachable!(),
}
Expand Down