Bladeren bron

Indent scopes in debug logging

Isaac Woods 4 jaren geleden
bovenliggende
commit
7e3f4ad9e1
2 gewijzigde bestanden met toevoegingen van 8 en 2 verwijderingen
  1. 2 0
      aml/src/lib.rs
  2. 6 2
      aml/src/parser.rs

+ 2 - 0
aml/src/lib.rs

@@ -110,6 +110,7 @@ pub struct AmlContext {
      * These track the state of the context while it's parsing an AML table.
      */
     current_scope: AmlName,
+    scope_indent: usize,
     debug_verbosity: DebugVerbosity,
 }
 
@@ -128,6 +129,7 @@ impl AmlContext {
             current_args: None,
 
             current_scope: AmlName::root(),
+            scope_indent: 0,
             debug_verbosity,
         }
     }

+ 6 - 2
aml/src/parser.rs

@@ -235,16 +235,20 @@ where
     R: core::fmt::Debug,
     P: Parser<'a, 'c, R>,
 {
+    const INDENT_PER_SCOPE: usize = 2;
+
     move |input, context: &'c mut AmlContext| {
         if verbosity <= context.debug_verbosity {
-            trace!("--> {}", scope_name);
+            trace!("{:indent$}--> {}", "", scope_name, indent = context.scope_indent);
         }
 
         // 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 {
-            trace!("<-- {}", scope_name);
+            trace!("{:indent$}<-- {}", "", scope_name, indent = context.scope_indent);
         }
 
         Ok((new_input, context, result))