Browse Source

Parse PrefixPath with no ^s and clean up some warnings

Isaac Woods 5 years ago
parent
commit
6af60fb366
4 changed files with 19 additions and 19 deletions
  1. 17 4
      aml_parser/src/name_object.rs
  2. 1 0
      aml_parser/src/opcode.rs
  3. 1 12
      aml_parser/src/parser.rs
  4. 0 3
      aml_parser/src/pkg_length.rs

+ 17 - 4
aml_parser/src/name_object.rs

@@ -1,6 +1,6 @@
 use crate::{
-    opcode::{opcode, DUAL_NAME_PREFIX, MULTI_NAME_PREFIX, NULL_NAME, ROOT_CHAR},
-    parser::{choice, consume, n_of, take, Parser},
+    opcode::{opcode, DUAL_NAME_PREFIX, MULTI_NAME_PREFIX, NULL_NAME, PREFIX_CHAR, ROOT_CHAR},
+    parser::{choice, comment_scope, consume, n_of, take, Parser},
     AmlError,
 };
 use alloc::string::String;
@@ -11,11 +11,24 @@ pub fn name_string<'a>() -> impl Parser<'a, String> {
      * NameString := <RootChar('\') NamePath> | <PrefixPath NamePath>
      * PrefixPath := Nothing | <'^' PrefixPath>
      */
-    // TODO: this does not yet parse <PrefixPath NamePath>
     let root_name_string =
         opcode(ROOT_CHAR).then(name_path()).map(|((), name_path)| String::from("\\") + &name_path);
 
-    choice!(root_name_string)
+    comment_scope("NameString", move |input: &'a [u8]| {
+        let first_char = *input.first().ok_or((input, AmlError::UnexpectedEndOfStream))?;
+        log::trace!("First char: {}, {:#x}", first_char, first_char);
+
+        match first_char {
+            ROOT_CHAR => root_name_string.parse(input),
+
+            PREFIX_CHAR => {
+                // TODO: parse <PrefixPath NamePath> where there are actually PrefixChars
+                unimplemented!();
+            }
+
+            _ => name_path().parse(input),
+        }
+    })
 }
 
 pub fn name_path<'a>() -> impl Parser<'a, String> {

+ 1 - 0
aml_parser/src/opcode.rs

@@ -4,6 +4,7 @@ pub const NULL_NAME: u8 = 0x00;
 pub const DUAL_NAME_PREFIX: u8 = 0x2E;
 pub const MULTI_NAME_PREFIX: u8 = 0x2F;
 pub const ROOT_CHAR: u8 = b'\\';
+pub const PREFIX_CHAR: u8 = b'^';
 
 pub const ZERO_OP: u8 = 0x00;
 pub const ONE_OP: u8 = 0x01;

+ 1 - 12
aml_parser/src/parser.rs

@@ -132,7 +132,7 @@ where
         let mut results = Vec::with_capacity(n);
         let mut new_input = input;
 
-        for i in 0..n {
+        for _ in 0..n {
             let (after_input, result) = match parser.parse(new_input) {
                 Ok((input, result)) => (input, result),
                 Err((_, err)) => return Err((input, err)),
@@ -156,17 +156,6 @@ where
     }
 }
 
-// TODO: can we make this formattable with stuff from the parse result?
-pub fn comment<'a, P, R>(parser: P, comment: &'static str) -> impl Parser<'a, R>
-where
-    P: Parser<'a, R>,
-{
-    move |input| {
-        trace!("{}", comment);
-        parser.parse(input)
-    }
-}
-
 pub fn comment_scope<'a, P, R>(scope_name: &'a str, parser: P) -> impl Parser<'a, R>
 where
     P: Parser<'a, R>,

+ 0 - 3
aml_parser/src/pkg_length.rs

@@ -3,7 +3,6 @@ use crate::{
     AmlError,
 };
 use bit_field::BitField;
-use log::trace;
 
 #[derive(Clone, Copy, PartialEq, Eq, Debug)]
 pub struct PkgLength {
@@ -49,8 +48,6 @@ pub fn raw_pkg_length<'a>() -> impl Parser<'a, u32> {
      * The length encoded by the PkgLength includes the number of bytes used to encode it.
      */
     move |input: &'a [u8]| {
-        let starting_len = input.len() as u32;
-
         let (new_input, lead_byte) = take().parse(input)?;
         let byte_count = lead_byte.get_bits(6..8);