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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
mod process_line;
mod parsing_lines;

use parsing_lines::ParsingLines;
use process_line::process_line;


#[cfg(test)]
mod tests;


// ------------------------------------------------------------------
// ------------------------------------------------------------------
//  API

//  CONSTANTS
const EOL: char = '\n';
const PUSH_INDENT: char = 0x02 as char;
const POP_INDENT: char = 0x03 as char;


//  NEW TYPES
#[derive(Debug, PartialEq, Copy, Clone)]
pub struct LineNum(u32);

#[derive(Debug, PartialEq, Clone, Eq)]
pub struct SLine(String);

#[derive(Debug, PartialEq, Clone, Eq, Default)]
pub struct SFlattedText(String);



//  ERROR TYPE
#[derive(Debug, PartialEq)]
pub struct Error {
    pub line: LineNum,
    pub desc: String,
}


//  FUNCTION
pub fn flatter(input: &str) -> Result<SFlattedText, Error> {
    let mut parsing_lines = ParsingLines::new();

    for l in input.lines() {
        parsing_lines.add_opt_line(&process_line(&SLine::from(l)))?;
    }

    parsing_lines.close();
    Ok(parsing_lines.flat_text)
}


//  API
// ------------------------------------------------------------------
// ------------------------------------------------------------------



#[derive(Debug, PartialEq, Eq, Copy, Clone, PartialOrd, Ord)]
pub struct NSpaces(usize);


impl SLine {
    pub fn new() -> Self {
        SLine(String::new())
    }
    pub fn from(s: &str) -> Self {
        SLine(String::from(s))
    }
}

impl SFlattedText {
    pub fn new() -> Self {
        SFlattedText(String::new())
    }
    pub fn from(s: &str) -> Self {
        SFlattedText(String::from(s))
    }
}