syntex_fmt_macros 0.4.0

Export of fmt_macros code generation
Documentation
b0VIM 7.4}�=U���xericktErick-Tryzelaar-MBP.local~erickt/projects/rust/rust-syntex/syntex_fmt_macros/src/lib.rsutf-8
3210#"! UtpRhhl�R<	���\*ad���]Z��R.-�
o
X
W
?
&
��R��������|kj�
�
�
j
U
	
�	�	�	�	�	k	Q	-	
	����}[?���s_:��x)�����n&������\:%����ve1��xh1��    FlagSignMinus,    /// A `-` will be used to denote negative numbers. This is the default.    FlagSignPlus,    /// A `+` will be used to denote positive numbers.pub enum Flag {#[derive(Copy, Clone, PartialEq)]/// flags is defined by the formatters themselves./// Various flags which can be applied to format strings. The meaning of these}    AlignUnknown,    /// The value will take on a default alignment.    AlignCenter,    /// The value will be aligned in the center.    AlignRight,    /// The value will be aligned to the right.    AlignLeft,    /// The value will be aligned to the left.pub enum Alignment {#[derive(Copy, Clone, PartialEq)]/// Enum of alignments which are supported.}    ArgumentNamed(&'a str),    /// The argument has a name.    ArgumentIs(usize),    /// The argument is located at a specific index.    ArgumentNext,    /// The argument will be in the next position. This is the default.pub enum Position<'a> {#[derive(Copy, Clone, PartialEq)]/// Enum describing where an argument for a format can be located.}    pub ty: &'a str    /// it is required to be one word.    /// this argument, this can be empty or any number of characters, although    /// The descriptor string representing the name of the format desired for    pub width: Count<'a>,    /// The string width requested for the resulting format    pub precision: Count<'a>,    /// The integer precision to use    pub flags: u32,    /// Packed version of various flags provided    pub align: Alignment,    /// Optionally specified alignment    pub fill: Option<char>,    /// Optionally specified character to fill alignment withpub struct FormatSpec<'a> {#[derive(Copy, Clone, PartialEq)]/// Specification for the formatting of an argument in the format string.}    pub format: FormatSpec<'a>,    /// How to format the argument    pub position: Position<'a>,    /// Where to find this argumentpub struct Argument<'a> {#[derive(Copy, Clone, PartialEq)]/// Representation of an argument specification.}    NextArgument(Argument<'a>),    /// specified inside) for emission.    /// This describes that formatting should process the next argument (as    String(&'a str),    /// A literal string which should directly be emittedpub enum Piece<'a> {#[derive(Copy, Clone, PartialEq)]/// to emit. These are emitted as a stream by the `Parser` class./// A piece is a portion of the format string which represents the next partuse std::string;use std::str;pub use self::Count::*;pub use self::Flag::*;pub use self::Alignment::*;pub use self::Position::*;pub use seextern crate unicode_xid;       html_playground_url = "http://play.rust-lang.org/")]       html_root_url = "http://doc.rust-lang.org/nightly/",       html_favicon_url = "http://www.rust-lang.org/favicon.ico",#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",#![crate_type = "dylib"]#![crate_type = "rlib"]//! generated instead.//! Parsing does not happen at runtime: structures of `std::fmt::rt` are//! These structures are used when parsing format strings for the compiler.//!//! Macro support for format strings// except according to those terms.// option. This file may not be copied, modified, or distributed// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or//// http://rust-lang.org/COPYRIGHT.// file at the top-level directory of this distribution and at// Copyright 2013 The Rust Project Developers. See the COPYRIGHTado�\���t[L>	����iA�
�
�
�
�
l
P
+

�����V2����dK<.�
�
�
�
t
Z
-

�	�	�	�	�	�	u	Q	0		���mUF8����1�������8����nI0!���}    }        }), String(" efg")]);            },                ty: "a",                width: CountImplied,                precision: CountImplied,                flags: 0,                align: AlignUnknown,                fill: None,            format: FormatSpec {            position: ArgumentIs(3),        same("abcd {3:a} efg", &[String("abcd "), NextArgument(Argument {    fn format_mixture() {    #[test]    }        })]);            },                ty: "",                width: CountImplied,                precision: CountImplied,                flags: (1 << FlagSignPlus as u32) | (1 << FlagAlternate as u32),                align: AlignUnknown,                fill: None,            format: FormatSpec {            position: ArgumentNext,        same("{:+#}", &[NextArgument(Argument {        })]);            },                ty: "",                width: CountImplied,                precision: CountImplied,                flags: (1 << FlagSignMinus as u32),                align: AlignUnknown,                fill: None,            format: FormatSpec {            position: ArgumentNext,        same("{:-}", &[NextArgument(Argument {    fn format_flags() {    #[test]    }        })]);            },                ty: "s",                width: CountIsName("a"),                precision: CountIsName("b"),                flags: 0,                align: AlignUnknown,                fill: None,            format: FormatSpec {            position: ArgumentNext,        same("{:a$.b$s}", &[NextArgument(Argument {        })]);            },                ty: "s",                width: CountImplied,                precision: CountIsParam(10),                flags: 0,                align: AlignUnknown,                fill: None,            format: FormatSpec {            position: ArgumentNext,        same("{:.10$s}", &[NextArgument(Argument {        })]);            },                ty: "s",                width: CountImplied,                precision: CountIsNextParam,                flags: 0,                align: AlignUnknown,                fill: None,            format: FormatSpec {            position: ArgumentNext,        same("{:.*s}", &[NextArgument(Argument {        })]);            },                ty: "s",                width: CountIsParam(10),                precision: CountIs(10),                flags: 0,                align: AlignUnknown,                fill: None,            format: FormatSpec {            position: ArgumentNext,        same("{:10$.10s}", &[NextArgument(Argument {        })]);            },                ty: "s",                width: CountIs(10),                precision: CountImplied,                flags: 0,                align: AlignUnknown,ad5�R�������raDC���}C.�
�
�
�
�
f
D
*

�����V4���}L8�
�
�
Q

�	�	�	�	�	_	G	�����dba5�����O>
����sQA
���    FlagSignMinus,    /// A `-` will be used to denote negative numbers. This is the default.    FlagSignPlus,    /// A `+` will be used to denote positive numbers.pub enum Flag {#[derive(Copy, Clone, PartialEq)]/// flags is defined by the formatters themselves./// Various flags which can be applied to format strings. The meaning of these}    AlignUnknown,    /// The value will take on a default alignment.    AlignCenter,    /// The value will be aligned in the center.    AlignRight,    /// The value will be aligned to the right.    AlignLeft,    /// The value will be aligned to the left.pub enum Alignment {#[derive(Copy, Clone, PartialEq)]/// Enum of alignments which are supported.}    ArgumentNamed(&'a str),    /// The argument has a name.    ArgumentIs(usize),    /// The argument is located at a specific index.    ArgumentNext,    /// The argument will be in the next position. This is the default.pub enum Position<'a> {#[derive(Copy, Clone, PartialEq)]/// Enum describing where an argument for a format can be located.}    pub ty: &'a str    /// it is required to be one word.    /// this argument, this can be empty or any number of characters, although    /// The descriptor string representing the name of the format desired for    pub width: Count<'a>,    /// The string width requested for the resulting format    pub precision: Count<'a>,    /// The integer precision to use    pub flags: u32,    /// Packed version of various flags provided    pub align: Alignment,    /// Optionally specified alignment    pub fill: Option<char>,    /// Optionally specified character to fill alignment withpub struct FormatSpec<'a> {#[derive(Copy, Clone, PartialEq)]/// Specification for the formatting of an argument in the format string.}    pub format: FormatSpec<'a>,    /// How to format the argument    pub position: Position<'a>,    /// Where to find this argumentpub struct Argument<'a> {#[derive(Copy, Clone, PartialEq)]/// Representation of an argument specification.}    NextArgument(Argument<'a>),    /// specified inside) for emission.    /// This describes that formatting should process the next argument (as    String(&'a str),    /// A literal string which should directly be emittedpub enum Piece<'a> {#[derive(Copy, Clone, PartialEq)]/// to emit. These are emitted as a stream by the `Parser` class./// A piece is a portion of the format string which represents the next partuse unicode_xid::UnicodeXID;use std::string;use std::str;pub use self::Count::*;pub use self::Flag::*;pub use self::Alignment::*;pub use self::Position::*;pub use self::Piece::*;ad�h�dQ����e*�
�
�
p
V

���m[YX
���^�
�
�
�
n
l
k
H
-
,
�	�	�	�	l	5		����uS2���m[M�������fU?����R(����2���a@+�����sI6��                self.cur.next();            Some((_, maybe)) if c == maybe => {        match self.cur.clone().next() {        self.ws();    fn must_consume(&mut self, c: char) {    /// found, an error is emitted.    /// Forces consumption of the specified character. If the character is not    }        }            Some(..) | None => false,            }                true                self.cur.next();            Some((_, maybe)) if c == maybe => {        match self.cur.clone().next() {    fn consume(&mut self, c: char) -> bool {    /// returned, otherwise the character is consumed and true is returned.    /// the current position, then the current iterator isn't moved and false is    /// Optionally consumes the specified character. If the character is not at    }        self.errors.push(msg.to_string());    fn err(&mut self, msg: &str) {    /// might as well start using it now.    /// String, but I think it does when this eventually uses conditions so it    /// Notifies of an error. The message doesn't actually need to be of type    }        }            errors: vec!(),            cur: s.char_indices(),            input: s,        Parser {    pub fn new(s: &'a str) -> Parser<'a> {    /// Creates a new parser for the given format stringimpl<'a> Parser<'a> {}    }        }            None => None            Some((pos, _)) => { Some(String(self.string(pos))) }            }                }                    None                    self.err("unmatched `}` found");                } else {                    Some(String(self.string(pos + 1)))                if self.consume('}') {                self.cur.next();            Some((pos, '}')) => {            }                }                    ret                    self.must_consume('}');                    let ret = Some(NextArgument(self.argument()));                } else {                    Some(String(self.string(pos + 1)))                if self.consume('{') {                self.cur.next();            Some((pos, '{')) => {        match self.cur.clone().next() {    fn next(&mut self) -> Option<Piece<'a>> {    type Item = Piece<'a>;impl<'a> Iterator for Parser<'a> {}    pub errors: Vec<string::String>,    /// Error messages accumulated during parsing    cur: str::CharIndices<'a>,    input: &'a str,pub struct Parser<'a> {/// necessary there's probably lots of room for improvement performance-wise./// This is a recursive-descent parser for the sake of simplicity, and if////// being output./// modelled as an iterator over `Piece` structures to form a stream of tokens/// The parser structure for interpreting the input format string. This is}    CountImplied,    /// The count is implied and cannot be explicitly specified.    CountIsNextParam,    /// The count is specified by the next parameter.    CountIsParam(usize),    /// The count is specified by the argument at the given index.    CountIsName(&'a str),    /// The count is specified by the argument with the given name.    CountIs(usize),    /// The count is specified explicitly.pub enum Count<'a> {#[derive(Copy, Clone, PartialEq)]/// can reference either an argument or a literal integer./// A count is used for the precision and width parameters of an integer, and}    FlagSignAwareZeroPad,    /// and the sign (`+` or `-`) will precede them.    /// For numbers, this means that the number will be padded with zeroes,    FlagAlternate,    /// this means that the number will be prefixed with the supplied string.    /// An alternate form will be used for the value. In the case of numbers,ad7l���_Q;������\J3$�
�
�
r
h
b
a

���H���lR-�
�
�
�
�
�
l
R
%

�	�	�	�	�	l	!	����f+��������;���zd?������b*���tJ8*	����f@���H>"        if self.consume('#') {        // Alternate marker        }            spec.flags |= 1 << (FlagSignMinus as u32);        } else if self.consume('-') {            spec.flags |= 1 << (FlagSignPlus as u32);        if self.consume('+') {        // Sign flags        }            spec.align = AlignCenter;        } else if self.consume('^') {            spec.align = AlignRight;        } else if self.consume('>') {            spec.align = AlignLeft;        if self.consume('<') {        // Alignment        }            None => {}            }                }                    Some(..) | None => {}                    }                        self.cur.next();                        spec.fill = Some(c);                    Some((_, '>')) | Some((_, '<')) | Some((_, '^')) => {                match self.cur.clone().skip(1).next() {            Some((_, c)) => {        match self.cur.clone().next() {        // fill character        if !self.consume(':') { return spec }        };            ty: &self.input[..0],            width: CountImplied,            precision: CountImplied,            flags: 0,            align: AlignUnknown,            fill: None,        let mut spec = FormatSpec {    fn format(&mut self) -> FormatSpec<'a> {    /// relevant information in the FormatSpec struct.    /// Parses a format specifier at the current position, returning all of the    }        }            }                }                    _ => ArgumentNext                    }                        ArgumentNamed(self.word())                    Some((_, c)) if c.is_alphabetic() => {                match self.cur.clone().next() {            None => {            Some(i) => { ArgumentIs(i) }        match self.integer() {    fn position(&mut self) -> Position<'a> {    /// integer index of an argument, a named argument, or a blank string.    /// Parses a positional argument for a format. This could either be an    }        }            format: self.format(),            position: self.position(),        Argument {    fn argument(&mut self) -> Argument<'a> {    /// the format string    /// Parses an Argument structure, or what's contained within braces inside    }        }            }                }                    return &self.input[start..self.input.len()];                    self.cur.next();                None => {                Some(..) => { self.cur.next(); }                }                    return &self.input[start..pos];                Some((pos, '}')) | Some((pos, '{')) => {            match self.cur.clone().next() {            // we may not consume the character, so clone the iterator        loop {    fn string(&mut self, start: usize) -> &'a str {    /// format string. This is everything outside of the braces.    /// Parses all of a string which is to be considered a "raw literal" in a    }        }            }                Some(..) | None => { return }                Some((_, c)) if c.is_whitespace() => { self.cur.next(); }            match self.cur.clone().next() {        loop {    fn ws(&mut self) {    /// character    /// Consumes all whitespace characters until the first non-whitespace    }        }            }                                  c));                self.err(&format!("expected `{:?}` but string was terminated",            None => {            }                                  other));                self.err(&format!("expected `{:?}`, found `{:?}`", c,            Some((_, other)) => {            }ad�R���}^
�m3�
�
�
i
[
Q
9


���~OA7�����{ut&�
�
�
�
m
F
"
	
�	�	�	�	�	d	2		���_E/��������0���z;�����a���vh^>87��}dE6
���_5���                        None => { break }                        }                            self.cur.next();                            found = true;                            cur = cur * 10 + i as usize;                        Some(i) => {                    match c.to_digit(10) {                Some((_, c)) => {            match self.cur.clone().next() {        loop {        let mut found = false;        let mut cur = 0;    fn integer(&mut self) -> Option<usize> {    /// with overflow at all, it's just accumulating digits.    /// Optionally parses an integer at the current position. This doesn't deal    }        &self.input[start..end]        }            }                None => { end = self.input.len(); break }                Some((pos, _)) => { end =                 Some((_, c)) if UnicodeXID:c.is_xid_continue() =>                  Some((_, c)) if UnicodeXID::is_xid_continue(c) => {            match self.cur.clone().next() {        loop {        let mut end;        };            Some(..) | None => { return &self.input[..0]; }            }                pos                self.cur.next();            Some((pos, c)) if UnicodeXID::is_xid_start(c) => {        let start = match self.cur.clone().next() {    fn word(&mut self) -> &'a str {    /// characters.    /// be an alphabetic character followed by any number of alphanumeric    /// Parses a word starting at the current position. A word is considered to    }        }            }                }                    }                        CountImplied                        self.cur = tmp;                    _ => {                    }                        }                            CountImplied                            self.cur = tmp;                        } else {                            CountIsName(word)                        if self.consume('$') {                    word if !word.is_empty() => {                match self.word() {                let tmp = self.cur.clone();            None => {            }                }                    CountIs(i)                } else {                    CountIsParam(i)                if self.consume('$') {            Some(i) => {        match self.integer() {    fn count(&mut self) -> Count<'a> {    /// width.    /// for 'CountIsNextParam' because that is only used in precision, not    /// Parses a Count parameter at the current position. This does not check    }        return spec;        }            spec.ty = self.word();        } else {            spec.ty = "?";        if self.consume('?') {        // Finally the actual format specifier        }            }                spec.precision = self.count();            } else {                spec.precision = CountIsNextParam;            if self.consume('*') {        if self.consume('.') {        }            spec.width = self.count();        if !havewidth {        }            }                spec.flags |= 1 << (FlagSignAwareZeroPad as u32);            } else {                havewidth = true;                spec.width = CountIsParam(0);            if self.consume('$') {            // no '0' flag and '0$' as the width instead.            // and no count, but this is better if we instead interpret this as            // '0' flag and then an ill-formatted format string with just a '$'            // small ambiguity with '0$' as a format string. In theory this is a        if self.consume('0') {        let mut havewidth = false;        // Width and precision        }            spec.flags |= 1 << (FlagAlternate as u32);ad<�������m\C9310#��ga`6�
�
�
�
q
g
a
`
F
"

������g3����vJ�
�
�
�
�
g
C
$



�	�	�	w	i	c	W	/		������U0����fM>0*���oL2	����~Y8����ufX#�����W2�����yX<;                fill: None,            format: FormatSpec {            position: ArgumentNext,        same("{:10s}", &[NextArgument(Argument {    fn format_counts() {    #[test]    }        })]);            },                ty: "abcd",                width: CountImplied,                precision: CountImplied,                flags: 0,                align: AlignLeft,                fill: Some('*'),            format: FormatSpec {            position: ArgumentIs(3),        same("{3:*<abcd}", &[NextArgument(Argument {        })]);            },                ty: "",                width: CountImplied,                precision: CountImplied,                flags: 0,                align: AlignLeft,                fill: Some('0'),            format: FormatSpec {            position: ArgumentIs(3),        same("{3:0<}", &[NextArgument(Argument {        })]);            },                ty: "",                width: CountImplied,                precision: CountImplied,                flags: 0,                align: AlignRight,                fill: None,            format: FormatSpec {            position: ArgumentIs(3),        same("{3:>}", &[NextArgument(Argument {    fn format_align_fill() {    #[test]    }        })]);            },                ty: "a",                width: CountImplied,                precision: CountImplied,                flags: 0,                align: AlignUnknown,                fill: None,            format: FormatSpec {            position: ArgumentIs(3),        same("{3:a}", &[NextArgument(Argument {    fn format_type() {    #[test]    }        })]);            format: fmtdflt(),            position: ArgumentIs(3),        same("{3:}", &[NextArgument(Argument {    fn format_position_nothing_else() {    #[test]    }        })]);            format: fmtdflt(),            position: ArgumentIs(3),        same("{3}", &[NextArgument(Argument {    fn format_position() {    #[test]    }        })]);            format: fmtdflt(),            position: ArgumentNext,        same("{}", &[NextArgument(Argument {    fn format_nothing() {    #[test]    #[test] fn invalid06() { musterr("{:>>>}") }    #[test] fn invalid05() { musterr("{:|}") }    #[test] fn invalid04() { musterr("{3a}") }    #[test] fn invalid02() { musterr("}") }    #[test] fn invalid01() { musterr("{") }    }        same("\\}}", &[String("\\"), String("}")]);        same("}}", &[String("}")]);        same("a}}", &[String("a"), String("}")]);        same("a}}b", &[String("a"), String("}b")]);        same("a{{b", &[String("a"), String("{b")]);        same("asdf", &[String("asdf")]);    fn simple() {    #[test]    }        assert!(!p.errors.is_empty());        p.next();        let mut p = Parser::new(s);    fn musterr(s: &str) {    }        }            ty: "",            width: CountImplied,            precision: CountImplied,            flags: 0,            align: AlignUnknown,            fill: None,        return FormatSpec {    fn fmtdflt() -> FormatSpec<'static> {    }        assert!(parser.collect::<Vec<Piece<'static>>>() == p);        let parser = Parser::new(fmt);    fn same(fmt: &'static str, p: &[Piece<'static>]) {    use super::*;mod tests {#[cfg(test)]}    }        }            return None;        } else {            return Some(cur);        if found {        }            }                None => { break }                }                    }ad*����XJ@ ��_F'�
�
�
z
A

���                        None => { break }                        }                            self.cur.next();                            found = true;                            cur = cur * 10 + i as usize;                        Some(i) => {                    match c.to_digit(10) {                Some((_, c)) => {            match self.cur.clone().next() {        loop {        let mut found = false;        let mut cur = 0;    fn integer(&mut self) -> Option<usize> {    /// with overflow at all, it's just accumulating digits.    /// Optionally parses an integer at the current position. This doesn't deal    }        &self.input[start..end]        }            }                None => { end = self.input.len(); break }                Some((pos, _)) => { end = pos; break }                }                    self.cur.next();