Skip to content

Commit 24fc952

Browse files
committed
proc_macro: reexport most of the proc-macro2 public API.
1 parent af751ee commit 24fc952

File tree

3 files changed

+32
-38
lines changed

3 files changed

+32
-38
lines changed

README.md

+1-5
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@ Easiest way to get started is through `gll-macros`:
1111
[dependencies]
1212
gll = "0.0.2"
1313
gll-macros = "0.0.2"
14-
proc-macro2 = "0.4.20"
1514
```
1615
```rust
1716
extern crate gll;
1817
extern crate gll_macros;
19-
extern crate proc_macro2;
2018
```
2119

2220
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).
4240

4341
To parse a string with that grammar:
4442
```rust
45-
use proc_macro2::TokenStream;
46-
47-
let tokens: TokenStream = string.parse().unwrap();
43+
let tokens = string.parse::<::gll::proc_macro::TokenStream>().unwrap();
4844
json_like::Value::parse_with(tokens, |parser, result| {
4945
let value = result.unwrap();
5046
// ...

macros/tests/json.rs

+30-32
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,30 @@ mod json_like {
1919

2020
#[test]
2121
fn json_like_proc_macro() {
22-
json_like::Value::parse_with(
23-
quote::quote! {
24-
// Example from `serde_json`.
25-
{
26-
name: "John Doe",
27-
age: 43,
28-
address: {
29-
street: "10 Downing Street",
30-
city: "London"
31-
},
32-
phones: [
33-
"+44 1234567",
34-
"+44 2345678"
35-
],
22+
let tokens: ::gll::proc_macro::TokenStream = quote::quote! {
23+
// Example from `serde_json`.
24+
{
25+
name: "John Doe",
26+
age: 43,
27+
address: {
28+
street: "10 Downing Street",
29+
city: "London"
30+
},
31+
phones: [
32+
"+44 1234567",
33+
"+44 2345678"
34+
],
3635

37-
test: [null, false, true, (format!("{:?}", Some(1 + 2)))]
38-
}
39-
},
40-
|_, result| {
41-
let result = format!("{:#?}", result.unwrap());
42-
// HACK(eddyb) clean up the result, as we have no span info.
43-
let result = result
44-
.replace("Span..Span => ", "")
45-
.replace("Span..Span", "?");
46-
let expected = "\
36+
test: [null, false, true, (format!("{:?}", Some(1 + 2)))]
37+
}
38+
};
39+
json_like::Value::parse_with(tokens, |_, result| {
40+
let result = format!("{:#?}", result.unwrap());
41+
// HACK(eddyb) clean up the result, as we have no span info.
42+
let result = result
43+
.replace("Span..Span => ", "")
44+
.replace("Span..Span", "?");
45+
let expected = "\
4746
Value::Object {
4847
fields: [
4948
Field {
@@ -111,12 +110,11 @@ Value::Object {
111110
}
112111
]
113112
}";
114-
assert!(
115-
result == expected,
116-
"mismatched output, expected:\n{}\n\nfound:\n{}",
117-
expected,
118-
result
119-
);
120-
},
121-
)
113+
assert!(
114+
result == expected,
115+
"mismatched output, expected:\n{}\n\nfound:\n{}",
116+
expected,
117+
result
118+
);
119+
})
122120
}

src/proc_macro.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use generate::rust::RustInputPat;
22
use grammar::{self, call, eat, MatchesEmpty, MaybeKnown};
33
use indexing::Container;
4-
use proc_macro2::{
4+
pub use proc_macro2::{
55
Delimiter, Ident, LexError, Literal, Punct, Spacing, Span, TokenStream, TokenTree,
66
};
77
use runtime::{Input, InputMatch, Range};

0 commit comments

Comments
 (0)