Remove dependency on libsyntax
This commit is contained in:
parent
a7a68370a7
commit
93b2bb01a9
5 changed files with 13 additions and 23 deletions
|
@ -715,9 +715,6 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fmt_macros"
|
name = "fmt_macros"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
dependencies = [
|
|
||||||
"syntax 0.0.0",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fnv"
|
name = "fnv"
|
||||||
|
|
|
@ -7,6 +7,3 @@ version = "0.0.0"
|
||||||
name = "fmt_macros"
|
name = "fmt_macros"
|
||||||
path = "lib.rs"
|
path = "lib.rs"
|
||||||
crate-type = ["dylib"]
|
crate-type = ["dylib"]
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
syntax = { path = "../libsyntax" }
|
|
||||||
|
|
|
@ -28,8 +28,6 @@ pub use self::Alignment::*;
|
||||||
pub use self::Flag::*;
|
pub use self::Flag::*;
|
||||||
pub use self::Count::*;
|
pub use self::Count::*;
|
||||||
|
|
||||||
extern crate syntax;
|
|
||||||
|
|
||||||
use std::str;
|
use std::str;
|
||||||
use std::string;
|
use std::string;
|
||||||
use std::iter;
|
use std::iter;
|
||||||
|
@ -152,8 +150,8 @@ pub struct Parser<'a> {
|
||||||
pub errors: Vec<ParseError>,
|
pub errors: Vec<ParseError>,
|
||||||
/// Current position of implicit positional argument pointer
|
/// Current position of implicit positional argument pointer
|
||||||
curarg: usize,
|
curarg: usize,
|
||||||
/// The style of the string (raw or not), used to position spans correctly
|
/// `Some(raw count)` when the string is "raw", used to position spans correctly
|
||||||
style: syntax::ast::StrStyle,
|
style: Option<usize>,
|
||||||
/// How many newlines have been seen in the string so far, to adjust the error spans
|
/// How many newlines have been seen in the string so far, to adjust the error spans
|
||||||
seen_newlines: usize,
|
seen_newlines: usize,
|
||||||
}
|
}
|
||||||
|
@ -162,10 +160,7 @@ impl<'a> Iterator for Parser<'a> {
|
||||||
type Item = Piece<'a>;
|
type Item = Piece<'a>;
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Piece<'a>> {
|
fn next(&mut self) -> Option<Piece<'a>> {
|
||||||
let raw = match self.style {
|
let raw = self.style.map(|raw| raw + self.seen_newlines).unwrap_or(0);
|
||||||
syntax::ast::StrStyle::Raw(raw) => raw as usize + self.seen_newlines,
|
|
||||||
_ => 0,
|
|
||||||
};
|
|
||||||
if let Some(&(pos, c)) = self.cur.peek() {
|
if let Some(&(pos, c)) = self.cur.peek() {
|
||||||
match c {
|
match c {
|
||||||
'{' => {
|
'{' => {
|
||||||
|
@ -208,7 +203,7 @@ impl<'a> Iterator for Parser<'a> {
|
||||||
|
|
||||||
impl<'a> Parser<'a> {
|
impl<'a> Parser<'a> {
|
||||||
/// Creates a new parser for the given format string
|
/// Creates a new parser for the given format string
|
||||||
pub fn new(s: &'a str, style: syntax::ast::StrStyle) -> Parser<'a> {
|
pub fn new(s: &'a str, style: Option<usize>) -> Parser<'a> {
|
||||||
Parser {
|
Parser {
|
||||||
input: s,
|
input: s,
|
||||||
cur: s.char_indices().peekable(),
|
cur: s.char_indices().peekable(),
|
||||||
|
@ -278,10 +273,7 @@ impl<'a> Parser<'a> {
|
||||||
/// found, an error is emitted.
|
/// found, an error is emitted.
|
||||||
fn must_consume(&mut self, c: char) {
|
fn must_consume(&mut self, c: char) {
|
||||||
self.ws();
|
self.ws();
|
||||||
let raw = match self.style {
|
let raw = self.style.unwrap_or(0);
|
||||||
syntax::ast::StrStyle::Raw(raw) => raw as usize,
|
|
||||||
_ => 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
let padding = raw + self.seen_newlines;
|
let padding = raw + self.seen_newlines;
|
||||||
if let Some(&(pos, maybe)) = self.cur.peek() {
|
if let Some(&(pos, maybe)) = self.cur.peek() {
|
||||||
|
|
|
@ -15,7 +15,7 @@ use ty::{self, TyCtxt, GenericParamDefKind};
|
||||||
use util::common::ErrorReported;
|
use util::common::ErrorReported;
|
||||||
use util::nodemap::FxHashMap;
|
use util::nodemap::FxHashMap;
|
||||||
|
|
||||||
use syntax::ast::{self, MetaItem, NestedMetaItem};
|
use syntax::ast::{MetaItem, NestedMetaItem};
|
||||||
use syntax::attr;
|
use syntax::attr;
|
||||||
use syntax_pos::Span;
|
use syntax_pos::Span;
|
||||||
use syntax_pos::symbol::LocalInternedString;
|
use syntax_pos::symbol::LocalInternedString;
|
||||||
|
@ -242,7 +242,7 @@ impl<'a, 'gcx, 'tcx> OnUnimplementedFormatString {
|
||||||
{
|
{
|
||||||
let name = tcx.item_name(trait_def_id);
|
let name = tcx.item_name(trait_def_id);
|
||||||
let generics = tcx.generics_of(trait_def_id);
|
let generics = tcx.generics_of(trait_def_id);
|
||||||
let parser = Parser::new(&self.0, ast::StrStyle::Cooked);
|
let parser = Parser::new(&self.0, None);
|
||||||
let mut result = Ok(());
|
let mut result = Ok(());
|
||||||
for token in parser {
|
for token in parser {
|
||||||
match token {
|
match token {
|
||||||
|
@ -298,7 +298,7 @@ impl<'a, 'gcx, 'tcx> OnUnimplementedFormatString {
|
||||||
Some((name, value))
|
Some((name, value))
|
||||||
}).collect::<FxHashMap<String, String>>();
|
}).collect::<FxHashMap<String, String>>();
|
||||||
|
|
||||||
let parser = Parser::new(&self.0, ast::StrStyle::Cooked);
|
let parser = Parser::new(&self.0, None);
|
||||||
parser.map(|p| {
|
parser.map(|p| {
|
||||||
match p {
|
match p {
|
||||||
Piece::String(s) => s,
|
Piece::String(s) => s,
|
||||||
|
|
|
@ -778,7 +778,11 @@ pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt,
|
||||||
};
|
};
|
||||||
|
|
||||||
let fmt_str = &*fmt.node.0.as_str();
|
let fmt_str = &*fmt.node.0.as_str();
|
||||||
let mut parser = parse::Parser::new(fmt_str, fmt.node.1);
|
let str_style = match fmt.node.1 {
|
||||||
|
ast::StrStyle::Cooked => None,
|
||||||
|
ast::StrStyle::Raw(raw) => Some(raw as usize),
|
||||||
|
};
|
||||||
|
let mut parser = parse::Parser::new(fmt_str, str_style);
|
||||||
let mut pieces = vec![];
|
let mut pieces = vec![];
|
||||||
|
|
||||||
while let Some(mut piece) = parser.next() {
|
while let Some(mut piece) = parser.next() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue