• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

TyRoXx / NonlocalityOS / 15376226008

01 Jun 2025 02:37PM UTC coverage: 73.929% (+1.0%) from 72.943%
15376226008

Pull #276

github

web-flow
Merge 1ddae1c07 into 458977aea
Pull Request #276: GH-275: begin code formatting algorithm

183 of 184 new or added lines in 2 files covered. (99.46%)

3658 of 4948 relevant lines covered (73.93%)

2095.89 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.18
/lambda_compiler/src/format.rs
1
use crate::ast::{Expression, LambdaParameter};
2

3
fn format_string_literal<W>(content: &str, writer: &mut W) -> std::fmt::Result
6✔
4
where
5
    W: std::fmt::Write,
6
{
7
    write!(writer, "\"")?;
6✔
8
    for character in content.chars() {
29✔
9
        match character {
23✔
10
            '"' | '\'' | '\\' => write!(writer, "\\{}", character)?,
3✔
11
            '\n' => write!(writer, "\\n")?,
1✔
12
            '\r' => write!(writer, "\\r")?,
1✔
13
            '\t' => write!(writer, "\\t")?,
1✔
14
            _ => write!(writer, "{}", character)?,
17✔
15
        }
16
    }
17
    write!(writer, "\"")
6✔
18
}
19

20
fn format_apply<W>(
3✔
21
    callee: &Expression,
22
    arguments: &[Expression],
23
    writer: &mut W,
24
) -> std::fmt::Result
25
where
26
    W: std::fmt::Write,
27
{
28
    format_expression(callee, writer)?;
3✔
29
    write!(writer, "(")?;
3✔
30
    for argument in arguments.iter() {
6✔
31
        format_expression(argument, writer)?;
3✔
32
        write!(writer, ", ")?;
3✔
33
    }
34
    write!(writer, ")")
3✔
35
}
36

37
fn format_lambda<W>(
4✔
38
    parameters: &[LambdaParameter],
39
    body: &Expression,
40
    writer: &mut W,
41
) -> std::fmt::Result
42
where
43
    W: std::fmt::Write,
44
{
45
    write!(writer, "(")?;
4✔
46
    for parameter in parameters.iter() {
8✔
47
        write!(writer, "{}", parameter.name.key)?;
4✔
48
        match &parameter.type_annotation {
4✔
49
            Some(type_annotation) => {
1✔
50
                write!(writer, ": ")?;
1✔
51
                format_expression(type_annotation, writer)?;
1✔
52
            }
53
            None => {}
3✔
54
        }
55
        write!(writer, ", ")?;
4✔
56
    }
57
    write!(writer, ") => ")?;
4✔
58
    format_expression(body, writer)
4✔
59
}
60

61
pub fn format_expression<W>(expression: &Expression, writer: &mut W) -> std::fmt::Result
33✔
62
where
63
    W: std::fmt::Write,
64
{
65
    match expression {
33✔
66
        Expression::Identifier(name, _source_location) => write!(writer, "{}", &name.key),
15✔
67
        Expression::StringLiteral(content) => format_string_literal(content, writer),
6✔
68
        Expression::Apply { callee, arguments } => format_apply(callee, arguments, writer),
3✔
69
        Expression::Lambda { parameters, body } => format_lambda(&parameters, body, writer),
4✔
70
        Expression::ConstructTree(children) => {
3✔
71
            write!(writer, "[")?;
3✔
72
            for child in children.iter() {
6✔
73
                format_expression(child, writer)?;
3✔
74
                write!(writer, ", ")?;
3✔
75
            }
76
            write!(writer, "]")
3✔
77
        }
78
        Expression::Braces(expression) => {
1✔
79
            write!(writer, "{{")?;
1✔
80
            format_expression(expression, writer)?;
1✔
81
            write!(writer, "}}")
1✔
82
        }
NEW
83
        Expression::Let {
×
84
            name,
1✔
85
            location: _,
1✔
86
            value,
1✔
87
            body,
1✔
88
        } => {
1✔
89
            write!(writer, "let {} = ", &name.key)?;
1✔
90
            format_expression(value, writer)?;
1✔
91
            write!(writer, "\n")?;
1✔
92
            format_expression(body, writer)
1✔
93
        }
94
    }
95
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc