pest-parser / ast

Apache License 2.0
81 stars 15 forks source link

Add teeny tiny amount of trace logging #17

Closed killercup closed 5 years ago

killercup commented 5 years ago

This is a first step towards #9.

I had waaaay more logs in there but those were just for me to understand how this works. (Turns out, I just wrote inner where it should've said outer.)

CAD97 commented 5 years ago

To avoid the need to add log to the user's crate, log should probably be re-exported from from-pest conditionally. Honestly, I'm fine just adding log support unconditionally, it's good to have and it's not like log is going to significantly change the compile time of this procedural macro.

The problem with adding a "peer dependency" like this is that it'll break upstream crates using pest-ast as well as the crate enabling the feature, so it's not purely additive.

killercup commented 5 years ago

Good idea about re-exporting log. It might be a bit tricky to get it right, though, as a single log::trace!(..) expands to this:

{
    let lvl = ::log::Level::Trace;
    if lvl <= ::log::STATIC_MAX_LEVEL && lvl <= ::log::max_level() {
        ::log::__private_api_log( fmt_args!(OMITTED) );
    }
};

As you can see, it refers to a few items from log itself. I'll try to adapt the function I added to directly emit this code while replacing ::log:: with ::from_pest::.

I'll still keep it behind a feature flag, just because it's no additional work; but I'll enable it by default.

killercup commented 5 years ago

Ah, nope, not necessary thanks to #[macro_export(local_inner_macros)]!