Parcourir la source

Fix two bugs in parser debug printing

* Comments would appear under module `aml`, but `comment_scopes` would
  appear under `aml::parser`, which throws off the indentation.
* Scopes that aren't printed because they don't meet the verbosity setting
  still contributed to the indent level, so stuff would be massively
  indented by scopes that aren't printed.
Isaac Woods il y a 4 ans
Parent
commit
44ce66dfd8
2 fichiers modifiés avec 14 ajouts et 12 suppressions
  1. 0 9
      aml/src/lib.rs
  2. 14 3
      aml/src/parser.rs

+ 0 - 9
aml/src/lib.rs

@@ -219,15 +219,6 @@ impl AmlContext {
             _ => panic!("Invalid local number: {}", local),
         }
     }
-
-    /// 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 + parser::INDENT_PER_SCOPE);
-        }
-    }
 }
 
 #[derive(Clone, Debug, PartialEq, Eq)]

+ 14 - 3
aml/src/parser.rs

@@ -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);
         }