syntex_syntax 0.9.0

Export of libsyntax for code generation
1
2
3
4
5
6
7
8
9
10
11
12
b0VIM 7.4��U\X~ericktErick-Tryzelaar-MBP.local~erickt/projects/rust/rust-syntex/syntex_syntax/src/ext/format.rs
3210#"! Utpn��������bo��������Y���������X*��������R���������U���������Z)U�ad�n��]Z��R.-�
�
�
�
�
�
�
~
l
J
8
,
+


�����������kM����wv(�
�
�
4
�	�	�	q	Q	P		����iF�����lU@>=����mi#�y>�����t,����P7-��{S+���                }                    i                    panictry!(p.bump());                token::Ident(i, _) => {            let ident = match p.token {            named = true;        if named || (p.token.is_ident() && p.look_ahead(1, |t| *t == token::Eq)) {        if p.token == token::Eof { break } // accept trailing commas        }            return None;            ecx.span_err(sp, "expected token: `,`");        if !panictry!(p.eat(&token::Comma)) {    while p.token != token::Eof {    let mut named = false;    let fmtstr = p.parse_expr();    }        return None;        ecx.span_err(sp, "requires at least a format string argument");    if p.token == token::Eof {    let mut p = ecx.new_parser_from_tts(tts);    let mut order = Vec::new();    let mut names = HashMap::<String, P<ast::Expr>>::new();    let mut args = Vec::new();                         HashMap<String, P<ast::Expr>>)> {              -> Option<(P<ast::Expr>, Vec<P<ast::Expr>>, Vec<String>,fn parse_args(ecx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])///           named arguments))///     Some((fmtstr, unnamed arguments, ordering of named arguments,////// If parsing succeeds, the return value is:////// expressions./// if there's a parse error so we can continue parsing other format!/// Parses the arguments from the given list of tokens, returning None}    next_arg: usize,    nest_level: usize,    /// Updated as arguments are consumed or methods are entered    name_positions: HashMap<String, usize>,    all_pieces_simple: bool,    /// Stays `true` if all formatting parameters are default (as in "{}{}").    str_pieces: Vec<P<ast::Expr>>,    /// Collection of string literals    pieces: Vec<P<ast::Expr>>,    /// Collection of the compiled `rt::Argument` structures    literal: String,    /// The latest consecutive literal strings, or empty if there weren't any.    name_ordering: Vec<String>,    name_types: HashMap<String, ArgumentType>,    names: HashMap<String, P<ast::Expr>>,    /// were declared in.    /// found to be sure that we can translate them in the same order that they    /// Note that we keep a side-array of the ordering of the named arguments    /// Parsed named expressions and the types that we've found for them so far.    arg_types: Vec<Option<ArgumentType>>,    args: Vec<P<ast::Expr>>,    /// them.    /// Parsed argument expressions and the types that we've found so far for    fmtsp: Span,    /// The span of the format string literal.    macsp: Span,    /// use this span to pass the stability checker.    /// The macro's call site. References to unstable formatting internals must    ecx: &'a mut ExtCtxt<'b>,struct Context<'a, 'b:'a> {}    Named(String),    Exact(usize),enum Position {}    Unsigned    Known(String),enum ArgumentType {#[derive(PartialEq)]use std::collections::HashMap;use ptr::P;use parse::token;use parse::token::special_idents;use fold::Folder;use fmt_macros as parse;use ext::build::AstBuilder;use ext::base;use ext::base::*;use codemap::{Span, respan};use ast;use self::Position::*;use self::ArgumentType::*;// 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 2012 The Rust Project Developers. See the COPYRIGHTad�]U�����M��W
�
�
q
"
��]B0����v_J*�
�
�
�
�
k
B
�	�	�	�	�	i	h	]	?	"	���n3�����f\V3��|vV+��j%���ysr_]\}    cx.into_expr()    }        }            cx.ecx.span_err(e.span, "named argument never used");        if !cx.name_types.contains_key(name) {    for (name, e) in &cx.names {    }        }            cx.ecx.span_err(cx.args[i].span, "argument never used");        if ty.is_none() {    for (i, ty) in cx.arg_types.iter().enumerate() {    // Make sure that all arguments were used and all arguments have types.    }        cx.str_pieces.push(s);        let s = cx.trans_literal_string();    if !cx.literal.is_empty() {    }        return DummyResult::raw_expr(sp);                                          parser.errors.remove(0)));        cx.ecx.span_err(cx.fmtsp, &format!("invalid format string: {}",    if !parser.errors.is_empty() {    }        }            None => break            }                }                    None => {}                    }                        cx.pieces.push(piece);                        cx.str_pieces.push(s);                        let s = cx.trans_literal_string();                    Some(piece) => {                match cx.trans_piece(&piece) {                cx.verify_piece(&piece);                if !parser.errors.is_empty() { break }            Some(piece) => {        match parser.next() {    loop {    let mut parser = parse::Parser::new(&fmt);    };        None => return DummyResult::raw_expr(sp)        Some((fmt, _)) => fmt,                                   "format argument must be a string literal.") {                                   efmt,    let fmt = match expr_to_string(cx.ecx,    };        fmtsp: efmt.span,        macsp: macsp,        all_pieces_simple: true,        str_pieces: Vec::new(),        pieces: Vec::new(),        literal: String::new(),        next_arg: 0,        nest_level: 0,        name_ordering: name_ordering,        name_types: HashMap::new(),        name_positions: HashMap::new(),        names: names,        arg_types: arg_types,        args: args,        ecx: ecx,    let mut cx = Context {    let efmt = ecx.expander().fold_expr(efmt);    // a macro. (e.g. println!("{}"), which uses concat!($fmt, "\n")).    // is essential for locating a bug when the format literal is generated in    // Expand the format literal so that efmt.span will have a backtrace. This    let macsp = ecx.call_site();    let arg_types: Vec<_> = (0..args.len()).map(|_| None).collect();                                    -> P<ast::Expr> {                                    names: HashMap<String, P<ast::Expr>>)                                    name_ordering: Vec<String>,                                    args: Vec<P<ast::Expr>>,                                    efmt: P<ast::Expr>,pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt, sp: Span,/// and construct the appropriate formatting expression./// Take the various parts of `format_args!(efmt, args..., name=names...)`}    }        None => DummyResult::expr(sp)