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
pub mod instructions;
pub mod interpreter;

/// This function transpiles brainfuck code to ojisanfuck code.
/// This is useful to generate ojisanfuck code.
pub fn transpile_from(source: &str) -> String {
    source
        .chars()
        .filter_map(|c| match c {
            '>' => Some('😅'),
            '<' => Some('😭'),
            '+' => Some('😘'),
            '-' => Some('😚'),
            '.' => Some('💦'),
            ',' => Some('⁉'),
            '[' => Some('✋'),
            ']' => Some('🤟'),
            _ => None,
        })
        .collect::<String>()
}

#[derive(Debug)]
pub enum EvalError {
    MemoryOverflow,
    MemoryUnderflow,
    MemoryOutOfRange,
    UnbalancedBracket,
    InputExhausted,
}

#[cfg(test)]
mod tests {
    use crate::transpile_from;

    #[test]
    fn test_transpile() {
        let source = ">v<+a-.,[x]";
        let expected = "😅😭😘😚💦⁉✋🤟";
        assert_eq!(expected, transpile_from(source));
    }
}