-
-
Notifications
You must be signed in to change notification settings - Fork 324
How to debug a "failed to parse all tokens" ParseError? #423
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
Comments
request {
pub foo: String,
} This is not syntactically an expression in Rust. |
For failed to parse errors I typically bisect by removing lines until the error goes away and then minimizing until it is obvious what went wrong. |
From your sample input it looks like the relevant types are going to be use syn::{Field, FieldValue};
use syn::punctuated::Punctuated;
use syn::synom::Synom;
struct Exprs {
metadata: Vec<FieldValue>,
request: Vec<Field>,
response: Vec<Field>,
}
type ParseMetadata = Punctuated<FieldValue, Token![,]>;
type ParseFields = Punctuated<Field, Token![,]>;
impl Synom for Exprs {
named!(parse -> Self, do_parse!(
custom_keyword!(metadata) >>
metadata: braces!(ParseMetadata::parse_terminated) >>
custom_keyword!(request) >>
request: braces!(call!(ParseFields::parse_terminated_with, Field::parse_named)) >>
custom_keyword!(response) >>
response: braces!(call!(ParseFields::parse_terminated_with, Field::parse_named)) >>
(Exprs {
// Convert from Punctuated to Vec.
metadata: metadata.1.into_iter().collect(),
request: request.1.into_iter().collect(),
response: response.1.into_iter().collect(),
})
));
} |
Thanks much, @dtolnay! That was enough info for me to progress. Do you think there's anything actionable here in terms of documentation additions? If not, feel free to close the issue. |
I just ran into this while trying to figure out #436. The trick to debugging this is calling use syn::buffer::TokenBuffer;
use syn::synom::Synom;
let buffer = TokenBuffer::new(input);
match Exprs::parse(buffer.begin()) {
Ok((exprs, rest)) => {
println!("Parsed Exprs:- \n{:#?}", exprs.inner);
println!("Remaining tokens:- \n{:#?}", rest.token_stream());
}
Err(error) => println!("Error: {:?}", error),
} |
This is being addressed by #47 and will be shipping in 0.15. |
I'm working on updating ruma-api-macros from syn 0.11 to 0.13 and I finally got the version using 0.13 compiling. However, when I run the integration test, I get this error:
I see the error is generated here but I'm not sure what to do to figure out why.
The macro invocation looks like this:
and I'm attempting to parse it like this:
Apparently the structure of the macro syntax cannot be represented as a series of
Expr
s? I tried usingExprStruct
s instead, but no dice. Is there another type I should be using to represent this syntax? I might be able to figure it out myself if I had a better idea where the parser was getting stuck.The text was updated successfully, but these errors were encountered: