Vendor things
This commit is contained in:
parent
5deceec006
commit
977e3c17e5
19434 changed files with 10682014 additions and 0 deletions
1
third-party/vendor/pmutil/.cargo-checksum.json
vendored
Normal file
1
third-party/vendor/pmutil/.cargo-checksum.json
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"files":{"Cargo.toml":"be8c3a4ffa5a19da85682463e06c40b802fc18c0265e4c9c158ffe56138bd262","LICENSE-APACHE":"769f80b5bcb42ed0af4e4d2fd74e1ac9bf843cb80c5a29219d1ef3544428a6bb","LICENSE-MIT":"30fefc3a7d6a0041541858293bcbea2dde4caa4c0a5802f996a7f7e8c0085652","README.md":"22607fb5b9f78c73721cc6db9b7c56b7a63b43185b93ff61929d741adcef64c9","src/comment.rs":"2f2aa4548e7b6da185b72e8438cde5228b89ac79303cc54a69ef47adc1cbe9d9","src/lib.rs":"62e1343663d13667d17f564399d31130ed4291c49e955785aa9d802707ad506b","src/prelude.rs":"a07d22cbe1d384245963dd2f2fd5b02f576d1cc0a8e4460d79ae74c32aff027f","src/respan.rs":"5c4a793b45dedf0d1964299fee6068b6ab86b65420a2f30d04ee9fbdae5aac24","src/span_ext.rs":"3e41af13410d9dfd8401def6d06f4e3a07e342a5d570a3edbb0ac45db8131d55","src/spanned_quote.rs":"29b660b5b3d7003cbad55164e5634cb50bbd092c4aa8fd2edf0efd3e2cab4141","src/spanned_quote/buffer.rs":"d599db8d098ee8bd3cd4ee22d177d6641ba05c929941f454073533adf3b38f20","src/synom_ext.rs":"1aabd04134329295295648505000ad3da242f7c1830357b0b35ec8a5601b127d"},"package":"52a40bc70c2c58040d2d8b167ba9a5ff59fc9dab7ad44771cfde3dcfde7a09c6"}
|
||||
34
third-party/vendor/pmutil/Cargo.toml
vendored
Normal file
34
third-party/vendor/pmutil/Cargo.toml
vendored
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
|
||||
#
|
||||
# When uploading crates to the registry Cargo will automatically
|
||||
# "normalize" Cargo.toml files for maximal compatibility
|
||||
# with all versions of Cargo and also rewrite `path` dependencies
|
||||
# to registry (e.g., crates.io) dependencies.
|
||||
#
|
||||
# If you are reading this file be aware that the original Cargo.toml
|
||||
# will likely look very different (and much more reasonable).
|
||||
# See Cargo.toml.orig for the original contents.
|
||||
|
||||
[package]
|
||||
edition = "2018"
|
||||
name = "pmutil"
|
||||
version = "0.6.1"
|
||||
authors = ["강동윤 <kdy1@outlook.kr>"]
|
||||
description = "Utils for proc-macro"
|
||||
readme = "README.md"
|
||||
license = "Apache-2.0/MIT"
|
||||
repository = "https://github.com/kdy1/rust-pmutil"
|
||||
|
||||
[dependencies.proc-macro2]
|
||||
version = "1.0"
|
||||
|
||||
[dependencies.quote]
|
||||
version = "1.0"
|
||||
|
||||
[dependencies.syn]
|
||||
version = "2.0"
|
||||
features = [
|
||||
"derive",
|
||||
"parsing",
|
||||
]
|
||||
default-features = false
|
||||
201
third-party/vendor/pmutil/LICENSE-APACHE
vendored
Normal file
201
third-party/vendor/pmutil/LICENSE-APACHE
vendored
Normal file
|
|
@ -0,0 +1,201 @@
|
|||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
23
third-party/vendor/pmutil/LICENSE-MIT
vendored
Normal file
23
third-party/vendor/pmutil/LICENSE-MIT
vendored
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
Permission is hereby granted, free of charge, to any
|
||||
person obtaining a copy of this software and associated
|
||||
documentation files (the "Software"), to deal in the
|
||||
Software without restriction, including without
|
||||
limitation the rights to use, copy, modify, merge,
|
||||
publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software
|
||||
is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice
|
||||
shall be included in all copies or substantial portions
|
||||
of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
|
||||
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
|
||||
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
||||
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
3
third-party/vendor/pmutil/README.md
vendored
Normal file
3
third-party/vendor/pmutil/README.md
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# rust-pmutil
|
||||
|
||||
Utility for proc-macro implementors.
|
||||
36
third-party/vendor/pmutil/src/comment.rs
vendored
Normal file
36
third-party/vendor/pmutil/src/comment.rs
vendored
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
//!
|
||||
//!
|
||||
use super::SpanExt;
|
||||
use proc_macro2::Span;
|
||||
use syn::punctuated::Pair;
|
||||
use syn::*;
|
||||
|
||||
/// Creates a comment from `s`.
|
||||
pub fn comment<S>(s: S) -> Attribute
|
||||
where
|
||||
S: AsRef<str>,
|
||||
{
|
||||
let span = Span::call_site();
|
||||
|
||||
Attribute {
|
||||
style: AttrStyle::Outer,
|
||||
bracket_token: span.as_token(),
|
||||
pound_token: span.as_token(),
|
||||
meta: Meta::NameValue(MetaNameValue {
|
||||
path: Path {
|
||||
leading_colon: None,
|
||||
segments: vec![Pair::End(PathSegment {
|
||||
ident: Ident::new("doc", span),
|
||||
arguments: Default::default(),
|
||||
})]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
},
|
||||
eq_token: span.as_token(),
|
||||
value: Expr::Lit(ExprLit {
|
||||
attrs: Default::default(),
|
||||
lit: Lit::Str(LitStr::new(s.as_ref(), span)),
|
||||
}),
|
||||
}),
|
||||
}
|
||||
}
|
||||
62
third-party/vendor/pmutil/src/lib.rs
vendored
Normal file
62
third-party/vendor/pmutil/src/lib.rs
vendored
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
//! Utils for implementing proc-macro. Works on stable.
|
||||
//!
|
||||
//!
|
||||
//!
|
||||
|
||||
#![recursion_limit = "128"]
|
||||
|
||||
extern crate proc_macro;
|
||||
pub use proc_macro2;
|
||||
pub use quote;
|
||||
pub use syn;
|
||||
|
||||
pub use self::span_ext::SpanExt;
|
||||
use proc_macro2::TokenStream;
|
||||
use quote::ToTokens;
|
||||
pub use spanned_quote::Quote;
|
||||
use syn::Ident;
|
||||
|
||||
pub mod comment;
|
||||
pub mod prelude;
|
||||
pub mod respan;
|
||||
mod span_ext;
|
||||
pub mod spanned_quote;
|
||||
pub mod synom_ext;
|
||||
|
||||
/// Extension trait for [syn::Ident][].
|
||||
///
|
||||
///
|
||||
///[syn::Ident]:../syn/struct.Ident.html
|
||||
pub trait IdentExt {
|
||||
/// Creates a new ident with same span by applying `map` to `self`.
|
||||
fn new_ident_with<F, S>(&self, map: F) -> Ident
|
||||
where
|
||||
F: for<'a> FnOnce(&'a str) -> S,
|
||||
S: AsRef<str>;
|
||||
}
|
||||
|
||||
impl IdentExt for Ident {
|
||||
/// Creates a new ident with same span by applying `map` to `self`.
|
||||
fn new_ident_with<F, S>(&self, map: F) -> Ident
|
||||
where
|
||||
F: for<'a> FnOnce(&'a str) -> S,
|
||||
S: AsRef<str>,
|
||||
{
|
||||
Ident::new(map(&format!("{self}")).as_ref(), self.span())
|
||||
}
|
||||
}
|
||||
|
||||
pub trait ToTokensExt: ToTokens {
|
||||
fn dump(&self) -> TokenStream {
|
||||
let mut tmp = TokenStream::new();
|
||||
self.to_tokens(&mut tmp);
|
||||
tmp
|
||||
}
|
||||
|
||||
/// Usage: `Quote::new(body.first_last())`
|
||||
fn first_last(&self) -> respan::FirstLast {
|
||||
respan::FirstLast::from_tokens(&self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: ToTokens> ToTokensExt for T {}
|
||||
6
third-party/vendor/pmutil/src/prelude.rs
vendored
Normal file
6
third-party/vendor/pmutil/src/prelude.rs
vendored
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
//! Prelude for convenience.
|
||||
|
||||
pub use super::comment::comment;
|
||||
pub use super::spanned_quote::Quote;
|
||||
pub use super::{IdentExt, SpanExt, ToTokensExt};
|
||||
pub use crate::{q, smart_quote};
|
||||
76
third-party/vendor/pmutil/src/respan.rs
vendored
Normal file
76
third-party/vendor/pmutil/src/respan.rs
vendored
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
//! Span support for quasi-quotting.
|
||||
|
||||
use proc_macro2::{Span, TokenStream, TokenTree};
|
||||
use quote::ToTokens;
|
||||
use std::cell::Cell;
|
||||
|
||||
pub trait Respan {
|
||||
/// Used while quasi quotting.
|
||||
fn next_span(&self) -> Span;
|
||||
|
||||
fn respan(&self, mut tt: TokenTree) -> TokenTree {
|
||||
let span = self.next_span();
|
||||
|
||||
match tt {
|
||||
TokenTree::Group(ref mut tt) => tt.set_span(span),
|
||||
TokenTree::Ident(ref mut tt) => tt.set_span(span),
|
||||
TokenTree::Punct(ref mut tt) => tt.set_span(span),
|
||||
TokenTree::Literal(ref mut tt) => tt.set_span(span),
|
||||
}
|
||||
|
||||
tt
|
||||
}
|
||||
}
|
||||
|
||||
impl Respan for Span {
|
||||
fn next_span(&self) -> Span {
|
||||
*self
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, S> Respan for &'a S
|
||||
where
|
||||
S: ?Sized + Respan,
|
||||
{
|
||||
fn next_span(&self) -> Span {
|
||||
<S as Respan>::next_span(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<S> Respan for Box<S>
|
||||
where
|
||||
S: ?Sized + Respan,
|
||||
{
|
||||
fn next_span(&self) -> Span {
|
||||
<S as Respan>::next_span(self)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct FirstLast {
|
||||
first: Cell<Option<Span>>,
|
||||
last: Span,
|
||||
}
|
||||
impl Respan for FirstLast {
|
||||
fn next_span(&self) -> Span {
|
||||
// Default value of Option<_> is None, so Cell<Option<_>>.take() works
|
||||
self.first.take().unwrap_or(self.last)
|
||||
}
|
||||
}
|
||||
|
||||
impl FirstLast {
|
||||
pub fn from_tokens(tokens: &dyn ToTokens) -> Self {
|
||||
let mut spans = TokenStream::new();
|
||||
tokens.to_tokens(&mut spans);
|
||||
let good_tokens = spans.into_iter().collect::<Vec<_>>();
|
||||
let first_span = good_tokens
|
||||
.first()
|
||||
.map(|t| t.span())
|
||||
.unwrap_or(Span::call_site());
|
||||
let last = good_tokens.last().map(|t| t.span()).unwrap_or(first_span);
|
||||
FirstLast {
|
||||
first: Cell::new(Some(first_span)),
|
||||
last,
|
||||
}
|
||||
}
|
||||
}
|
||||
32
third-party/vendor/pmutil/src/span_ext.rs
vendored
Normal file
32
third-party/vendor/pmutil/src/span_ext.rs
vendored
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
use crate::synom_ext::FromSpan;
|
||||
use proc_macro2::Span;
|
||||
|
||||
/// Extension trait for [Span][] and [syn::Span][].
|
||||
///
|
||||
///
|
||||
///[Span]:../proc_macro2/struct.Span.html
|
||||
///[syn::Span]:../syn/struct.Span.html
|
||||
pub trait SpanExt: Copy {
|
||||
fn new_ident<S>(self, s: S) -> syn::Ident
|
||||
where
|
||||
S: AsRef<str>,
|
||||
{
|
||||
syn::Ident::new(s.as_ref(), self.into_pm2_span())
|
||||
}
|
||||
|
||||
/// Creates `Token` from `self`.
|
||||
fn as_token<Token>(self) -> Token
|
||||
where
|
||||
Token: FromSpan,
|
||||
{
|
||||
Token::from_span(self.into_pm2_span())
|
||||
}
|
||||
|
||||
fn into_pm2_span(self) -> Span;
|
||||
}
|
||||
|
||||
impl SpanExt for Span {
|
||||
fn into_pm2_span(self) -> Self {
|
||||
self
|
||||
}
|
||||
}
|
||||
283
third-party/vendor/pmutil/src/spanned_quote.rs
vendored
Normal file
283
third-party/vendor/pmutil/src/spanned_quote.rs
vendored
Normal file
|
|
@ -0,0 +1,283 @@
|
|||
//! Span-aware quasi quotting built on top of `quote` crate.
|
||||
//!
|
||||
|
||||
mod buffer;
|
||||
pub use self::buffer::{Location, Quote};
|
||||
|
||||
#[macro_export]
|
||||
#[doc(hidden)]
|
||||
macro_rules! quoter_location {
|
||||
() => {{
|
||||
$crate::spanned_quote::Location {
|
||||
line: line!(),
|
||||
col: column!(),
|
||||
file_name: file!(),
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
||||
// ----- Start of variable handling macros.
|
||||
|
||||
/// Usage: __sq_handle_vars! { a, b: expression(), c, };
|
||||
///
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
macro_rules! handle_vars_for_quote {
|
||||
(
|
||||
@NORMALIZED {
|
||||
$(
|
||||
$name:ident: $value:expr,
|
||||
)*
|
||||
},
|
||||
) => {
|
||||
$crate::declare_vars_for_quote!(
|
||||
$($name: $value,)*
|
||||
);
|
||||
};
|
||||
|
||||
(
|
||||
@NORMALIZED {
|
||||
$($norm:tt)*
|
||||
},
|
||||
$name:ident,
|
||||
$($rest:tt)*
|
||||
) => {
|
||||
$crate::handle_vars_for_quote!(
|
||||
@NORMALIZED {
|
||||
$($norm)*
|
||||
$name: $name,
|
||||
},
|
||||
$($rest)*
|
||||
)
|
||||
};
|
||||
|
||||
(
|
||||
@NORMALIZED {
|
||||
$($norm:tt)*
|
||||
},
|
||||
$name:ident
|
||||
) => {
|
||||
$crate::handle_vars_for_quote!(
|
||||
@NORMALIZED {
|
||||
$($norm)*
|
||||
$name: $name,
|
||||
},
|
||||
)
|
||||
};
|
||||
|
||||
(
|
||||
@NORMALIZED {
|
||||
$($norm:tt)*
|
||||
},
|
||||
$name:ident: $value:expr,
|
||||
$($rest:tt)*
|
||||
) => {
|
||||
$crate::handle_vars_for_quote!(
|
||||
@NORMALIZED {
|
||||
$($norm)*
|
||||
$name: $value,
|
||||
},
|
||||
$($rest)*
|
||||
)
|
||||
};
|
||||
|
||||
(
|
||||
@NORMALIZED {
|
||||
$($norm:tt)*
|
||||
},
|
||||
$name:ident: $value:expr
|
||||
) => {
|
||||
$crate::handle_vars_for_quote!(
|
||||
@NORMALIZED {
|
||||
$($norm)*
|
||||
$name: $value,
|
||||
},
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
/// This macro handles `Vars`, and creates a new hidden macro used inside quasi-quotting.
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
macro_rules! declare_vars_for_quote {
|
||||
(
|
||||
$(
|
||||
$name:ident: $val:expr,
|
||||
)*
|
||||
) => {
|
||||
$(
|
||||
#[allow(non_snake_case)]
|
||||
let $name = $val;
|
||||
)*
|
||||
|
||||
// This macro quotes only one token at once.
|
||||
macro_rules! __sq_push_token_custom {
|
||||
$(
|
||||
($tokens:expr, $name) => {
|
||||
$tokens.push_tokens(&$name);
|
||||
};
|
||||
)*
|
||||
// default (stringify + parse)
|
||||
($tokens:expr, $t:tt) => {
|
||||
$tokens.push_parsed(stringify!($t));
|
||||
};
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
// ----- End of variable handling macros.
|
||||
|
||||
/// This macro assumes that `Vars` is already handled.
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
macro_rules! __sq_quote_tokens_to {
|
||||
// Done.
|
||||
($tokens:expr,) => {{}};
|
||||
|
||||
($tokens:expr, ( $($inner:tt)* ) $($rest:tt)*) => {{
|
||||
$tokens.push_group(::proc_macro2::Delimiter::Parenthesis, $crate::__sq_quote_closure! {
|
||||
$($inner)*
|
||||
});
|
||||
$crate::__sq_quote_tokens_to!($tokens, $($rest)*);
|
||||
}};
|
||||
|
||||
|
||||
($tokens:expr, { $($inner:tt)* } $($rest:tt)*) => {{
|
||||
$tokens.push_group(::proc_macro2::Delimiter::Brace, $crate::__sq_quote_closure! {
|
||||
$($inner)*
|
||||
});
|
||||
$crate::__sq_quote_tokens_to!($tokens, $($rest)*);
|
||||
}};
|
||||
|
||||
($tokens:expr, [ $($inner:tt)* ] $($rest:tt)*) => {{
|
||||
$tokens.push_group(::proc_macro2::Delimiter::Bracket, $crate::__sq_quote_closure! {
|
||||
$($inner)*
|
||||
});
|
||||
$crate::__sq_quote_tokens_to!($tokens, $($rest)*);
|
||||
}};
|
||||
|
||||
// If we have to quote one token, check if user declared variable.
|
||||
($tokens:expr, $first:tt $($rest:tt)*) => {
|
||||
__sq_push_token_custom!($tokens, $first);
|
||||
|
||||
$crate::__sq_quote_tokens_to!($tokens, $($rest)*);
|
||||
};
|
||||
}
|
||||
|
||||
/// ide-friendly quasi quotting.
|
||||
///
|
||||
///# Syntax
|
||||
///## Vars
|
||||
///Syntax is simillar to field initialization syntax.
|
||||
///
|
||||
///```rust,ignore
|
||||
///Vars {
|
||||
/// a,
|
||||
/// b: expr_b,
|
||||
/// c: fn_c(),
|
||||
/// d,
|
||||
///}
|
||||
/// // is equivalent to
|
||||
///Vars {
|
||||
/// a: a,
|
||||
/// b: expr_b,
|
||||
/// c: fn_c(),
|
||||
/// d: d,
|
||||
///}
|
||||
///
|
||||
///```
|
||||
///
|
||||
///Note that `Vars{}` is required even if there's no variable.
|
||||
///
|
||||
///## Tokens
|
||||
/// As parsers for syntax highligters implement error recovery,
|
||||
/// tokens are wrapped in block or paren like `{ tokens.. }`/ `( tokens.. )`.
|
||||
///
|
||||
///# Example
|
||||
///
|
||||
///```rust,ignore
|
||||
/// smart_quote!(Vars{
|
||||
/// OrigTrait: tr.ident,
|
||||
/// SpecializerTrait: tr.ident.new_ident_with(|tr| format!("{}Specializer", tr)),
|
||||
/// }, {
|
||||
/// impl<T> OrigTrait for T where T: SpecializerTrait {
|
||||
/// }
|
||||
/// })
|
||||
///```
|
||||
///
|
||||
///# Example (no variable)
|
||||
///
|
||||
///```rust,ignore
|
||||
/// smart_quote!(Vars{}, {
|
||||
/// yield ();
|
||||
/// })
|
||||
///```
|
||||
#[macro_export]
|
||||
macro_rules! smart_quote {
|
||||
(
|
||||
Vars{ $($vars:tt)* },
|
||||
{
|
||||
$(
|
||||
$tokens:tt
|
||||
)*
|
||||
}
|
||||
) => {{
|
||||
|_tokens: &mut $crate::Quote| {
|
||||
$crate::handle_vars_for_quote!(@NORMALIZED{}, $($vars)*);
|
||||
|
||||
_tokens.report_loc($crate::quoter_location!());
|
||||
$crate::__sq_quote_tokens_to!(_tokens, $($tokens)*);
|
||||
}
|
||||
}};
|
||||
|
||||
(
|
||||
{
|
||||
$(
|
||||
$tokens:tt
|
||||
)*
|
||||
}
|
||||
) => {{
|
||||
$crate::smart_quote!(Vars {}, { $($tokens)* })
|
||||
}};
|
||||
|
||||
(
|
||||
Vars{ $($vars:tt)* },
|
||||
(
|
||||
$(
|
||||
$tokens:tt
|
||||
)*
|
||||
)
|
||||
) => {
|
||||
$crate::smart_quote!(Vars { $($vars)* }, { $($tokens)* })
|
||||
};
|
||||
|
||||
(
|
||||
(
|
||||
$(
|
||||
$tokens:tt
|
||||
)*
|
||||
)
|
||||
) => {
|
||||
$crate::smart_quote!(Vars {}, { $($tokens)* })
|
||||
};
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
macro_rules! __sq_quote_closure {
|
||||
( $($tokens:tt)* ) => {{
|
||||
|_tokens: &mut $crate::Quote| {
|
||||
_tokens.report_loc($crate::quoter_location!());
|
||||
$crate::__sq_quote_tokens_to!(_tokens, $($tokens)*);
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
||||
/// Shortcut for `Quote::new_call_site().quote_with(smart_quote!( $tokens ))`
|
||||
#[macro_export]
|
||||
macro_rules! q {
|
||||
( $($tokens:tt)* ) => {{
|
||||
$crate::Quote::new_call_site().quote_with($crate::smart_quote!( $($tokens)* ))
|
||||
}};
|
||||
}
|
||||
227
third-party/vendor/pmutil/src/spanned_quote/buffer.rs
vendored
Normal file
227
third-party/vendor/pmutil/src/spanned_quote/buffer.rs
vendored
Normal file
|
|
@ -0,0 +1,227 @@
|
|||
use crate::respan::{self, Respan};
|
||||
use proc_macro2::{Delimiter, Group, Ident, Span, TokenStream, TokenTree};
|
||||
use quote::{ToTokens, TokenStreamExt};
|
||||
use std::collections::HashSet;
|
||||
use std::env;
|
||||
use std::fmt::{self, Display, Formatter, Write};
|
||||
use syn::parse::Parse;
|
||||
|
||||
/// Buffer for quasi quotting.
|
||||
pub struct Quote {
|
||||
tts: TokenStream,
|
||||
span: Option<Box<(dyn Respan + 'static)>>,
|
||||
/// Location of smart_quote! invokations.
|
||||
/// Used for error reporting.
|
||||
sources: HashSet<Location>,
|
||||
}
|
||||
|
||||
const INVALID_SPAN_STATE: &str = "Span is in invalid state.
|
||||
Closure provided to push_group should not panic.";
|
||||
|
||||
/// Location of `smart_quote!` macro invocation.
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
|
||||
pub struct Location {
|
||||
pub file_name: &'static str,
|
||||
pub line: u32,
|
||||
pub col: u32,
|
||||
}
|
||||
|
||||
impl Display for Location {
|
||||
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
||||
write!(f, "{}:{}:{}", self.file_name, self.line, self.col)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Quote {
|
||||
pub fn new<S: Respan + 'static>(span: S) -> Self {
|
||||
Quote {
|
||||
span: Some(Box::new(span)),
|
||||
tts: TokenStream::new(),
|
||||
sources: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Shorthand for
|
||||
///
|
||||
/// ```rust,ignore
|
||||
/// Quote::new(Span::call_site())
|
||||
/// ```
|
||||
pub fn new_call_site() -> Self {
|
||||
Self::new(Span::call_site())
|
||||
}
|
||||
|
||||
/// Shorthand for
|
||||
///
|
||||
/// ```rust,ignore
|
||||
/// Quote::new(tokens.first_last())
|
||||
/// ```
|
||||
pub fn from_tokens(tokens: &dyn ToTokens) -> Self {
|
||||
Self::new(respan::FirstLast::from_tokens(tokens))
|
||||
}
|
||||
|
||||
/// Shorthand for
|
||||
///
|
||||
///```rust,ignore
|
||||
/// tokens
|
||||
/// .as_ref()
|
||||
/// .map(|tokens| Quote::from_tokens(tokens))
|
||||
/// .unwrap_or_else(|| Quote::new(default_span))
|
||||
///```
|
||||
///
|
||||
pub fn from_tokens_or<T: ToTokens>(tokens: &Option<T>, default_span: Span) -> Self {
|
||||
match *tokens {
|
||||
Some(ref tokens) => Self::from_tokens(tokens),
|
||||
None => Self::new(default_span),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Quote {
|
||||
/// Parse tokens as `Node`.
|
||||
/// Panics if parsing failed.
|
||||
pub fn parse<Node>(self) -> Node
|
||||
where
|
||||
Node: Parse,
|
||||
{
|
||||
// TODO: Use span to report error.
|
||||
let Quote { tts, sources, .. } = self;
|
||||
|
||||
let debug_tts = if env::var("DBG_DUMP").is_ok() {
|
||||
Some(tts.clone())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
syn::parse2(tts).unwrap_or_else(|err| {
|
||||
let debug_tts: &dyn Display = match debug_tts {
|
||||
Some(ref tts) => tts,
|
||||
None => {
|
||||
&"To get code failed to parse,
|
||||
please set environment variable `DBG_DUMP` and run in again"
|
||||
}
|
||||
};
|
||||
|
||||
let notes = {
|
||||
let mut b = String::from("Note: quasi quotting was invoked from:\n");
|
||||
for src in &sources {
|
||||
writeln!(b, " {src}").unwrap();
|
||||
}
|
||||
b
|
||||
};
|
||||
|
||||
panic!(
|
||||
"Quote::parse() failed.
|
||||
{notes}
|
||||
Error from syn: {err}
|
||||
>>>>>
|
||||
{debug_tts}
|
||||
<<<<<",
|
||||
notes = notes,
|
||||
err = err,
|
||||
debug_tts = debug_tts
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// Methods for quasi-quotting.
|
||||
impl Quote {
|
||||
#[doc(hidden)]
|
||||
/// Reports location of `smart_quote!` invocation.
|
||||
pub fn report_loc(&mut self, loc: Location) {
|
||||
self.sources.insert(loc);
|
||||
}
|
||||
|
||||
pub fn quote_with<F>(mut self, quote: F) -> Self
|
||||
where
|
||||
F: FnOnce(&mut Self),
|
||||
{
|
||||
(quote)(&mut self);
|
||||
self
|
||||
}
|
||||
|
||||
/// Parse `token` and append it to `self`.
|
||||
pub fn push_parsed(&mut self, token: &str) {
|
||||
let Quote {
|
||||
ref mut span,
|
||||
ref mut tts,
|
||||
..
|
||||
} = *self;
|
||||
|
||||
token
|
||||
.parse::<TokenStream>()
|
||||
.expect("Failed to parse token to quote")
|
||||
.into_iter()
|
||||
.map(|tt| span.as_ref().expect(INVALID_SPAN_STATE).respan(tt))
|
||||
.for_each(|tt| tts.append(tt));
|
||||
}
|
||||
|
||||
/// Append `tt` to `self`.
|
||||
pub fn push_tt(&mut self, tt: TokenTree) {
|
||||
self.tts.append(tt)
|
||||
}
|
||||
|
||||
/// Respan symbol and append it to `self`.
|
||||
pub fn push_sym(&mut self, term: &str) {
|
||||
let span = self.next_span();
|
||||
self.push_tt(TokenTree::Ident(Ident::new(term, span)))
|
||||
}
|
||||
|
||||
fn next_span(&self) -> Span {
|
||||
self.span.as_ref().expect(INVALID_SPAN_STATE).next_span()
|
||||
}
|
||||
|
||||
/// Respan and append `TokenStream::Group`
|
||||
pub fn push_group<F>(&mut self, delim: Delimiter, child: F)
|
||||
where
|
||||
F: FnOnce(&mut Quote),
|
||||
{
|
||||
//TODO: Exception safety
|
||||
let span = self.span.take().expect(INVALID_SPAN_STATE);
|
||||
let mut sub = Quote::new(span);
|
||||
child(&mut sub);
|
||||
self.sources.extend(sub.sources);
|
||||
|
||||
debug_assert!(self.span.is_none());
|
||||
self.span = Some(sub.span.expect(INVALID_SPAN_STATE));
|
||||
|
||||
self.push_tt(TokenTree::Group(Group::new(delim, sub.tts)))
|
||||
}
|
||||
|
||||
/// Appends node into `self` **without respanning**.
|
||||
pub fn push_tokens<T: ?Sized + ToTokens>(&mut self, node: &T) {
|
||||
node.to_tokens(&mut self.tts);
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoIterator for Quote {
|
||||
type IntoIter = <TokenStream as IntoIterator>::IntoIter;
|
||||
type Item = <TokenStream as IntoIterator>::Item;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
self.tts.into_iter()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Quote> for TokenStream {
|
||||
fn from(quote: Quote) -> Self {
|
||||
quote.tts
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Quote> for proc_macro::TokenStream {
|
||||
fn from(quote: Quote) -> Self {
|
||||
TokenStream::from(quote).into()
|
||||
}
|
||||
}
|
||||
|
||||
impl ToTokens for Quote {
|
||||
fn to_tokens(&self, dst: &mut TokenStream) {
|
||||
self.tts.to_tokens(dst)
|
||||
}
|
||||
|
||||
fn into_token_stream(self) -> TokenStream {
|
||||
self.tts
|
||||
}
|
||||
}
|
||||
110
third-party/vendor/pmutil/src/synom_ext.rs
vendored
Normal file
110
third-party/vendor/pmutil/src/synom_ext.rs
vendored
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
//! Utils for tokens from synom::tokens.
|
||||
|
||||
use proc_macro2::Span;
|
||||
use syn::token::*;
|
||||
|
||||
/// See [SpanExt#as_token][] for usage. Create tokens from [Span][].
|
||||
///
|
||||
///
|
||||
///[SpanExt#as_token]:../trait.SpanExt.html#method.as_token
|
||||
///[Span]:../../proc_macro2/struct.Span.html
|
||||
pub trait FromSpan {
|
||||
fn from_span(span: Span) -> Self;
|
||||
}
|
||||
|
||||
impl FromSpan for Span {
|
||||
#[inline(always)]
|
||||
fn from_span(span: Span) -> Self {
|
||||
span
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! impl_array {
|
||||
($n:expr) => {
|
||||
impl<T: FromSpan + Copy> FromSpan for [T; $n] {
|
||||
#[inline(always)]
|
||||
fn from_span(span: Span) -> Self{
|
||||
let e = FromSpan::from_span(span);
|
||||
[e; $n]
|
||||
}
|
||||
}
|
||||
};
|
||||
($n:expr, $($rest:tt)*) => {
|
||||
impl_array!($n);
|
||||
impl_array!($($rest)*);
|
||||
};
|
||||
}
|
||||
|
||||
impl_array!(1, 2, 3, 4);
|
||||
|
||||
macro_rules! bridge_spans {
|
||||
// Done
|
||||
($t:path) => {
|
||||
impl FromSpan for $t {
|
||||
fn from_span(span: Span) -> Self {
|
||||
let spans = FromSpan::from_span(span);
|
||||
$t { spans }
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
($t:path, $($rest:tt)+) => {
|
||||
bridge_spans!($t);
|
||||
bridge_spans!($($rest)*);
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! bridge {
|
||||
// Done
|
||||
($t:path) => {
|
||||
impl FromSpan for $t {
|
||||
fn from_span(span: Span) -> Self {
|
||||
let span = FromSpan::from_span(span);
|
||||
$t { span }
|
||||
}
|
||||
}
|
||||
};
|
||||
($t:path,) => {
|
||||
bridge!($t);
|
||||
};
|
||||
|
||||
($t:path, $($rest:tt)+) => {
|
||||
bridge!($t);
|
||||
bridge!($($rest)*);
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! bridge_group {
|
||||
// Done
|
||||
($t:path) => {
|
||||
impl FromSpan for $t {
|
||||
fn from_span(span: Span) -> Self {
|
||||
$t(span)
|
||||
}
|
||||
}
|
||||
};
|
||||
($t:path,) => {
|
||||
bridge_group!($t);
|
||||
};
|
||||
|
||||
($t:path, $($rest:tt)+) => {
|
||||
bridge_group!($t);
|
||||
bridge_group!($($rest)*);
|
||||
};
|
||||
}
|
||||
|
||||
bridge_spans!(
|
||||
And, AndAnd, AndEq, At, Caret, CaretEq, Colon, Comma, Dollar, Dot, DotDot, DotDotDot, DotDotEq,
|
||||
Eq, EqEq, FatArrow, Ge, Gt, LArrow, Le, Lt, Minus, MinusEq, Ne, Not, Or, OrEq, OrOr, PathSep,
|
||||
Percent, PercentEq, Plus, PlusEq, Pound, Question, RArrow, Semi, Shl, ShlEq, Shr, ShrEq, Slash,
|
||||
SlashEq, Star, StarEq, Tilde, Underscore
|
||||
);
|
||||
|
||||
bridge_group!(Brace, Bracket, Paren);
|
||||
|
||||
bridge!(
|
||||
Abstract, As, Async, Auto, Await, Become, Box, Break, Const, Continue, Crate, Default, Do, Dyn,
|
||||
Else, Enum, Extern, Final, Fn, For, If, Impl, In, Let, Loop, Macro, Match, Mod, Move, Mut,
|
||||
Override, Priv, Pub, Ref, Return, SelfType, SelfValue, Static, Struct, Super, Trait, Try, Type,
|
||||
Typeof, Union, Unsafe, Unsized, Use, Virtual, Where, While, Yield,
|
||||
);
|
||||
Loading…
Add table
Add a link
Reference in a new issue