aiken_lang/parser/expr/
int.rs1use chumsky::prelude::*;
2
3use crate::{
4 expr::UntypedExpr,
5 parser::{error::ParseError, literal::uint, token::Token},
6};
7
8pub fn parser() -> impl Parser<Token, UntypedExpr, Error = ParseError> {
9 uint().map_with_span(|(value, base), span| UntypedExpr::UInt {
10 location: span,
11 value,
12 base,
13 })
14}
15
16#[cfg(test)]
17mod tests {
18 use crate::assert_expr;
19
20 #[test]
21 fn int_literal() {
22 assert_expr!("1");
23 }
24
25 #[test]
26 fn int_negative() {
27 assert_expr!("-1");
28 }
29
30 #[test]
31 fn int_numeric_underscore() {
32 assert_expr!(
33 r#"
34 {
35 let i = 1_234_567
36 let j = 1_000_000
37 let k = -10_000
38 }
39 "#
40 );
41 }
42
43 #[test]
44 fn int_hex_bytes() {
45 assert_expr!(r#"0x01"#);
46 }
47}