leo_input/types/
signed_integer_type.rs

1// Copyright (C) 2019-2021 Aleo Systems Inc.
2// This file is part of the Leo library.
3
4// The Leo library is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// The Leo library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
16
17use crate::ast::Rule;
18
19use pest_ast::FromPest;
20use std::fmt;
21
22#[derive(Clone, Debug, FromPest, PartialEq, Eq)]
23#[pest_ast(rule(Rule::type_integer_signed))]
24pub enum SignedIntegerType {
25    I8Type(I8Type),
26    I16Type(I16Type),
27    I32Type(I32Type),
28    I64Type(I64Type),
29    I128Type(I128Type),
30}
31
32#[derive(Clone, Debug, FromPest, PartialEq, Eq)]
33#[pest_ast(rule(Rule::type_i8))]
34pub struct I8Type {}
35
36#[derive(Clone, Debug, FromPest, PartialEq, Eq)]
37#[pest_ast(rule(Rule::type_i16))]
38pub struct I16Type {}
39
40#[derive(Clone, Debug, FromPest, PartialEq, Eq)]
41#[pest_ast(rule(Rule::type_i32))]
42pub struct I32Type {}
43
44#[derive(Clone, Debug, FromPest, PartialEq, Eq)]
45#[pest_ast(rule(Rule::type_i64))]
46pub struct I64Type {}
47
48#[derive(Clone, Debug, FromPest, PartialEq, Eq)]
49#[pest_ast(rule(Rule::type_i128))]
50pub struct I128Type {}
51
52impl fmt::Display for SignedIntegerType {
53    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
54        match self {
55            SignedIntegerType::I8Type(_) => write!(f, "i8"),
56            SignedIntegerType::I16Type(_) => write!(f, "i16"),
57            SignedIntegerType::I32Type(_) => write!(f, "i32"),
58            SignedIntegerType::I64Type(_) => write!(f, "i64"),
59            SignedIntegerType::I128Type(_) => write!(f, "i128"),
60        }
61    }
62}