Repository: ergoplatform/sigma-rust (language: rust)

Issue:
Add numeric literals support in the compiler



Discussion / hints:

Fix patch:
diff --git a/ergoscript-compiler/src/ast.rs b/ergoscript-compiler/src/ast.rs
index 49d0c0d24..923b2e707 100644
--- a/ergoscript-compiler/src/ast.rs
+++ b/ergoscript-compiler/src/ast.rs
@@ -75,7 +75,7 @@ impl Ident {
 pub enum Expr {
     Ident(Ident),
     BinaryExpr(BinaryExpr),
-    // Literal(Literal),
+    Literal(Literal),
     // ParenExpr(ParenExpr),
     // UnaryExpr(UnaryExpr),
 }
@@ -85,7 +85,8 @@ impl Expr {
         let result = match node.kind() {
             SyntaxKind::Ident => Self::Ident(Ident(node)),
             SyntaxKind::InfixExpr => Self::BinaryExpr(BinaryExpr(node)),
-            // SyntaxKind::Literal => Self::Literal(Literal(node)),
+            SyntaxKind::IntNumber => Self::Literal(Literal(node)),
+            SyntaxKind::LongNumber => Self::Literal(Literal(node)),
             // SyntaxKind::ParenExpr => Self::ParenExpr(ParenExpr(node)),
             // SyntaxKind::PrefixExpr => Self::UnaryExpr(UnaryExpr(node)),
             _ => return None,
@@ -135,22 +136,41 @@ impl BinaryExpr {
     }
 }
 
-// #[derive(Debug)]
-// pub struct Literal(SyntaxNode);
+#[derive(Debug)]
+pub enum LiteralValue {
+    Int(i32),
+    Long(i64),
+}
 
-// impl Literal {
-//     pub fn cast(node: SyntaxNode) -> Option<Self> {
-//         if node.kind() == SyntaxKind::Literal {
-//             Some(Self(node))
-//         } else {
-//             None
-//         }
-//     }
+#[derive(Debug)]
+pub struct Literal(SyntaxNode);
+
+impl Literal {
+    // pub fn cast(node: SyntaxNode) -> Option<Self> {
+    //     if node.kind() == SyntaxKind::Literal {
+    //         Some(Self(node))
+    //     } else {
+    //         None
+    //     }
+    // }
 
-//     pub fn parse(&self) -> Option<u64> {
-//         self.0.first_token().unwrap().text().parse().ok()
-//     }
-// }
+    pub fn parse(&self) -> Option<LiteralValue> {
+        let text = self.0.first_token().unwrap().text().to_string();
+        if text.ends_with('L') {
+            text.strip_suffix("L")
+                .unwrap()
+                .parse()
+                .ok()
+                .map(LiteralValue::Long)
+        } else {
+            text.parse().ok().map(LiteralValue::Int)
+        }
+    }
+
+    pub fn span(&self) -> TextRange {
+        self.0.text_range()
+    }
+}
 
 // #[derive(Debug)]
 // pub struct ParenExpr(SyntaxNode);
diff --git a/ergoscript-compiler/src/compiler.rs b/ergoscript-compiler/src/compiler.rs
index ee0661561..86e8bfac3 100644
--- a/ergoscript-compiler/src/compiler.rs
+++ b/ergoscript-compiler/src/compiler.rs
@@ -55,15 +55,7 @@ pub fn compile_expr(
     source: &str,
     env: ScriptEnv,
 ) -> Result<ergotree_ir::mir::expr::Expr, CompileError> {
-    let parse = super::parser::parse(&source);
-    dbg!(parse.debug_tree());
-    if !parse.errors.is_empty() {
-        return Err(CompileError::ParseError(parse.errors));
-    }
-    let syntax = parse.syntax();
-    dbg!(&syntax);
-    let root = ast::Root::cast(syntax).unwrap();
-    let hir = hir::lower(root)?;
+    let hir = compile_hir(source)?;
     dbg!(&hir);
     let binder = Binder::new(env);
     let bind = binder.bind(hir)?;
@@ -80,9 +72,22 @@ pub fn compile(source: &str, env: ScriptEnv) -> Result<ErgoTree, CompileError> {
     Ok(expr.into())
 }
 
+pub(crate) fn compile_hir(source: &str) -> Result<hir::Expr, CompileError> {
+    let parse = super::parser::parse(&source);
+    dbg!(parse.debug_tree());
+    if !parse.errors.is_empty() {
+        return Err(CompileError::ParseError(parse.errors));
+    }
+    let syntax = parse.syntax();
+    dbg!(&syntax);
+    let root = ast::Root::cast(syntax).unwrap();
+    let hir = hir::lower(root)?;
+    Ok(hir)
+}
+
 #[cfg(test)]
 fn check(input: &str, expected_tree: expect_test::Expect) {
-    let res = compile(input, ScriptEnv::new());
+    let res = compile_expr(input, ScriptEnv::new());
 
     let expected_out = res
         .map(|tree| tree.debug_tree())
@@ -100,21 +105,9 @@ mod tests {
         check(
             "HEIGHT",
             expect![[r#"
-            ErgoTree {
-                header: ErgoTreeHeader(
-                    16,
-                ),
-                tree: Ok(
-                    ParsedTree {
-                        constants: [],
-                        root: Ok(
-                            GlobalVars(
-                                Height,
-                            ),
-                        ),
-                    },
-                ),
-            }"#]],
+                GlobalVars(
+                    Height,
+                )"#]],
         );
     }
 
@@ -123,10 +116,10 @@ mod tests {
         check(
             "HSB.HEIGHT",
             expect![[r#"
-            error: expected ‘+’, ‘-’, ‘*’, ‘/’, ‘val’, number, identifier, ‘-’ or ‘(’, but found an unrecognized token
-            line: 1
-            HSB.HEIGHT
-              ^^"#]],
+                error: expected ‘+’, ‘-’, ‘*’, ‘/’, ‘val’, number, number, identifier, ‘-’ or ‘(’, but found an unrecognized token
+                line: 1
+                HSB.HEIGHT
+                  ^^"#]],
         );
     }
 }
diff --git a/ergoscript-compiler/src/hir.rs b/ergoscript-compiler/src/hir.rs
index 835730832..cc2f82ff1 100644
--- a/ergoscript-compiler/src/hir.rs
+++ b/ergoscript-compiler/src/hir.rs
@@ -61,6 +61,27 @@ impl Expr {
                 .ok_or_else(|| {
                     HirLoweringError::new(format!("Empty Ident.name: {:?}", ast), ast.span())
                 }),
+            ast::Expr::Literal(ast) => {
+                let v = ast.parse().ok_or_else(|| {
+                    HirLoweringError::new(
+                        format!("Failed to parse Literal from: {:?}", ast),
+                        ast.span(),
+                    )
+                })?;
+                let expr = match v {
+                    ast::LiteralValue::Int(v) => Expr {
+                        kind: Literal::Int(v).into(),
+                        span: ast.span(),
+                        tpe: Some(SType::SInt),
+                    },
+                    ast::LiteralValue::Long(v) => Expr {
+                        kind: Literal::Long(v).into(),
+                        span: ast.span(),
+                        tpe: Some(SType::SLong),
+                    },
+                };
+                Ok(expr)
+            }
         }
     }
 
@@ -118,6 +139,7 @@ pub enum ExprKind {
     Ident(String),
     Binary(Binary),
     GlobalVars(GlobalVars),
+    Literal(Literal),
     // ...
     // Block
     // ValNode
@@ -153,3 +175,44 @@ impl GlobalVars {
         }
     }
 }
+
+#[derive(Debug, PartialEq, Clone)]
+pub enum Literal {
+    Int(i32),
+    Long(i64),
+}
+
+#[cfg(test)]
+mod tests {
+    use expect_test::expect;
+
+    use crate::compiler::compile_hir;
+
+    fn check(input: &str, expected_tree: expect_test::Expect) {
+        let res = compile_hir(input);
+
+        let expected_out = res
+            .map(|tree| tree.debug_tree())
+            .unwrap_or_else(|e| e.pretty_desc(input));
+        expected_tree.assert_eq(&expected_out);
+    }
+
+    #[test]
+    fn long_literal() {
+        check(
+            "42L",
+            expect![[r#"
+            Expr {
+                kind: Literal(
+                    Long(
+                        42,
+                    ),
+                ),
+                span: 0..3,
+                tpe: Some(
+                    SLong,
+                ),
+            }"#]],
+        );
+    }
+}
diff --git a/ergoscript-compiler/src/hir/rewrite.rs b/ergoscript-compiler/src/hir/rewrite.rs
index 2b6c84d03..5ebe999f3 100644
--- a/ergoscript-compiler/src/hir/rewrite.rs
+++ b/ergoscript-compiler/src/hir/rewrite.rs
@@ -10,7 +10,6 @@ use super::ExprKind;
 pub fn rewrite<E, F: Fn(&Expr) -> Result<Option<Expr>, E>>(e: Expr, f: F) -> Result<Expr, E> {
     let e = f(&e)?.unwrap_or(e);
     Ok(match &e.kind {
-        ExprKind::Ident(_) => f(&e)?.unwrap_or(e),
         ExprKind::Binary(binary) => match (f(&binary.lhs)?, f(&binary.rhs)?) {
             (None, None) => e,
             (l, r) => Expr {
@@ -23,6 +22,6 @@ pub fn rewrite<E, F: Fn(&Expr) -> Result<Option<Expr>, E>>(e: Expr, f: F) -> Res
                 ..e
             },
         },
-        ExprKind::GlobalVars(_) => f(&e)?.unwrap_or(e),
+        _ => f(&e)?.unwrap_or(e),
     })
 }
diff --git a/ergoscript-compiler/src/lexer/token_kind.rs b/ergoscript-compiler/src/lexer/token_kind.rs
index 78ebdedd9..9602e6608 100644
--- a/ergoscript-compiler/src/lexer/token_kind.rs
+++ b/ergoscript-compiler/src/lexer/token_kind.rs
@@ -18,7 +18,10 @@ pub enum TokenKind {
     Ident,
 
     #[regex("[0-9]+")]
-    Number,
+    IntNumber,
+
+    #[regex("[0-9]+L")]
+    LongNumber,
 
     #[token("+")]
     Plus,
@@ -70,7 +73,8 @@ impl fmt::Display for TokenKind {
             Self::FnKw => "‘def’",
             Self::ValKw => "‘val’",
             Self::Ident => "identifier",
-            Self::Number => "number",
+            Self::IntNumber => "number",
+            Self::LongNumber => "number",
             Self::Plus => "‘+’",
             Self::Minus => "‘-’",
             Self::Star => "‘*’",
@@ -137,7 +141,7 @@ mod tests {
 
     #[test]
     fn lex_number() {
-        check("123456", TokenKind::Number);
+        check("123456", TokenKind::IntNumber);
     }
 
     #[test]
diff --git a/ergoscript-compiler/src/lib.rs b/ergoscript-compiler/src/lib.rs
index f09d1ac08..83b69e900 100644
--- a/ergoscript-compiler/src/lib.rs
+++ b/ergoscript-compiler/src/lib.rs
@@ -6,7 +6,8 @@
 #![deny(non_camel_case_types)]
 #![deny(non_snake_case)]
 #![deny(unused_mut)]
-#![deny(dead_code)]
+// TODO: restore
+// #![deny(dead_code)]
 #![deny(unused_imports)]
 #![deny(missing_docs)]
 // Clippy exclusions
diff --git a/ergoscript-compiler/src/mir/lower.rs b/ergoscript-compiler/src/mir/lower.rs
index 1972cc503..fc1fd3edb 100644
--- a/ergoscript-compiler/src/mir/lower.rs
+++ b/ergoscript-compiler/src/mir/lower.rs
@@ -1,6 +1,7 @@
 use ergotree_ir::mir::bin_op::ArithOp;
 use ergotree_ir::mir::bin_op::BinOp;
 use ergotree_ir::mir::bin_op::BinOpKind;
+use ergotree_ir::mir::constant::Constant;
 use ergotree_ir::mir::expr::Expr;
 use ergotree_ir::mir::global_vars::GlobalVars;
 use hir::BinaryOp;
@@ -46,6 +47,13 @@ pub fn lower(hir_expr: hir::Expr) -> Result<Expr, MirLoweringError> {
             }
             .into()
         }
+        hir::ExprKind::Literal(hir) => {
+            let constant: Constant = match *hir {
+                hir::Literal::Int(v) => v.into(),
+                hir::Literal::Long(v) => v.into(),
+            };
+            constant.into()
+        }
     };
     let hir_tpe = hir_expr.tpe.clone().ok_or_else(|| {
         MirLoweringError::new(
@@ -117,4 +125,98 @@ mod tests {
             )"#]],
         )
     }
+
+    #[test]
+    fn literal_int() {
+        check(
+            "42",
+            expect![[r#"
+            Const(
+                Constant {
+                    tpe: SInt,
+                    v: Int(
+                        42,
+                    ),
+                },
+            )"#]],
+        );
+    }
+
+    #[test]
+    fn literal_long() {
+        check(
+            "42L",
+            expect![[r#"
+            Const(
+                Constant {
+                    tpe: SLong,
+                    v: Long(
+                        42,
+                    ),
+                },
+            )"#]],
+        );
+    }
+
+    #[test]
+    fn bin_numeric_int() {
+        check(
+            "4+2",
+            expect![[r#"
+            BinOp(
+                BinOp {
+                    kind: Arith(
+                        Plus,
+                    ),
+                    left: Const(
+                        Constant {
+                            tpe: SInt,
+                            v: Int(
+                                4,
+                            ),
+                        },
+                    ),
+                    right: Const(
+                        Constant {
+                            tpe: SInt,
+                            v: Int(
+                                2,
+                            ),
+                        },
+                    ),
+                },
+            )"#]],
+        );
+    }
+
+    #[test]
+    fn bin_numeric_long() {
+        check(
+            "4L+2L",
+            expect![[r#"
+            BinOp(
+                BinOp {
+                    kind: Arith(
+                        Plus,
+                    ),
+                    left: Const(
+                        Constant {
+                            tpe: SLong,
+                            v: Long(
+                                4,
+                            ),
+                        },
+                    ),
+                    right: Const(
+                        Constant {
+                            tpe: SLong,
+                            v: Long(
+                                2,
+                            ),
+                        },
+                    ),
+                },
+            )"#]],
+        );
+    }
 }
diff --git a/ergoscript-compiler/src/parser.rs b/ergoscript-compiler/src/parser.rs
index bff88cf4c..6df4f8089 100644
--- a/ergoscript-compiler/src/parser.rs
+++ b/ergoscript-compiler/src/parser.rs
@@ -142,4 +142,26 @@ mod tests {
               Comment@0..9 "// hello!""#]],
         );
     }
+
+    #[test]
+    fn parse_int_literal() {
+        check(
+            "42",
+            expect![[r#"
+                Root@0..2
+                  IntNumber@0..2
+                    IntNumber@0..2 "42""#]],
+        );
+    }
+
+    #[test]
+    fn parse_long_literal() {
+        check(
+            "42L",
+            expect![[r#"
+                Root@0..3
+                  LongNumber@0..3
+                    LongNumber@0..3 "42L""#]],
+        );
+    }
 }
diff --git a/ergoscript-compiler/src/parser/grammar/expr.rs b/ergoscript-compiler/src/parser/grammar/expr.rs
index b965b1da2..fd8ee52c5 100644
--- a/ergoscript-compiler/src/parser/grammar/expr.rs
+++ b/ergoscript-compiler/src/parser/grammar/expr.rs
@@ -104,8 +104,10 @@ fn expr_binding_power(p: &mut Parser, minimum_binding_power: u8) -> Option<Compl
 }
 
 fn lhs(p: &mut Parser) -> Option<CompletedMarker> {
-    let cm = if p.at(TokenKind::Number) {
-        literal(p)
+    let cm = if p.at(TokenKind::IntNumber) {
+        int_number(p)
+    } else if p.at(TokenKind::LongNumber) {
+        long_number(p)
     } else if p.at(TokenKind::Ident) {
         ident(p)
         // variable_ref(p)
@@ -151,12 +153,18 @@ impl UnaryOp {
     }
 }
 
-fn literal(p: &mut Parser) -> CompletedMarker {
-    assert!(p.at(TokenKind::Number));
+fn int_number(p: &mut Parser) -> CompletedMarker {
+    assert!(p.at(TokenKind::IntNumber));
+    let m = p.start();
+    p.bump();
+    m.complete(p, SyntaxKind::IntNumber)
+}
 
+fn long_number(p: &mut Parser) -> CompletedMarker {
+    assert!(p.at(TokenKind::LongNumber));
     let m = p.start();
     p.bump();
-    m.complete(p, SyntaxKind::Literal)
+    m.complete(p, SyntaxKind::LongNumber)
 }
 
 // fn variable_ref(p: &mut Parser) -> CompletedMarker {
@@ -212,9 +220,9 @@ mod tests {
         check(
             "123",
             expect![[r#"
-Root@0..3
-  Literal@0..3
-    Number@0..3 "123""#]],
+                Root@0..3
+                  IntNumber@0..3
+                    IntNumber@0..3 "123""#]],
         );
     }
 
@@ -225,8 +233,8 @@ Root@0..3
             expect![[r#"
                 Root@0..6
                   Whitespace@0..2 "  "
-                  Literal@2..6
-                    Number@2..6 "9876""#]],
+                  IntNumber@2..6
+                    IntNumber@2..6 "9876""#]],
         );
     }
 
@@ -236,8 +244,8 @@ Root@0..3
             "999  ",
             expect![[r#"
                 Root@0..5
-                  Literal@0..5
-                    Number@0..3 "999"
+                  IntNumber@0..5
+                    IntNumber@0..3 "999"
                     Whitespace@3..5 "  ""#]],
         );
     }
@@ -249,8 +257,8 @@ Root@0..3
             expect![[r#"
                 Root@0..8
                   Whitespace@0..1 " "
-                  Literal@1..8
-                    Number@1..4 "123"
+                  IntNumber@1..8
+                    IntNumber@1..4 "123"
                     Whitespace@4..8 "    ""#]],
         );
     }
@@ -262,11 +270,11 @@ Root@0..3
             expect![[r#"
                 Root@0..3
                   InfixExpr@0..3
-                    Literal@0..1
-                      Number@0..1 "1"
+                    IntNumber@0..1
+                      IntNumber@0..1 "1"
                     Plus@1..2 "+"
-                    Literal@2..3
-                      Number@2..3 "3""#]],
+                    IntNumber@2..3
+                      IntNumber@2..3 "3""#]],
         );
     }
 
@@ -278,14 +286,14 @@ Root@0..3
                 Root@0..5
                   InfixExpr@0..5
                     InfixExpr@0..3
-                      Literal@0..1
-                        Number@0..1 "1"
+                      IntNumber@0..1
+                        IntNumber@0..1 "1"
                       Plus@1..2 "+"
-                      Literal@2..3
-                        Number@2..3 "2"
+                      IntNumber@2..3
+                        IntNumber@2..3 "2"
                     Plus@3..4 "+"
-                    Literal@4..5
-                      Number@4..5 "3""#]],
+                    IntNumber@4..5
+                      IntNumber@4..5 "3""#]],
         );
     }
 
@@ -297,18 +305,18 @@ Root@0..3
                 Root@0..7
                   InfixExpr@0..7
                     InfixExpr@0..5
-                      Literal@0..1
-                        Number@0..1 "1"
+                      IntNumber@0..1
+                        IntNumber@0..1 "1"
                       Plus@1..2 "+"
                       InfixExpr@2..5
-                        Literal@2..3
-                          Number@2..3 "2"
+                        IntNumber@2..3
+                          IntNumber@2..3 "2"
                         Star@3..4 "*"
-                        Literal@4..5
-                          Number@4..5 "3"
+                        IntNumber@4..5
+                          IntNumber@4..5 "3"
                     Minus@5..6 "-"
-                    Literal@6..7
-                      Number@6..7 "5""#]],
+                    IntNumber@6..7
+                      IntNumber@6..7 "5""#]],
         );
     }
 
@@ -320,18 +328,18 @@ Root@0..3
                 Root@0..11
                   Whitespace@0..1 " "
                   InfixExpr@1..11
-                    Literal@1..3
-                      Number@1..2 "1"
+                    IntNumber@1..3
+                      IntNumber@1..2 "1"
                       Whitespace@2..3 " "
                     Plus@3..4 "+"
                     Whitespace@4..6 "  "
                     InfixExpr@6..11
-                      Literal@6..7
-                        Number@6..7 "2"
+                      IntNumber@6..7
+                        IntNumber@6..7 "2"
                       Star@7..8 "*"
                       Whitespace@8..9 " "
-                      Literal@9..11
-                        Number@9..10 "3"
+                      IntNumber@9..11
+                        IntNumber@9..10 "3"
                         Whitespace@10..11 " ""#]],
         );
     }
@@ -348,20 +356,20 @@ Root@0..3
                   Whitespace@0..1 "\n"
                   InfixExpr@1..37
                     InfixExpr@1..22
-                      Literal@1..5
-                        Number@1..2 "1"
+                      IntNumber@1..5
+                        IntNumber@1..2 "1"
                         Whitespace@2..5 "\n  "
                       Plus@5..6 "+"
                       Whitespace@6..7 " "
-                      Literal@7..22
-                        Number@7..8 "1"
+                      IntNumber@7..22
+                        IntNumber@7..8 "1"
                         Whitespace@8..9 " "
                         Comment@9..19 "// Add one"
                         Whitespace@19..22 "\n  "
                     Plus@22..23 "+"
                     Whitespace@23..24 " "
-                    Literal@24..37
-                      Number@24..26 "10"
+                    IntNumber@24..37
+                      IntNumber@24..26 "10"
                       Whitespace@26..27 " "
                       Comment@27..37 "// Add ten""#]],
         );
@@ -372,15 +380,15 @@ Root@0..3
         check(
             "(2+",
             expect![[r#"
-            Root@0..3
-              ParenExpr@0..3
-                LParen@0..1 "("
-                InfixExpr@1..3
-                  Literal@1..2
-                    Number@1..2 "2"
-                  Plus@2..3 "+"
-            error: expected number, identifier, ‘-’ or ‘(’
-            error: expected ‘)’"#]],
+                Root@0..3
+                  ParenExpr@0..3
+                    LParen@0..1 "("
+                    InfixExpr@1..3
+                      IntNumber@1..2
+                        IntNumber@1..2 "2"
+                      Plus@2..3 "+"
+                error: expected number, number, identifier, ‘-’ or ‘(’
+                error: expected ‘)’"#]],
         );
     }
 
@@ -392,8 +400,8 @@ Root@0..3
                 Root@0..3
                   PrefixExpr@0..3
                     Minus@0..1 "-"
-                    Literal@1..3
-                      Number@1..3 "11""#]],
+                    IntNumber@1..3
+                      IntNumber@1..3 "11""#]],
         );
     }
 
@@ -406,11 +414,11 @@ Root@0..3
                   InfixExpr@0..6
                     PrefixExpr@0..3
                       Minus@0..1 "-"
-                      Literal@1..3
-                        Number@1..3 "20"
+                      IntNumber@1..3
+                        IntNumber@1..3 "20"
                     Plus@3..4 "+"
-                    Literal@4..6
-                      Number@4..6 "21""#]],
+                    IntNumber@4..6
+                      IntNumber@4..6 "21""#]],
         );
     }
 
@@ -432,8 +440,8 @@ Root@0..3
                             LParen@4..5 "("
                             ParenExpr@5..9
                               LParen@5..6 "("
-                              Literal@6..8
-                                Number@6..8 "11"
+                              IntNumber@6..8
+                                IntNumber@6..8 "11"
                               RParen@8..9 ")"
                             RParen@9..10 ")"
                           RParen@10..11 ")"
@@ -450,17 +458,17 @@ Root@0..3
             expect![[r#"
                 Root@0..7
                   InfixExpr@0..7
-                    Literal@0..1
-                      Number@0..1 "5"
+                    IntNumber@0..1
+                      IntNumber@0..1 "5"
                     Star@1..2 "*"
                     ParenExpr@2..7
                       LParen@2..3 "("
                       InfixExpr@3..6
-                        Literal@3..4
-                          Number@3..4 "2"
+                        IntNumber@3..4
+                          IntNumber@3..4 "2"
                         Plus@4..5 "+"
-                        Literal@5..6
-                          Number@5..6 "3"
+                        IntNumber@5..6
+                          IntNumber@5..6 "3"
                       RParen@6..7 ")""#]],
         );
     }
diff --git a/ergoscript-compiler/src/parser/parse_error.rs b/ergoscript-compiler/src/parser/parse_error.rs
index 80a4d8efd..6295a39ff 100644
--- a/ergoscript-compiler/src/parser/parse_error.rs
+++ b/ergoscript-compiler/src/parser/parse_error.rs
@@ -96,7 +96,7 @@ mod tests {
     fn multiple_expected_did_find() {
         check(
             vec![
-                TokenKind::Number,
+                TokenKind::IntNumber,
                 TokenKind::Ident,
                 TokenKind::Minus,
                 TokenKind::LParen,
diff --git a/ergoscript-compiler/src/syntax.rs b/ergoscript-compiler/src/syntax.rs
index 4ca646e00..cd93308be 100644
--- a/ergoscript-compiler/src/syntax.rs
+++ b/ergoscript-compiler/src/syntax.rs
@@ -10,7 +10,8 @@ pub enum SyntaxKind {
     FnKw,
     ValKw,
     Ident,
-    Number,
+    IntNumber,
+    LongNumber,
     Plus,
     Minus,
     Star,
@@ -25,7 +26,6 @@ pub enum SyntaxKind {
     Error,
     Root,
     InfixExpr,
-    Literal,
     ParenExpr,
     PrefixExpr,
     VariableDef,
@@ -38,7 +38,8 @@ impl From<TokenKind> for SyntaxKind {
             TokenKind::FnKw => Self::FnKw,
             TokenKind::ValKw => Self::ValKw,
             TokenKind::Ident => Self::Ident,
-            TokenKind::Number => Self::Number,
+            TokenKind::IntNumber => Self::IntNumber,
+            TokenKind::LongNumber => Self::LongNumber,
             TokenKind::Plus => Self::Plus,
             TokenKind::Minus => Self::Minus,
             TokenKind::Star => Self::Star,


Test patch: