Skip to content

Make rules and declarations parsers take &mut self #109

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 1 commit into from
Sep 7, 2016
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]

name = "cssparser"
version = "0.6.0"
version = "0.7.0"
authors = [ "Simon Sapin <simon.sapin@exyr.org>" ]

description = "Rust implementation of CSS Syntax Level 3"
Expand Down
12 changes: 6 additions & 6 deletions src/rules_and_declarations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub trait DeclarationParser {
/// If `!important` can be used in a given context,
/// `input.try(parse_important).is_ok()` should be used at the end
/// of the implementation of this method and the result should be part of the return value.
fn parse_value(&self, name: &str, input: &mut Parser) -> Result<Self::Declaration, ()>;
fn parse_value(&mut self, name: &str, input: &mut Parser) -> Result<Self::Declaration, ()>;
}


Expand Down Expand Up @@ -106,7 +106,7 @@ pub trait AtRuleParser {
/// The given `input` is a "delimited" parser
/// that ends wherever the prelude should end.
/// (Before the next semicolon, the next `{`, or the end of the current block.)
fn parse_prelude(&self, name: &str, input: &mut Parser)
fn parse_prelude(&mut self, name: &str, input: &mut Parser)
-> Result<AtRuleType<Self::Prelude, Self::AtRule>, ()> {
let _ = name;
let _ = input;
Expand All @@ -121,7 +121,7 @@ pub trait AtRuleParser {
///
/// This is only called when `parse_prelude` returned `WithBlock` or `OptionalBlock`,
/// and a block was indeed found following the prelude.
fn parse_block(&self, prelude: Self::Prelude, input: &mut Parser)
fn parse_block(&mut self, prelude: Self::Prelude, input: &mut Parser)
-> Result<Self::AtRule, ()> {
let _ = prelude;
let _ = input;
Expand All @@ -132,7 +132,7 @@ pub trait AtRuleParser {
///
/// Convert the prelude into the finished representation of the at-rule
/// as returned by `RuleListParser::next` or `DeclarationListParser::next`.
fn rule_without_block(&self, prelude: Self::Prelude) -> Self::AtRule {
fn rule_without_block(&mut self, prelude: Self::Prelude) -> Self::AtRule {
let _ = prelude;
panic!("The `AtRuleParser::rule_without_block` method must be overriden \
if `AtRuleParser::parse_prelude` ever returns `AtRuleType::OptionalBlock`.")
Expand Down Expand Up @@ -166,7 +166,7 @@ pub trait QualifiedRuleParser {
///
/// The given `input` is a "delimited" parser
/// that ends where the prelude should end (before the next `{`).
fn parse_prelude(&self, input: &mut Parser) -> Result<Self::Prelude, ()> {
fn parse_prelude(&mut self, input: &mut Parser) -> Result<Self::Prelude, ()> {
let _ = input;
Err(())
}
Expand All @@ -176,7 +176,7 @@ pub trait QualifiedRuleParser {
/// Return the finished representation of the qualified rule
/// as returned by `RuleListParser::next`,
/// or `Err(())` to ignore the entire at-rule as invalid.
fn parse_block(&self, prelude: Self::Prelude, input: &mut Parser)
fn parse_block(&mut self, prelude: Self::Prelude, input: &mut Parser)
-> Result<Self::QualifiedRule, ()> {
let _ = prelude;
let _ = input;
Expand Down
12 changes: 6 additions & 6 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ struct JsonParser;
impl DeclarationParser for JsonParser {
type Declaration = Json;

fn parse_value(&self, name: &str, input: &mut Parser) -> Result<Json, ()> {
fn parse_value(&mut self, name: &str, input: &mut Parser) -> Result<Json, ()> {
let mut value = vec![];
let mut important = false;
loop {
Expand Down Expand Up @@ -622,7 +622,7 @@ impl AtRuleParser for JsonParser {
type Prelude = Vec<Json>;
type AtRule = Json;

fn parse_prelude(&self, name: &str, input: &mut Parser)
fn parse_prelude(&mut self, name: &str, input: &mut Parser)
-> Result<AtRuleType<Vec<Json>, Json>, ()> {
Ok(AtRuleType::OptionalBlock(vec![
"at-rule".to_json(),
Expand All @@ -631,12 +631,12 @@ impl AtRuleParser for JsonParser {
]))
}

fn parse_block(&self, mut prelude: Vec<Json>, input: &mut Parser) -> Result<Json, ()> {
fn parse_block(&mut self, mut prelude: Vec<Json>, input: &mut Parser) -> Result<Json, ()> {
prelude.push(Json::Array(component_values_to_json(input)));
Ok(Json::Array(prelude))
}

fn rule_without_block(&self, mut prelude: Vec<Json>) -> Json {
fn rule_without_block(&mut self, mut prelude: Vec<Json>) -> Json {
prelude.push(Json::Null);
Json::Array(prelude)
}
Expand All @@ -646,11 +646,11 @@ impl QualifiedRuleParser for JsonParser {
type Prelude = Vec<Json>;
type QualifiedRule = Json;

fn parse_prelude(&self, input: &mut Parser) -> Result<Vec<Json>, ()> {
fn parse_prelude(&mut self, input: &mut Parser) -> Result<Vec<Json>, ()> {
Ok(component_values_to_json(input))
}

fn parse_block(&self, prelude: Vec<Json>, input: &mut Parser) -> Result<Json, ()> {
fn parse_block(&mut self, prelude: Vec<Json>, input: &mut Parser) -> Result<Json, ()> {
Ok(JArray![
"qualified rule",
prelude,
Expand Down