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

Use the ParserContext along with the Parser #14373

Merged
merged 2 commits into from Nov 27, 2016
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -8,7 +8,7 @@

use Atom;
use cssparser::{Delimiter, Parser, SourcePosition, Token, TokenSerializationType};
use parser::Parse;
use parser::{Parse, ParserContext};
use properties::DeclaredValue;
use std::ascii::AsciiExt;
use std::borrow::Cow;
@@ -113,7 +113,7 @@ impl ComputedValue {
}

impl Parse for SpecifiedValue {
fn parse(input: &mut Parser) -> Result<Self, ()> {
fn parse(_context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
let mut references = Some(HashSet::new());
let (first, css, last) = try!(parse_self_contained_declaration_value(input, &mut references));
Ok(SpecifiedValue {
@@ -69,8 +69,6 @@ pub fn log_css_error(input: &mut Parser, position: SourcePosition, message: &str

// XXXManishearth Replace all specified value parse impls with impls of this
// trait. This will make it easy to write more generic values in the future.
// There may need to be two traits -- one for parsing with context, and one
// for parsing without
pub trait Parse {
fn parse(input: &mut Parser) -> Result<Self, ()> where Self: Sized;
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> where Self: Sized;
}
@@ -16,7 +16,7 @@
</%call>
</%def>

<%def name="predefined_type(name, type, initial_value, parse_method='parse', needs_context=False, **kwargs)">
<%def name="predefined_type(name, type, initial_value, parse_method='parse', needs_context=True, **kwargs)">
<%call expr="longhand(name, predefined_type=type, **kwargs)">
#[allow(unused_imports)]
use app_units::Au;
@@ -283,7 +283,7 @@
% if not property.derived_from:
pub fn parse_declared(context: &ParserContext, input: &mut Parser)
-> Result<DeclaredValue<SpecifiedValue>, ()> {
match input.try(CSSWideKeyword::parse) {
match input.try(|i| CSSWideKeyword::parse(context, i)) {
Ok(CSSWideKeyword::InheritKeyword) => Ok(DeclaredValue::Inherit),
Ok(CSSWideKeyword::InitialKeyword) => Ok(DeclaredValue::Initial),
Ok(CSSWideKeyword::UnsetKeyword) => Ok(DeclaredValue::${
@@ -515,7 +515,7 @@
% endif
</%def>

<%def name="four_sides_shorthand(name, sub_property_pattern, parser_function)">
<%def name="four_sides_shorthand(name, sub_property_pattern, parser_function, needs_context=True)">
<%self:shorthand name="${name}" sub_properties="${
' '.join(sub_property_pattern % side
for side in ['top', 'right', 'bottom', 'left'])}">
@@ -524,8 +524,14 @@
use super::parse_four_sides;
use values::specified;

pub fn parse_value(_: &ParserContext, input: &mut Parser) -> Result<Longhands, ()> {
let (top, right, bottom, left) = try!(parse_four_sides(input, ${parser_function}));
pub fn parse_value(context: &ParserContext, input: &mut Parser) -> Result<Longhands, ()> {
let (top, right, bottom, left) =
% if needs_context:
try!(parse_four_sides(input, |i| ${parser_function}(context, i)));
% else:
try!(parse_four_sides(input, ${parser_function}));
let _unused = context;
% endif
Ok(Longhands {
% for side in ["top", "right", "bottom", "left"]:
${to_rust_ident(sub_property_pattern % side)}: Some(${side}),
@@ -120,9 +120,9 @@ ${helpers.predefined_type("background-color", "CSSColor",
}
}

pub fn parse(_context: &ParserContext, input: &mut Parser)
pub fn parse(context: &ParserContext, input: &mut Parser)
-> Result<SpecifiedValue, ()> {
Ok(try!(Position::parse(input)))
Ok(try!(Position::parse(context, input)))
}
</%helpers:vector_longhand>

@@ -302,7 +302,7 @@ ${helpers.single_keyword("background-origin",
})
}

pub fn parse(_: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue,()> {
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue,()> {
let width;
if let Ok(value) = input.try(|input| {
match input.next() {
@@ -318,7 +318,7 @@ ${helpers.single_keyword("background-origin",
}) {
return Ok(value)
} else {
width = try!(specified::LengthOrPercentageOrAuto::parse(input))
width = try!(specified::LengthOrPercentageOrAuto::parse(context, input))
}

let height;
@@ -330,7 +330,7 @@ ${helpers.single_keyword("background-origin",
}) {
height = value
} else {
height = try!(specified::LengthOrPercentageOrAuto::parse(input));
height = try!(specified::LengthOrPercentageOrAuto::parse(context, input));
}

Ok(SpecifiedValue::Explicit(ExplicitSize {
@@ -18,7 +18,8 @@
% for side in ALL_SIDES:
${helpers.predefined_type("border-%s-style" % side[0], "BorderStyle",
"specified::BorderStyle::none",
need_clone=True, animatable=False, logical = side[1])}
needs_context=False, need_clone=True,
animatable=False, logical = side[1])}
% endfor

% for side in ALL_SIDES:
@@ -32,9 +33,9 @@
pub type SpecifiedValue = BorderWidth;

#[inline]
pub fn parse(_context: &ParserContext, input: &mut Parser)
pub fn parse(context: &ParserContext, input: &mut Parser)
-> Result<SpecifiedValue, ()> {
BorderWidth::parse(input)
BorderWidth::parse(context, input)
}

pub mod computed_value {
@@ -503,12 +504,12 @@ ${helpers.single_keyword("-moz-float-edge", "content-box margin-box",
}

impl Parse for SingleSpecifiedValue {
fn parse(input: &mut Parser) -> Result<Self, ()> {
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
if input.try(|input| input.expect_ident_matching("auto")).is_ok() {
return Ok(SingleSpecifiedValue::Auto);
}

if let Ok(len) = input.try(|input| LengthOrPercentage::parse(input)) {
if let Ok(len) = input.try(|input| LengthOrPercentage::parse(context, input)) {
return Ok(SingleSpecifiedValue::LengthOrPercentage(len));
}

@@ -517,10 +518,10 @@ ${helpers.single_keyword("-moz-float-edge", "content-box margin-box",
}
}

pub fn parse(_context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
let mut values = vec![];
for _ in 0..4 {
let value = input.try(|input| SingleSpecifiedValue::parse(input));
let value = input.try(|input| SingleSpecifiedValue::parse(context, input));
match value {
Ok(val) => values.push(val),
Err(_) => break,
@@ -709,8 +710,8 @@ ${helpers.single_keyword("-moz-float-edge", "content-box margin-box",
}

impl Parse for PercentageOrNumber {
fn parse(input: &mut Parser) -> Result<Self, ()> {
if let Ok(per) = input.try(|input| Percentage::parse(input)) {
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
if let Ok(per) = input.try(|input| Percentage::parse(context, input)) {
return Ok(PercentageOrNumber::Percentage(per));
}

@@ -719,12 +720,12 @@ ${helpers.single_keyword("-moz-float-edge", "content-box margin-box",
}
}

pub fn parse(_context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
let mut fill = input.try(|input| input.expect_ident_matching("fill")).is_ok();

let mut values = vec![];
for _ in 0..4 {
let value = input.try(|input| PercentageOrNumber::parse(input));
let value = input.try(|input| PercentageOrNumber::parse(context, input));
match value {
Ok(val) => values.push(val),
Err(_) => break,
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.