From 2d58877cd557215675088edad7643972b87ba1bd Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Fri, 2 Nov 2018 21:01:49 +0200 Subject: [PATCH] proc_macro: reexport most of the proc-macro2 public API. --- README.md | 6 +---- macros/tests/json.rs | 62 +++++++++++++++++++++----------------------- src/proc_macro.rs | 2 +- 3 files changed, 32 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index 5a4d457..5871dc6 100644 --- a/README.md +++ b/README.md @@ -11,12 +11,10 @@ Easiest way to get started is through `gll-macros`: [dependencies] gll = "0.0.2" gll-macros = "0.0.2" -proc-macro2 = "0.4.20" ``` ```rust extern crate gll; extern crate gll_macros; -extern crate proc_macro2; ``` As an example, this is what you might write for a JSON-like syntax, @@ -42,9 +40,7 @@ You can also use a build script to generate the parser (**TODO**: document). To parse a string with that grammar: ```rust -use proc_macro2::TokenStream; - -let tokens: TokenStream = string.parse().unwrap(); +let tokens = string.parse::<::gll::proc_macro::TokenStream>().unwrap(); json_like::Value::parse_with(tokens, |parser, result| { let value = result.unwrap(); // ... diff --git a/macros/tests/json.rs b/macros/tests/json.rs index 67d484f..beda378 100644 --- a/macros/tests/json.rs +++ b/macros/tests/json.rs @@ -19,31 +19,30 @@ mod json_like { #[test] fn json_like_proc_macro() { - json_like::Value::parse_with( - quote::quote! { - // Example from `serde_json`. - { - name: "John Doe", - age: 43, - address: { - street: "10 Downing Street", - city: "London" - }, - phones: [ - "+44 1234567", - "+44 2345678" - ], + let tokens: ::gll::proc_macro::TokenStream = quote::quote! { + // Example from `serde_json`. + { + name: "John Doe", + age: 43, + address: { + street: "10 Downing Street", + city: "London" + }, + phones: [ + "+44 1234567", + "+44 2345678" + ], - test: [null, false, true, (format!("{:?}", Some(1 + 2)))] - } - }, - |_, result| { - let result = format!("{:#?}", result.unwrap()); - // HACK(eddyb) clean up the result, as we have no span info. - let result = result - .replace("Span..Span => ", "") - .replace("Span..Span", "?"); - let expected = "\ + test: [null, false, true, (format!("{:?}", Some(1 + 2)))] + } + }; + json_like::Value::parse_with(tokens, |_, result| { + let result = format!("{:#?}", result.unwrap()); + // HACK(eddyb) clean up the result, as we have no span info. + let result = result + .replace("Span..Span => ", "") + .replace("Span..Span", "?"); + let expected = "\ Value::Object { fields: [ Field { @@ -116,12 +115,11 @@ Value::Object { let normalize = |s: &str| { s.replace(",\n", "\n") }; - assert!( - normalize(&result) == normalize(expected), - "mismatched output, expected:\n{}\n\nfound:\n{}", - expected, - result - ); - }, - ) + assert!( + normalize(&result) == normalize(expected), + "mismatched output, expected:\n{}\n\nfound:\n{}", + expected, + result + ); + }) } diff --git a/src/proc_macro.rs b/src/proc_macro.rs index bd80b0f..1615f94 100644 --- a/src/proc_macro.rs +++ b/src/proc_macro.rs @@ -1,7 +1,7 @@ use generate::rust::RustInputPat; use grammar::{self, call, eat, MatchesEmpty, MaybeKnown}; use indexing::Container; -use proc_macro2::{ +pub use proc_macro2::{ Delimiter, Ident, LexError, Literal, Punct, Spacing, Span, TokenStream, TokenTree, }; use runtime::{Input, InputMatch, Range};