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