From 80487ddcadda819e709beb9b996b12d322aa11a6 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 6 May 2014 09:52:53 -0700 Subject: 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] --- src/libsyntax/ext/format.rs | 22 ++++++---------------- src/libsyntax/lib.rs | 1 + 2 files changed, 7 insertions(+), 16 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/ext/format.rs b/src/libsyntax/ext/format.rs index fc3136996ae..7b465a2dc35 100644 --- a/src/libsyntax/ext/format.rs +++ b/src/libsyntax/ext/format.rs @@ -18,7 +18,7 @@ use parse::token::InternedString; use parse::token; use rsparse = parse; -use std::fmt::parse; +use parse = fmt_macros; use collections::{HashMap, HashSet}; #[deriving(Eq)] @@ -232,7 +232,7 @@ impl<'a, 'b> Context<'a, 'b> { parse::Keyword(name) => { self.ecx.span_err(self.fmtsp, format!("duplicate selector \ - `{:?}`", name)); + `{}`", name)); } parse::Literal(idx) => { self.ecx.span_err(self.fmtsp, @@ -375,21 +375,11 @@ impl<'a, 'b> Context<'a, 'b> { return vec!(unnamed, allow_dead_code); } - fn parsepath(&self, s: &str) -> Vec { - vec!(self.ecx.ident_of("std"), self.ecx.ident_of("fmt"), - self.ecx.ident_of("parse"), self.ecx.ident_of(s)) - } - fn rtpath(&self, s: &str) -> Vec { vec!(self.ecx.ident_of("std"), self.ecx.ident_of("fmt"), self.ecx.ident_of("rt"), self.ecx.ident_of(s)) } - fn ctpath(&self, s: &str) -> Vec { - vec!(self.ecx.ident_of("std"), self.ecx.ident_of("fmt"), - self.ecx.ident_of("parse"), self.ecx.ident_of(s)) - } - fn none(&self) -> @ast::Expr { let none = self.ecx.path_global(self.fmtsp, vec!( self.ecx.ident_of("std"), @@ -475,7 +465,7 @@ impl<'a, 'b> Context<'a, 'b> { }).collect(); let (lr, selarg) = match arm.selector { parse::Keyword(t) => { - let p = self.ctpath(format!("{:?}", t)); + let p = self.rtpath(t.to_str()); let p = self.ecx.path_global(sp, p); (self.rtpath("Keyword"), self.ecx.expr_path(p)) } @@ -564,13 +554,13 @@ impl<'a, 'b> Context<'a, 'b> { let fill = self.ecx.expr_lit(sp, ast::LitChar(fill)); let align = match arg.format.align { parse::AlignLeft => { - self.ecx.path_global(sp, self.parsepath("AlignLeft")) + self.ecx.path_global(sp, self.rtpath("AlignLeft")) } parse::AlignRight => { - self.ecx.path_global(sp, self.parsepath("AlignRight")) + self.ecx.path_global(sp, self.rtpath("AlignRight")) } parse::AlignUnknown => { - self.ecx.path_global(sp, self.parsepath("AlignUnknown")) + self.ecx.path_global(sp, self.rtpath("AlignUnknown")) } }; let align = self.ecx.expr_path(align); diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index 012bc50ecab..5e1d988df5c 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -35,6 +35,7 @@ extern crate term; extern crate collections; #[phase(syntax, link)] extern crate log; +extern crate fmt_macros; pub mod util { pub mod interner; -- cgit 1.4.1-3-g733a5