vgtk_macros/
lib.rs

1#![cfg_attr(can_show_location_of_runtime_parse_error, feature(proc_macro_span))]
2#![deny(rust_2018_idioms, unsafe_code)]
3
4#[allow(clippy::useless_attribute)]
5extern crate proc_macro;
6
7use proc_macro_hack::proc_macro_hack;
8
9mod context;
10mod error;
11mod gtk;
12mod lexer;
13mod parser;
14
15#[proc_macro_hack]
16pub fn gtk(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
17    // let orig_stream = input.clone();
18    // let input: proc_macro2::TokenStream = input.into();
19    // panic!("{:?}", input);
20    let stream: lexer::Tokens = input.into();
21    // panic!("{:?}", stream);
22
23    let result = parser::grammar::GtkElementParser::new().parse(stream.lexer());
24    match result {
25        Err(err) => error::parse_error(&stream, &err),
26        Ok(element) => gtk::expand_gtk(&element),
27    }
28    .into()
29
30    // let mut f = std::fs::OpenOptions::new()
31    //     .append(true)
32    //     .open("macroexpand.log")
33    //     .expect("unable to open macroexpand.log");
34    // use std::io::Write;
35    // f.write_fmt(format_args!(
36    //     "Original stream:\n\n{}\n\nExpanded stream:\n\n{}\n\n------\n\n",
37    //     orig_stream, result
38    // ))
39    // .expect("unable to write to macroexpand.log");
40}