Auto merge of #20304 - nupurbaghel:counterbound, r=emilio

CounterBound::Integer made to store an Integer

<!-- Please describe your changes on the following line: -->

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #20197

<!-- Either: -->
- [x] These changes do not require tests because they involve datatype change of already existing enum CounterBound

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/20304)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2018-03-19 04:25:56 -04:00 committed by GitHub
commit 6d06d1bbcc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 17 deletions

View file

@ -22,6 +22,7 @@ use str::CssStringWriter;
use style_traits::{Comma, CssWriter, OneOrMoreSeparated, ParseError};
use style_traits::{StyleParseErrorKind, ToCss};
use values::CustomIdent;
use values::specified::Integer;
/// Parse a counter style name reference.
///
@ -450,21 +451,19 @@ pub struct Ranges(pub Vec<Range<CounterBound>>);
#[derive(Clone, Copy, Debug, ToCss)]
pub enum CounterBound {
/// An integer bound.
///
/// FIXME(https://github.com/servo/servo/issues/20197)
Integer(i32),
Integer(Integer),
/// The infinite bound.
Infinite,
}
impl Parse for Ranges {
fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
if input.try(|input| input.expect_ident_matching("auto")).is_ok() {
Ok(Ranges(Vec::new()))
} else {
input.parse_comma_separated(|input| {
let opt_start = parse_bound(input)?;
let opt_end = parse_bound(input)?;
let opt_start = parse_bound(context, input)?;
let opt_end = parse_bound(context, input)?;
if let (CounterBound::Integer(start), CounterBound::Integer(end)) = (opt_start, opt_end) {
if start > end {
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
@ -477,18 +476,13 @@ impl Parse for Ranges {
}
fn parse_bound<'i, 't>(
input: &mut Parser<'i, 't>,
context: &ParserContext, input: &mut Parser<'i, 't>,
) -> Result<CounterBound, ParseError<'i>> {
let location = input.current_source_location();
match *input.next()? {
Token::Number { int_value: Some(v), .. } => {
Ok(CounterBound::Integer(v))
}
Token::Ident(ref ident) if ident.eq_ignore_ascii_case("infinite") => {
Ok(CounterBound::Infinite)
}
ref t => Err(location.new_unexpected_token_error(t.clone())),
if let Ok(integer) = input.try(|input| Integer::parse(context, input)) {
return Ok(CounterBound::Integer(integer));
}
input.expect_ident_matching("infinite")?;
Ok(CounterBound::Infinite)
}
impl ToCss for Ranges {

View file

@ -326,7 +326,7 @@ impl ToNsCssValue for counter_style::Ranges {
nscssvalue.set_pair_list(self.0.into_iter().map(|range| {
fn set_bound(bound: CounterBound, nscssvalue: &mut nsCSSValue) {
if let CounterBound::Integer(finite) = bound {
nscssvalue.set_integer(finite)
nscssvalue.set_integer(finite.value())
} else {
nscssvalue.set_enum(structs::NS_STYLE_COUNTER_RANGE_INFINITE as i32)
}