diff options
| author | bors <bors@rust-lang.org> | 2014-01-03 12:16:48 -0800 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-01-03 12:16:48 -0800 |
| commit | 08321f1c49d75e60a2c56320a3f1483e7bf79a91 (patch) | |
| tree | fd429cf0c3cd63379bef08c36fd9acf0f3e0d82a /src/libstd/fmt | |
| parent | 11ce6b709ace233e473eddb26e3e23c2c4c16cdd (diff) | |
| parent | 4bea679dbe3ba98049ac700d84ad48271753ce40 (diff) | |
| download | rust-08321f1c49d75e60a2c56320a3f1483e7bf79a91.tar.gz rust-08321f1c49d75e60a2c56320a3f1483e7bf79a91.zip | |
auto merge of #11149 : alexcrichton/rust/remove-either, r=brson
Had to change some stuff in typeck to bootstrap (getting methods in fmt off of Either), but other than that not so painful. Closes #9157
Diffstat (limited to 'src/libstd/fmt')
| -rw-r--r-- | src/libstd/fmt/mod.rs | 14 | ||||
| -rw-r--r-- | src/libstd/fmt/parse.rs | 35 | ||||
| -rw-r--r-- | src/libstd/fmt/rt.rs | 8 |
3 files changed, 35 insertions, 22 deletions
diff --git a/src/libstd/fmt/mod.rs b/src/libstd/fmt/mod.rs index cd9c0f5d2b7..53eaf17c7f8 100644 --- a/src/libstd/fmt/mod.rs +++ b/src/libstd/fmt/mod.rs @@ -757,7 +757,7 @@ impl<'a> Formatter<'a> { // offsetted value for s in selectors.iter() { match s.selector { - Right(val) if value == val => { + rt::Literal(val) if value == val => { return self.runplural(value, s.result); } _ => {} @@ -769,17 +769,17 @@ impl<'a> Formatter<'a> { let value = value - match offset { Some(i) => i, None => 0 }; for s in selectors.iter() { let run = match s.selector { - Left(parse::Zero) => value == 0, - Left(parse::One) => value == 1, - Left(parse::Two) => value == 2, + rt::Keyword(parse::Zero) => value == 0, + rt::Keyword(parse::One) => value == 1, + rt::Keyword(parse::Two) => value == 2, // XXX: Few/Many should have a user-specified boundary // One possible option would be in the function // pointer of the 'arg: Argument' struct. - Left(parse::Few) => value < 8, - Left(parse::Many) => value >= 8, + rt::Keyword(parse::Few) => value < 8, + rt::Keyword(parse::Many) => value >= 8, - Right(..) => false + rt::Literal(..) => false }; if run { return self.runplural(value, s.result); diff --git a/src/libstd/fmt/parse.rs b/src/libstd/fmt/parse.rs index e9f7af181a7..0ac1aac2380 100644 --- a/src/libstd/fmt/parse.rs +++ b/src/libstd/fmt/parse.rs @@ -122,12 +122,21 @@ pub enum Method<'a> { Select(~[SelectArm<'a>], ~[Piece<'a>]), } +/// A selector for what pluralization a plural method should take +#[deriving(Eq, IterBytes)] +pub enum PluralSelector { + /// One of the plural keywords should be used + Keyword(PluralKeyword), + /// A literal pluralization should be used + Literal(uint), +} + /// Structure representing one "arm" of the `plural` function. #[deriving(Eq)] pub struct PluralArm<'a> { /// A selector can either be specified by a keyword or with an integer /// literal. - selector: Either<PluralKeyword, uint>, + selector: PluralSelector, /// Array of pieces which are the format of this arm result: ~[Piece<'a>], } @@ -504,29 +513,29 @@ impl<'a> Parser<'a> { let mut isother = false; let selector = if self.wsconsume('=') { match self.integer() { - Some(i) => Right(i), + Some(i) => Literal(i), None => { self.err("plural `=` selectors must be followed by an \ integer"); - Right(0) + Literal(0) } } } else { let word = self.word(); match word { - "other" => { isother = true; Left(Zero) } - "zero" => Left(Zero), - "one" => Left(One), - "two" => Left(Two), - "few" => Left(Few), - "many" => Left(Many), + "other" => { isother = true; Keyword(Zero) } + "zero" => Keyword(Zero), + "one" => Keyword(One), + "two" => Keyword(Two), + "few" => Keyword(Few), + "many" => Keyword(Many), word => { self.err(format!("unexpected plural selector `{}`", word)); if word == "" { break } else { - Left(Zero) + Keyword(Zero) } } } @@ -955,9 +964,9 @@ mod tests { position: ArgumentNext, format: fmtdflt(), method: Some(~Plural(Some(1), ~[ - PluralArm{ selector: Right(2), result: ~[String("2")] }, - PluralArm{ selector: Right(3), result: ~[String("3")] }, - PluralArm{ selector: Left(Many), result: ~[String("yes")] } + PluralArm{ selector: Literal(2), result: ~[String("2")] }, + PluralArm{ selector: Literal(3), result: ~[String("3")] }, + PluralArm{ selector: Keyword(Many), result: ~[String("yes")] } ], ~[String("haha")])) })]); } diff --git a/src/libstd/fmt/rt.rs b/src/libstd/fmt/rt.rs index c139a2f5734..89895f30585 100644 --- a/src/libstd/fmt/rt.rs +++ b/src/libstd/fmt/rt.rs @@ -17,7 +17,6 @@ #[allow(missing_doc)]; #[doc(hidden)]; -use either::Either; use fmt::parse; use option::Option; @@ -55,8 +54,13 @@ pub enum Method<'a> { Select(&'a [SelectArm<'a>], &'a [Piece<'a>]), } +pub enum PluralSelector { + Keyword(parse::PluralKeyword), + Literal(uint), +} + pub struct PluralArm<'a> { - selector: Either<parse::PluralKeyword, uint>, + selector: PluralSelector, result: &'a [Piece<'a>], } |
