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 syn::Error;

pub(crate) fn expr_fix(input: &str) -> String {
    let mut peek = input.chars().peekable();
    let mut output = String::new();

    while let Some(cur) = peek.next() {
        let next = peek.peek().copied();
        if let Some(next) = next {
            if next == '{' && !cur.is_alphabetic() {
                output.push(cur);
                output.push('O')
            } else {
                output.push(cur);
            }
        } else {
            output.push(cur);
        }
    }

    output
}

pub fn otr<T>(opt: Option<T>) -> Result<T, Error> {
    match opt {
        Some(val) => Ok(val),
        None => Err(Error::new(proc_macro2::Span::call_site(), "Invalid args")),
    }
}

pub fn ewc<F, T, E>(callback: F) -> Result<T, E>
where
    F: FnOnce() -> Result<T, E>,
{
    // 调用闭包并返回结果
    callback()
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_expr_fix() {
        let input = "F(1, 2, { a: { b:2 } })";
        let output = expr_fix(input);
        assert_eq!(output, "F(1, 2, O{ a: O{ b:2 } })");
    }
}