mirror of
https://github.com/openharmony/third_party_rust_quote.git
synced 2026-07-19 22:03:30 -04:00
Update to published proc_macro2
This commit is contained in:
+1
-1
@@ -11,4 +11,4 @@ include = ["Cargo.toml", "src/**/*.rs", "tests/**/*.rs", "README.md", "LICENSE-A
|
||||
publish = false # this branch contains breaking changes
|
||||
|
||||
[dependencies]
|
||||
proc-macro2 = { git = 'https://github.com/alexcrichton/proc-macro2' }
|
||||
proc-macro2 = "0.1"
|
||||
|
||||
+5
-5
@@ -74,7 +74,7 @@ pub mod __rt {
|
||||
tokens.append_all(s.into_iter());
|
||||
}
|
||||
|
||||
pub fn append_kind(tokens: &mut ::Tokens, kind: TokenKind) {
|
||||
pub fn append_kind(tokens: &mut ::Tokens, kind: TokenNode) {
|
||||
tokens.append(TokenTree {
|
||||
span: Default::default(),
|
||||
kind: kind,
|
||||
@@ -229,7 +229,7 @@ macro_rules! quote_each_token {
|
||||
($tokens:ident # [ $($inner:tt)* ] $($rest:tt)*) => {
|
||||
quote_each_token!($tokens #);
|
||||
$crate::__rt::append_kind(&mut $tokens,
|
||||
$crate::__rt::TokenKind::Sequence(
|
||||
$crate::__rt::TokenNode::Group(
|
||||
$crate::__rt::Delimiter::Bracket,
|
||||
quote! { $($inner)* }.into()
|
||||
));
|
||||
@@ -243,7 +243,7 @@ macro_rules! quote_each_token {
|
||||
|
||||
($tokens:ident ( $($first:tt)* ) $($rest:tt)*) => {
|
||||
$crate::__rt::append_kind(&mut $tokens,
|
||||
$crate::__rt::TokenKind::Sequence(
|
||||
$crate::__rt::TokenNode::Group(
|
||||
$crate::__rt::Delimiter::Parenthesis,
|
||||
quote! { $($first)* }.into()
|
||||
));
|
||||
@@ -252,7 +252,7 @@ macro_rules! quote_each_token {
|
||||
|
||||
($tokens:ident [ $($first:tt)* ] $($rest:tt)*) => {
|
||||
$crate::__rt::append_kind(&mut $tokens,
|
||||
$crate::__rt::TokenKind::Sequence(
|
||||
$crate::__rt::TokenNode::Group(
|
||||
$crate::__rt::Delimiter::Bracket,
|
||||
quote! { $($first)* }.into()
|
||||
));
|
||||
@@ -261,7 +261,7 @@ macro_rules! quote_each_token {
|
||||
|
||||
($tokens:ident { $($first:tt)* } $($rest:tt)*) => {
|
||||
$crate::__rt::append_kind(&mut $tokens,
|
||||
$crate::__rt::TokenKind::Sequence(
|
||||
$crate::__rt::TokenNode::Group(
|
||||
$crate::__rt::Delimiter::Brace,
|
||||
quote! { $($first)* }.into()
|
||||
));
|
||||
|
||||
+19
-14
@@ -2,9 +2,9 @@ use super::Tokens;
|
||||
|
||||
use std::borrow::Cow;
|
||||
|
||||
use proc_macro2::{TokenKind, Literal, OpKind, Delimiter, Symbol, TokenTree, Span};
|
||||
use proc_macro2::{TokenNode, Literal, Spacing, Delimiter, Term, TokenTree, Span};
|
||||
|
||||
fn tt(kind: TokenKind) -> TokenTree {
|
||||
fn tt(kind: TokenNode) -> TokenTree {
|
||||
TokenTree {
|
||||
span: Span::default(),
|
||||
kind: kind,
|
||||
@@ -74,15 +74,15 @@ impl<T: ToTokens> ToTokens for Option<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl ToTokens for Symbol {
|
||||
impl ToTokens for Term {
|
||||
fn to_tokens(&self, tokens: &mut Tokens) {
|
||||
tokens.append(tt(TokenKind::Word(*self)));
|
||||
tokens.append(tt(TokenNode::Term(*self)));
|
||||
}
|
||||
}
|
||||
|
||||
impl ToTokens for str {
|
||||
fn to_tokens(&self, tokens: &mut Tokens) {
|
||||
tokens.append(tt(TokenKind::Literal(self.into())));
|
||||
tokens.append(tt(TokenNode::Literal(Literal::string(self))));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ macro_rules! primitive {
|
||||
($($t:ident)*) => ($(
|
||||
impl ToTokens for $t {
|
||||
fn to_tokens(&self, tokens: &mut Tokens) {
|
||||
tokens.append(tt(TokenKind::Literal((*self).into())));
|
||||
tokens.append(tt(TokenNode::Literal(Literal::$t(*self))));
|
||||
}
|
||||
}
|
||||
)*)
|
||||
@@ -105,14 +105,19 @@ macro_rules! primitive {
|
||||
primitive! {
|
||||
i8 i16 i32 i64 isize
|
||||
u8 u16 u32 u64 usize
|
||||
char
|
||||
f32 f64
|
||||
}
|
||||
|
||||
impl ToTokens for char {
|
||||
fn to_tokens(&self, tokens: &mut Tokens) {
|
||||
tokens.append(tt(TokenNode::Literal(Literal::character(*self))));
|
||||
}
|
||||
}
|
||||
|
||||
impl ToTokens for bool {
|
||||
fn to_tokens(&self, tokens: &mut Tokens) {
|
||||
let word = if *self {"true"} else {"false"};
|
||||
tokens.append(tt(TokenKind::Word(Symbol::from(word))));
|
||||
tokens.append(tt(TokenNode::Term(Term::intern(word))));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,7 +128,7 @@ pub struct ByteStr<'a>(pub &'a str);
|
||||
impl<'a> ToTokens for ByteStr<'a> {
|
||||
fn to_tokens(&self, tokens: &mut Tokens) {
|
||||
let lit = Literal::byte_string(self.0.as_bytes());
|
||||
tokens.append(tt(TokenKind::Literal(lit)));
|
||||
tokens.append(tt(TokenNode::Literal(lit)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,9 +137,9 @@ impl<T: ToTokens> ToTokens for [T] {
|
||||
let mut sub = Tokens::new();
|
||||
for item in self {
|
||||
item.to_tokens(&mut sub);
|
||||
sub.append(tt(TokenKind::Op(',', OpKind::Alone)));
|
||||
sub.append(tt(TokenNode::Op(',', Spacing::Alone)));
|
||||
}
|
||||
tokens.append(tt(TokenKind::Sequence(Delimiter::Bracket, sub.into())));
|
||||
tokens.append(tt(TokenNode::Group(Delimiter::Bracket, sub.into())));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,10 +180,10 @@ macro_rules! tuple_impls {
|
||||
let mut _sub = Tokens::new();
|
||||
$(
|
||||
self.$idx.to_tokens(&mut _sub);
|
||||
_sub.append(tt(TokenKind::Op(',', OpKind::Alone)));
|
||||
_sub.append(tt(TokenNode::Op(',', Spacing::Alone)));
|
||||
)*
|
||||
tokens.append(tt(TokenKind::Sequence(Delimiter::Parenthesis,
|
||||
_sub.into())));
|
||||
tokens.append(tt(TokenNode::Group(Delimiter::Parenthesis,
|
||||
_sub.into())));
|
||||
}
|
||||
}
|
||||
)+
|
||||
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
use super::ToTokens;
|
||||
use std::fmt::{self, Display};
|
||||
|
||||
use proc_macro2::{TokenStream, TokenTree, TokenKind, Symbol, Span};
|
||||
use proc_macro2::{TokenStream, TokenTree, TokenNode, Term, Span};
|
||||
use proc_macro2::Delimiter;
|
||||
|
||||
/// Tokens produced by a `quote!(...)` invocation.
|
||||
@@ -34,7 +34,7 @@ impl Tokens {
|
||||
pub fn append_sym(&mut self, sym: &str, span: Span) {
|
||||
self.append(TokenTree {
|
||||
span: span,
|
||||
kind: TokenKind::Word(Symbol::from(sym)),
|
||||
kind: TokenNode::Term(Term::intern(sym)),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ impl Tokens {
|
||||
let ret = f(&mut child);
|
||||
self.append(TokenTree {
|
||||
span: span,
|
||||
kind: TokenKind::Sequence(delim, child.into()),
|
||||
kind: TokenNode::Group(delim, child.into()),
|
||||
});
|
||||
return ret
|
||||
}
|
||||
|
||||
+8
-8
@@ -4,14 +4,14 @@ use std::borrow::Cow;
|
||||
extern crate quote;
|
||||
extern crate proc_macro2;
|
||||
|
||||
use proc_macro2::Symbol;
|
||||
use proc_macro2::Term;
|
||||
|
||||
struct X;
|
||||
|
||||
impl quote::ToTokens for X {
|
||||
fn to_tokens(&self, tokens: &mut quote::Tokens) {
|
||||
tokens.append(proc_macro2::TokenTree {
|
||||
kind: proc_macro2::TokenKind::Word("X".into()),
|
||||
kind: proc_macro2::TokenNode::Term(Term::intern("X")),
|
||||
span: Default::default(),
|
||||
});
|
||||
}
|
||||
@@ -260,8 +260,8 @@ fn test_byte_str_escape() {
|
||||
|
||||
#[test]
|
||||
fn test_ident() {
|
||||
let foo = Symbol::from("Foo");
|
||||
let bar = Symbol::from(format!("Bar{}", 7));
|
||||
let foo = Term::intern("Foo");
|
||||
let bar = Term::intern(&format!("Bar{}", 7));
|
||||
let tokens = quote!(struct #foo; enum #bar {});
|
||||
let expected = "struct Foo ; enum Bar7 { }";
|
||||
assert_eq!(expected, tokens.to_string());
|
||||
@@ -335,9 +335,9 @@ fn test_box_str() {
|
||||
|
||||
#[test]
|
||||
fn test_cow() {
|
||||
let owned: Cow<Symbol> = Cow::Owned(Symbol::from("owned"));
|
||||
let owned: Cow<Term> = Cow::Owned(Term::intern("owned"));
|
||||
|
||||
let ident = Symbol::from("borrowed");
|
||||
let ident = Term::intern("borrowed");
|
||||
let borrowed = Cow::Borrowed(&ident);
|
||||
|
||||
let tokens = quote! { #owned #borrowed };
|
||||
@@ -346,8 +346,8 @@ fn test_cow() {
|
||||
|
||||
#[test]
|
||||
fn test_closure() {
|
||||
fn field_i(i: usize) -> Symbol {
|
||||
Symbol::from(format!("__field{}", i))
|
||||
fn field_i(i: usize) -> Term {
|
||||
Term::intern(&format!("__field{}", i))
|
||||
}
|
||||
|
||||
let fields = (0usize..3)
|
||||
|
||||
Reference in New Issue
Block a user