diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2014-05-06 09:52:53 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-05-08 09:35:59 -0700 |
| commit | 80487ddcadda819e709beb9b996b12d322aa11a6 (patch) | |
| tree | 6fa2208f015edd2e0007b5bba723405b2f5d7172 /src/libstd/fmt/rt.rs | |
| parent | 87115fd001440652291c509a77bda74fa511dab0 (diff) | |
| download | rust-80487ddcadda819e709beb9b996b12d322aa11a6.tar.gz rust-80487ddcadda819e709beb9b996b12d322aa11a6.zip | |
std: Extract format string parsing out of libstd
This code does not belong in libstd, and rather belongs in a dedicated crate. In the future, the syntax::ext::format module should move to the fmt_macros crate (hence the name of the crate), but for now the fmt_macros crate will only contain the format string parser. The entire fmt_macros crate is marked #[experimental] because it is not meant for general consumption, only the format!() interface is officially supported, not the internals. This is a breaking change for anyone using the internals of std::fmt::parse. Some of the flags have moved to std::fmt::rt, while the actual parsing support has all moved to the fmt_macros library. [breaking-change]
Diffstat (limited to 'src/libstd/fmt/rt.rs')
| -rw-r--r-- | src/libstd/fmt/rt.rs | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/src/libstd/fmt/rt.rs b/src/libstd/fmt/rt.rs index 01c2c06c3fb..33e86a4485b 100644 --- a/src/libstd/fmt/rt.rs +++ b/src/libstd/fmt/rt.rs @@ -17,9 +17,17 @@ #![allow(missing_doc)] #![doc(hidden)] -use fmt::parse; use option::Option; +#[cfg(stage0)] +pub use fmt::parse::{Alignment, AlignLeft, AlignRight, AlignUnknown}; +#[cfg(stage0)] +pub use fmt::parse::{PluralKeyword, Zero, One, Two, Few, Many}; +#[cfg(stage0)] +pub use fmt::parse::{Flag, FlagSignPlus, FlagSignMinus, FlagSignAwareZeroPad}; +#[cfg(stage0)] +pub use fmt::parse::{FlagAlternate}; + pub enum Piece<'a> { String(&'a str), // FIXME(#8259): this shouldn't require the unit-value here @@ -35,12 +43,20 @@ pub struct Argument<'a> { pub struct FormatSpec { pub fill: char, - pub align: parse::Alignment, + pub align: Alignment, pub flags: uint, pub precision: Count, pub width: Count, } +#[cfg(not(stage0))] +#[deriving(Eq)] +pub enum Alignment { + AlignLeft, + AlignRight, + AlignUnknown, +} + pub enum Count { CountIs(uint), CountIsParam(uint), CountIsNextParam, CountImplied, } @@ -49,16 +65,32 @@ pub enum Position { ArgumentNext, ArgumentIs(uint) } +#[cfg(not(stage0))] +pub enum Flag { + FlagSignPlus, + FlagSignMinus, + FlagAlternate, + FlagSignAwareZeroPad, +} + pub enum Method<'a> { Plural(Option<uint>, &'a [PluralArm<'a>], &'a [Piece<'a>]), Select(&'a [SelectArm<'a>], &'a [Piece<'a>]), } pub enum PluralSelector { - Keyword(parse::PluralKeyword), + Keyword(PluralKeyword), Literal(uint), } +pub enum PluralKeyword { + Zero, + One, + Two, + Few, + Many, +} + pub struct PluralArm<'a> { pub selector: PluralSelector, pub result: &'a [Piece<'a>], |
