Skip to content
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

Custom properties, take 2 #7555

Merged
merged 10 commits into from Sep 17, 2015

Fix !important in custom properties.

  • Loading branch information
SimonSapin committed Sep 17, 2015
commit c7622bf22fa5d9623a5818d6f63c6e6369b23b60

Some generated files are not rendered by default. Learn more.

@@ -23,7 +23,7 @@ git = "https://github.com/servo/rust-selectors"
features = ["unstable"]

[dependencies.cssparser]
version = "0.3.6"
version = "0.3.8"
features = [ "serde-serialization" ]

[dependencies.url]
@@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use cssparser::{Parser, Token, SourcePosition};
use cssparser::{Parser, Token, SourcePosition, Delimiter};
use properties::DeclaredValue;
use std::collections::{HashMap, HashSet};
use std::sync::Arc;
@@ -37,8 +37,6 @@ pub struct BorrowedValue<'a> {
pub fn parse(input: &mut Parser) -> Result<Value, ()> {
let start = input.position();
let mut references = Some(HashSet::new());
// FIXME: don’t consume a top-level `!` as that would prevent parsing `!important`.
// Maybe using Parser::parse_until_before?
try!(parse_declaration_value(input, &mut references));
Ok(Value {
value: input.slice_from(start).to_owned(),
@@ -49,42 +47,13 @@ pub fn parse(input: &mut Parser) -> Result<Value, ()> {
/// https://drafts.csswg.org/css-syntax-3/#typedef-declaration-value
pub fn parse_declaration_value(input: &mut Parser, references: &mut Option<HashSet<Name>>)
-> Result<(), ()> {
if input.is_exhausted() {
// Need at least one token
return Err(())
}
while let Ok(token) = input.next() {
match token {
Token::BadUrl |
Token::BadString |
Token::CloseParenthesis |
Token::CloseSquareBracket |
Token::CloseCurlyBracket |

Token::Semicolon |
Token::Delim('!') => {
return Err(())
}

Token::Function(ref name) if name == "var" => {
try!(input.parse_nested_block(|input| {
parse_var_function(input, references)
}));
}

Token::Function(_) |
Token::ParenthesisBlock |
Token::CurlyBracketBlock |
Token::SquareBracketBlock => {
try!(input.parse_nested_block(|input| {
parse_declaration_value_block(input, references)
}));
}

_ => {}
input.parse_until_before(Delimiter::Bang | Delimiter::Semicolon, |input| {
if input.is_exhausted() {
// Need at least one token
return Err(())
}
}
Ok(())
parse_declaration_value_block(input, references)
})
}

/// Like parse_declaration_value,
@@ -312,11 +281,11 @@ fn substitute_block<F>(input: &mut Parser,
-> Result<(), ()>
where F: FnMut(&Name, &mut String) -> Result<(), ()> {
loop {
let input_slice = input.slice_from(*start);
let before_this_token = input.position();
let token = if let Ok(token) = input.next() { token } else { break };
match token {
Token::Function(ref name) if name == "var" => {
substituted.push_str(input_slice);
substituted.push_str(input.slice(*start..before_this_token));
try!(input.parse_nested_block(|input| {
// parse_var_function() ensures neither .unwrap() will fail.
let name = input.expect_ident().unwrap();

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.