Consume all tokens if we can't read an Ident, to avoid further errors

parent ef94c8b8
......@@ -184,8 +184,13 @@ mod parser;
///
#[proc_macro]
pub fn gobject_gen(input: TokenStream) -> TokenStream {
let ast_program = if let Ok(ast_program) = parser::parse_program(input) {
ast_program
} else {
return quote!{ }.into();
};
let result: Result<quote::Tokens> = (|| {
let ast_program = parser::parse_program(input)?;
let program = hir::Program::from_ast_program(&ast_program)?;
gen::classes(&program)
})();
......
......@@ -152,7 +152,17 @@ impl Synom for ast::ImplItemKind {
macro_rules! error_not_ident {
($i:expr,) => {{
let mut i = $i;
if let Some((token, _)) = i.token_tree() {
if let Some((token, tts)) = i.token_tree() {
i = tts;
loop {
if i.eof() {
break;
}
if let Some((tok, tts)) = i.token_tree() {
println!("token: {}", tok);
i = tts;
}
}
let span = token.span().unstable();
Diagnostic::spanned(
span.clone(),
......@@ -160,13 +170,16 @@ macro_rules! error_not_ident {
format!("expected identifier, found `{}`", token),
).emit();
}
Ok((Ident::from("__foo"), $i))
Ok(((), i))
}}
}
named!{parse_ident -> syn::Ident,
alt!(syn!(syn::Ident)
| error_not_ident!())
| do_parse!(
error_not_ident!() >>
map!(reject!(), |()| ()) >>
(Ident::from("__foo"))))
}
impl Synom for ast::ImplItemMethod {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment