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

ergoplatform / sigma-rust / 19957094785

05 Dec 2025 08:23AM UTC coverage: 86.918% (+8.5%) from 78.463%
19957094785

Pull #837

github

web-flow
Merge dec08367a into 2f840d387
Pull Request #837: Split TransactionHintsBag hints properly

44 of 53 new or added lines in 13 files covered. (83.02%)

1621 existing lines in 221 files now uncovered.

27453 of 31585 relevant lines covered (86.92%)

253204.4 hits per line

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

68.54
/ergoscript-compiler/src/ast.rs
1
use crate::error::pretty_error_desc;
2

3
use super::syntax::{SyntaxElement, SyntaxKind, SyntaxNode, SyntaxToken};
4
use text_size::TextRange;
5

6
#[derive(Debug, PartialEq, Eq)]
7
pub struct AstError {
8
    pub msg: String,
9
    pub span: TextRange,
10
}
11

12
impl AstError {
13
    pub fn new(msg: String, span: TextRange) -> Self {
×
UNCOV
14
        AstError { msg, span }
×
UNCOV
15
    }
×
16

17
    pub fn pretty_desc(&self, source: &str) -> String {
×
18
        pretty_error_desc(source, self.span, &self.msg)
×
UNCOV
19
    }
×
20
}
21

22
#[derive(Debug)]
23
pub struct Root(SyntaxNode);
24

25
impl Root {
26
    pub fn cast(node: SyntaxNode) -> Option<Self> {
10✔
27
        if node.kind() == SyntaxKind::Root {
10✔
28
            Some(Self(node))
10✔
29
        } else {
30
            None
×
31
        }
32
    }
10✔
33

34
    pub fn children(&self) -> impl Iterator<Item = Expr> {
10✔
35
        self.0.children().filter_map(Expr::cast)
10✔
36
    }
10✔
37

38
    pub fn span(&self) -> TextRange {
×
39
        self.0.text_range()
×
UNCOV
40
    }
×
41
}
42

43
#[derive(Debug)]
44
pub struct Ident(SyntaxNode);
45

46
impl Ident {
47
    pub fn name(&self) -> Result<SyntaxToken, AstError> {
7✔
48
        self.0
7✔
49
            .children_with_tokens()
7✔
50
            .filter_map(SyntaxElement::into_token)
7✔
51
            .find(|token| token.kind() == SyntaxKind::Ident)
7✔
52
            .ok_or_else(|| AstError::new(format!("Empty Ident.name in: {:?}", self.0), self.span()))
7✔
53
    }
7✔
54

55
    pub fn span(&self) -> TextRange {
7✔
56
        self.0.text_range()
7✔
57
    }
7✔
58
}
59

60
#[allow(clippy::enum_variant_names)]
61
#[derive(Debug)]
62
pub enum Expr {
63
    Ident(Ident),
64
    BinaryExpr(BinaryExpr),
65
    Literal(Literal),
66
    // ParenExpr(ParenExpr),
67
    // UnaryExpr(UnaryExpr),
68
}
69

70
impl Expr {
71
    pub fn cast(node: SyntaxNode) -> Option<Self> {
22✔
72
        let result = match node.kind() {
22✔
73
            SyntaxKind::Ident => Self::Ident(Ident(node)),
9✔
74
            SyntaxKind::InfixExpr => Self::BinaryExpr(BinaryExpr(node)),
4✔
75
            SyntaxKind::IntNumber => Self::Literal(Literal(node)),
4✔
76
            SyntaxKind::LongNumber => Self::Literal(Literal(node)),
5✔
77
            // SyntaxKind::ParenExpr => Self::ParenExpr(ParenExpr(node)),
78
            // SyntaxKind::PrefixExpr => Self::UnaryExpr(UnaryExpr(node)),
79
            _ => return None,
×
80
        };
81

82
        Some(result)
22✔
83
    }
22✔
84

85
    // pub fn span(&self) -> TextRange {
86
    //     match self {
87
    //         Expr::Ident(node) => node.0.text_range(),
88
    //         _ => todo!(),
89
    //     }
90
    // }
91
}
92

93
#[derive(Debug)]
94
pub struct BinaryExpr(SyntaxNode);
95

96
impl BinaryExpr {
97
    pub fn lhs(&self) -> Result<Expr, AstError> {
4✔
98
        self.0.children().find_map(Expr::cast).ok_or_else(|| {
4✔
99
            AstError::new(
×
100
                format!("Cannot find lhs in {:?}", self.0.children()),
×
101
                self.0.text_range(),
×
102
            )
UNCOV
103
        })
×
104
    }
4✔
105

106
    pub fn rhs(&self) -> Result<Expr, AstError> {
4✔
107
        self.0
4✔
108
            .children()
4✔
109
            .filter_map(Expr::cast)
4✔
110
            .nth(1)
4✔
111
            .ok_or_else(|| {
4✔
112
                AstError::new(
×
113
                    format!("Cannot find rhs in {:?}", self.0.children()),
×
114
                    self.0.text_range(),
×
115
                )
UNCOV
116
            })
×
117
    }
4✔
118

119
    pub fn op(&self) -> Result<SyntaxToken, AstError> {
4✔
120
        self.0
4✔
121
            .children_with_tokens()
4✔
122
            .filter_map(SyntaxElement::into_token)
4✔
123
            .find(|token| {
4✔
UNCOV
124
                matches!(
×
125
                    token.kind(),
4✔
126
                    SyntaxKind::Plus
127
                        | SyntaxKind::Minus
128
                        | SyntaxKind::Star
129
                        | SyntaxKind::Slash
130
                        | SyntaxKind::And,
131
                )
132
            })
4✔
133
            .ok_or_else(|| {
4✔
134
                AstError::new(
×
135
                    format!("Cannot find bin op in {:?}", self.0),
×
136
                    self.0.text_range(),
×
137
                )
UNCOV
138
            })
×
139
    }
4✔
140

141
    pub fn span(&self) -> TextRange {
4✔
142
        self.0.text_range()
4✔
143
    }
4✔
144
}
145

146
#[derive(Debug)]
147
pub enum LiteralValue {
148
    Int(i32),
149
    Long(i64),
150
}
151

152
#[derive(Debug)]
153
pub struct Literal(SyntaxNode);
154

155
impl Literal {
156
    pub fn parse(&self) -> Result<LiteralValue, AstError> {
7✔
157
        let text = self.0.first_token().unwrap().text().to_string();
7✔
158
        if text.ends_with('L') {
7✔
159
            text.strip_suffix('L')
4✔
160
                .unwrap()
4✔
161
                .parse()
4✔
162
                .ok()
4✔
163
                .map(LiteralValue::Long)
4✔
164
        } else {
165
            text.parse().ok().map(LiteralValue::Int)
3✔
166
        }
167
        .ok_or_else(|| {
7✔
168
            AstError::new(
×
169
                format!("Failed to parse Literal from: {:?}", self.0),
×
170
                self.span(),
×
171
            )
UNCOV
172
        })
×
173
    }
7✔
174

175
    pub fn span(&self) -> TextRange {
7✔
176
        self.0.text_range()
7✔
177
    }
7✔
178
}
179

180
// #[derive(Debug)]
181
// pub struct ParenExpr(SyntaxNode);
182

183
// impl ParenExpr {
184
//     pub fn expr(&self) -> Option<Expr> {
185
//         self.0.children().find_map(Expr::cast)
186
//     }
187
// }
188

189
// #[derive(Debug)]
190
// pub struct UnaryExpr(SyntaxNode);
191

192
// impl UnaryExpr {
193
//     pub fn expr(&self) -> Option<Expr> {
194
//         self.0.children().find_map(Expr::cast)
195
//     }
196

197
//     pub fn op(&self) -> Option<SyntaxToken> {
198
//         self.0
199
//             .children_with_tokens()
200
//             .filter_map(SyntaxElement::into_token)
201
//             .find(|token| token.kind() == SyntaxKind::Minus)
202
//     }
203
// }
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

© 2025 Coveralls, Inc