Skip to content

proc_macro: reexport most of the proc-macro2 public API. #87

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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();
// ...
Expand Down
62 changes: 30 additions & 32 deletions macros/tests/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
);
})
}
2 changes: 1 addition & 1 deletion src/proc_macro.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down