|
@@ -4,7 +4,18 @@ use core::marker::PhantomData;
|
|
|
use log::trace;
|
|
|
|
|
|
/// This is the number of spaces added to indent a scope when printing parser debug messages.
|
|
|
-pub(crate) const INDENT_PER_SCOPE: usize = 2;
|
|
|
+pub const INDENT_PER_SCOPE: usize = 2;
|
|
|
+
|
|
|
+impl AmlContext {
|
|
|
+ /// This is used by the parser to provide debug comments about the current object, which are indented to the
|
|
|
+ /// correct level for the current object. We most often need to print these comments from `map_with_context`s,
|
|
|
+ /// so it's most convenient to have this method on `AmlContext`.
|
|
|
+ pub(crate) fn comment(&self, verbosity: DebugVerbosity, message: &str) {
|
|
|
+ if verbosity <= self.debug_verbosity {
|
|
|
+ log::trace!("{:indent$}{}", "", message, indent = self.scope_indent + INDENT_PER_SCOPE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
pub type ParseResult<'a, 'c, R> =
|
|
|
Result<(&'a [u8], &'c mut AmlContext, R), (&'a [u8], &'c mut AmlContext, AmlError)>;
|
|
@@ -241,14 +252,14 @@ where
|
|
|
move |input, context: &'c mut AmlContext| {
|
|
|
if verbosity <= context.debug_verbosity {
|
|
|
trace!("{:indent$}--> {}", "", scope_name, indent = context.scope_indent);
|
|
|
+ context.scope_indent += INDENT_PER_SCOPE;
|
|
|
}
|
|
|
|
|
|
// Return if the parse fails, so we don't print the tail. Makes it easier to debug.
|
|
|
- context.scope_indent += INDENT_PER_SCOPE;
|
|
|
let (new_input, context, result) = parser.parse(input, context)?;
|
|
|
- context.scope_indent -= INDENT_PER_SCOPE;
|
|
|
|
|
|
if verbosity <= context.debug_verbosity {
|
|
|
+ context.scope_indent -= INDENT_PER_SCOPE;
|
|
|
trace!("{:indent$}<-- {}", "", scope_name, indent = context.scope_indent);
|
|
|
}
|
|
|
|