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/parse.rs | |
| 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/parse.rs')
| -rw-r--r-- | src/libstd/fmt/parse.rs | 35 |
1 files changed, 22 insertions, 13 deletions
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")])) })]); } |
