ds_decomp/config/
mod.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use std::{fmt::Display, str::SplitWhitespace};

pub mod config;
pub mod delinks;
pub mod module;
pub mod relocations;
pub mod section;
pub mod symbol;

#[derive(Debug, Clone)]
pub struct ParseContext {
    pub file_path: String,
    pub row: usize,
}

impl Display for ParseContext {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}:{}", self.file_path, self.row)
    }
}

// Shorthand for snafu errors
impl From<&ParseContext> for ParseContext {
    fn from(val: &ParseContext) -> Self {
        val.clone()
    }
}
impl From<&mut ParseContext> for ParseContext {
    fn from(val: &mut ParseContext) -> Self {
        val.clone()
    }
}

pub(crate) fn iter_attributes(words: SplitWhitespace<'_>) -> ParseAttributesIterator<'_> {
    ParseAttributesIterator { words }
}

pub(crate) struct ParseAttributesIterator<'a> {
    words: SplitWhitespace<'a>,
}

impl<'a> Iterator for ParseAttributesIterator<'a> {
    type Item = (&'a str, &'a str);

    fn next(&mut self) -> Option<Self::Item> {
        let word = self.words.next()?;
        Some(word.split_once(':').unwrap_or((word, "")))
    }
}