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

TyRoXx / NonlocalityOS / 15376299223

01 Jun 2025 02:46PM UTC coverage: 74.019% (+1.1%) from 72.943%
15376299223

Pull #276

github

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

180 of 182 new or added lines in 2 files covered. (98.9%)

3661 of 4946 relevant lines covered (74.02%)

2097.07 hits per line

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

96.23
/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
        if let Some(type_annotation) = &parameter.type_annotation {
5✔
NEW
49
            write!(writer, ": ")?;
×
50
            format_expression(type_annotation, writer)?;
1✔
51
        }
52
        write!(writer, ", ")?;
4✔
53
    }
54
    write!(writer, ") => ")?;
4✔
55
    format_expression(body, writer)
4✔
56
}
57

58
pub fn format_expression<W>(expression: &Expression, writer: &mut W) -> std::fmt::Result
33✔
59
where
60
    W: std::fmt::Write,
61
{
62
    match expression {
33✔
63
        Expression::Identifier(name, _source_location) => write!(writer, "{}", &name.key),
15✔
64
        Expression::StringLiteral(content) => format_string_literal(content, writer),
6✔
65
        Expression::Apply { callee, arguments } => format_apply(callee, arguments, writer),
3✔
66
        Expression::Lambda { parameters, body } => format_lambda(parameters, body, writer),
4✔
67
        Expression::ConstructTree(children) => {
3✔
68
            write!(writer, "[")?;
3✔
69
            for child in children.iter() {
6✔
70
                format_expression(child, writer)?;
3✔
71
                write!(writer, ", ")?;
3✔
72
            }
73
            write!(writer, "]")
3✔
74
        }
75
        Expression::Braces(expression) => {
1✔
76
            write!(writer, "{{")?;
1✔
77
            format_expression(expression, writer)?;
1✔
78
            write!(writer, "}}")
1✔
79
        }
NEW
80
        Expression::Let {
×
81
            name,
1✔
82
            location: _,
1✔
83
            value,
1✔
84
            body,
1✔
85
        } => {
1✔
86
            write!(writer, "let {} = ", &name.key)?;
1✔
87
            format_expression(value, writer)?;
1✔
88
            writeln!(writer)?;
1✔
89
            format_expression(body, writer)
1✔
90
        }
91
    }
92
}
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