Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
parity
Mirrored projects
ink
Commits
5a4d7fb6
Unverified
Commit
5a4d7fb6
authored
Mar 28, 2019
by
Robin Freyler
Browse files
[lang] Use proc_macro2::TokenStream as TokenStream2 (readability)
parent
1ff12504
Changes
5
Hide whitespace changes
Inline
Side-by-side
lang/src/ast.rs
View file @
5a4d7fb6
...
...
@@ -16,7 +16,10 @@
use
crate
::
parser
::
keywords
;
use
proc_macro2
::
Ident
;
use
proc_macro2
::{
Ident
,
TokenStream
as
TokenStream2
,
};
use
syn
::{
punctuated
::
Punctuated
,
token
,
...
...
@@ -161,7 +164,7 @@ pub enum FnArg {
}
impl
quote
::
ToTokens
for
FnArg
{
fn
to_tokens
(
&
self
,
tokens
:
&
mut
proc_macro2
::
TokenStream
)
{
fn
to_tokens
(
&
self
,
tokens
:
&
mut
TokenStream
2
)
{
match
self
{
FnArg
::
SelfRef
(
arg_self_ref
)
=>
arg_self_ref
.to_tokens
(
tokens
),
FnArg
::
SelfValue
(
arg_self_value
)
=>
arg_self_value
.to_tokens
(
tokens
),
...
...
lang/src/errors.rs
View file @
5a4d7fb6
...
...
@@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with pDSL. If not, see <http://www.gnu.org/licenses/>.
use
proc_macro2
::
TokenStream
;
use
proc_macro2
::
TokenStream
as
TokenStream2
;
use
quote
::
ToTokens
;
use
std
::
result
::
Result
as
StdResult
;
pub
use
syn
::
parse
::
Error
as
SynError
;
...
...
@@ -61,7 +61,7 @@ impl From<Vec<Errors>> for Errors {
/// Used to create a TokenStream from a list of errors
impl
ToTokens
for
Errors
{
fn
to_tokens
(
&
self
,
tokens
:
&
mut
TokenStream
)
{
fn
to_tokens
(
&
self
,
tokens
:
&
mut
TokenStream
2
)
{
for
item
in
self
.errors
.iter
()
{
item
.to_compile_error
()
.to_tokens
(
tokens
);
}
...
...
lang/src/lib.rs
View file @
5a4d7fb6
...
...
@@ -18,10 +18,12 @@
extern
crate
proc_macro
;
use
proc_macro
::
TokenStream
;
use
proc_macro2
::
TokenStream
as
TokenStream2
;
use
quote
::
ToTokens
;
#[proc_macro]
pub
fn
contract
(
input
:
proc_macro
::
TokenStream
)
->
proc_macro
::
TokenStream
{
pub
fn
contract
(
input
:
TokenStream
)
->
TokenStream
{
match
contract_gen_impl
(
input
)
{
Ok
(
tokens
)
=>
tokens
,
Err
(
err
)
=>
err
.into_token_stream
()
.into
(),
...
...
@@ -52,15 +54,15 @@ use errors::Result;
/// The actual `proc_macro` interface has to operate on `proc_macro::TokenStream`
/// but to keep this library testable we want to use only `proc_macro2::*` entities
/// internally.
fn
contract_gen_impl
(
input
:
proc_macro
::
TokenStream
)
->
Result
<
proc_macro
::
TokenStream
>
{
fn
contract_gen_impl
(
input
:
TokenStream
)
->
Result
<
TokenStream
>
{
contract_gen_impl2
(
input
.into
())
.map
(
Into
::
into
)
}
/// Parses the given token stream as pDSL contract, performs some checks and returns
/// the corresponding contract as token stream.
pub
(
crate
)
fn
contract_gen_impl2
(
input
:
proc_macro2
::
TokenStream
,
)
->
Result
<
proc_macro2
::
TokenStream
>
{
input
:
TokenStream
2
,
)
->
Result
<
TokenStream
2
>
{
let
ast_contract
=
parser
::
parse_contract
(
input
.clone
())
?
;
let
hir_contract
=
hir
::
Contract
::
from_ast
(
&
ast_contract
)
?
;
generate_api_description
(
&
hir_contract
)
?
;
...
...
lang/src/parser.rs
View file @
5a4d7fb6
...
...
@@ -15,6 +15,7 @@
// along with pDSL. If not, see <http://www.gnu.org/licenses/>.
use
crate
::
ast
;
use
proc_macro2
::
TokenStream
as
TokenStream2
;
use
syn
::{
self
,
parse
::{
...
...
@@ -33,7 +34,7 @@ pub mod keywords {
custom_keyword!
(
external
);
}
pub
fn
parse_contract
(
token_stream
:
proc_macro2
::
TokenStream
)
->
Result
<
ast
::
Contract
>
{
pub
fn
parse_contract
(
token_stream
:
TokenStream
2
)
->
Result
<
ast
::
Contract
>
{
syn
::
parse2
(
token_stream
)
.map_err
(
Into
::
into
)
}
...
...
lang/src/tests/utils.rs
View file @
5a4d7fb6
...
...
@@ -15,10 +15,11 @@
// along with pDSL. If not, see <http://www.gnu.org/licenses/>.
use
crate
::
contract_gen_impl2
;
use
proc_macro2
::
TokenStream
as
TokenStream2
;
pub
fn
assert_eq_tokenstreams
(
input
:
proc_macro2
::
TokenStream
,
expected
:
proc_macro2
::
TokenStream
,
input
:
TokenStream
,
expected
:
TokenStream
,
)
{
assert_eq!
(
contract_gen_impl2
(
input
)
...
...
@@ -28,7 +29,7 @@ pub fn assert_eq_tokenstreams(
)
}
pub
fn
assert_failure
(
input
:
proc_macro2
::
TokenStream
,
err_str
:
&
'static
str
)
{
pub
fn
assert_failure
(
input
:
TokenStream
,
err_str
:
&
'static
str
)
{
assert_eq!
(
contract_gen_impl2
(
input
)
.map
(|
result
|
result
.to_string
())
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment