mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-11-13 06:43:01 +03:00
Merge pull request #176 from AleoHQ/refactor/value-number
Refactor number value primitives in pest
This commit is contained in:
commit
ee5fa6b89d
@ -118,34 +118,42 @@ operation_pow_assign = { "**=" }
|
||||
// Declared in types/type_.rs
|
||||
type_ = { type_self | type_array | type_data | type_circuit }
|
||||
|
||||
// Declared in types/integer.rs
|
||||
// Declared in types/integer_type.rs
|
||||
type_integer = {
|
||||
type_u8
|
||||
| type_u16
|
||||
| type_u32
|
||||
| type_u64
|
||||
| type_u128
|
||||
| type_i8
|
||||
| type_i16
|
||||
| type_i32
|
||||
| type_i64
|
||||
| type_i128
|
||||
type_integer_signed
|
||||
| type_integer_unsigned
|
||||
}
|
||||
|
||||
// Declared in types/integer.rs
|
||||
// Declared in types/unsigned_integer_type.rs
|
||||
type_u8 = { "u8" }
|
||||
type_u16 = { "u16" }
|
||||
type_u32 = { "u32" }
|
||||
type_u64 = { "u64" }
|
||||
type_u128 = { "u128" }
|
||||
|
||||
// Declared in types/integer.rs
|
||||
type_integer_unsigned = {
|
||||
type_u8
|
||||
| type_u16
|
||||
| type_u32
|
||||
| type_u64
|
||||
| type_u128
|
||||
}
|
||||
|
||||
// Declared in types/signed_integer_type.rs
|
||||
type_i8 = { "i8" }
|
||||
type_i16 = { "i16" }
|
||||
type_i32 = { "i32" }
|
||||
type_i64 = { "i64" }
|
||||
type_i128 = { "i128" }
|
||||
|
||||
type_integer_signed = {
|
||||
type_i8
|
||||
| type_i16
|
||||
| type_i32
|
||||
| type_i64
|
||||
| type_i128
|
||||
}
|
||||
|
||||
// Declared in types/field_type.rs
|
||||
type_field = { "field" }
|
||||
|
||||
@ -174,7 +182,7 @@ type_self = { "Self" }
|
||||
type_circuit = { identifier }
|
||||
|
||||
// Declared in types/array_type.rs
|
||||
type_array = { type_data ~ ("[" ~ positive_number ~ "]")+ }
|
||||
type_array = { type_data ~ ("[" ~ number_positive ~ "]")+ }
|
||||
|
||||
type_list = _{ (type_ ~ ("," ~ type_)*)? }
|
||||
|
||||
@ -187,37 +195,43 @@ value = {
|
||||
| value_field
|
||||
| value_group
|
||||
| value_integer
|
||||
| value_implicit // must be last as a catch all
|
||||
| value_number // must be last as a catch all
|
||||
}
|
||||
|
||||
// Declared in values/number_value.rs
|
||||
value_number = @{ (("-" ~ ASCII_NONZERO_DIGIT) | "0" | ASCII_NONZERO_DIGIT) ~ ASCII_DIGIT* }
|
||||
value_number = { number_negative | number_positive }
|
||||
|
||||
// Declared in values/number_negative.rs
|
||||
number_negative = @{ "-" ~ ASCII_DIGIT+ }
|
||||
|
||||
// Declared in values/number_positive.rs
|
||||
positive_number = @{ ("0" | ASCII_NONZERO_DIGIT) ~ ASCII_DIGIT*}
|
||||
|
||||
// Declared in values/number_implicit_value.rs
|
||||
value_implicit = { value_number }
|
||||
number_positive = @{ ASCII_DIGIT+ }
|
||||
|
||||
// Declared in values/integer_value.rs
|
||||
value_integer = { value_number ~ type_integer }
|
||||
value_integer = { value_integer_signed | value_integer_unsigned}
|
||||
|
||||
// Declared in values/signed_integer_value.rs
|
||||
value_integer_signed = ${ value_number ~ type_integer_signed }
|
||||
|
||||
// Declared in values/unsigned_integer_value.rs
|
||||
value_integer_unsigned = ${ number_positive ~ type_integer_unsigned }
|
||||
|
||||
// Declared in values/boolean_value.rs
|
||||
value_boolean = { "true" | "false" }
|
||||
|
||||
// Declared in values/field_value.rs
|
||||
value_field = { value_number ~ type_field }
|
||||
value_field = ${ value_number ~ type_field }
|
||||
|
||||
// Declared in values/group_value.rs
|
||||
value_group = { group_single_or_tuple ~ type_group }
|
||||
group_tuple = {"(" ~ value_number ~ "," ~ value_number ~ ")"}
|
||||
value_group = ${ group_single_or_tuple ~ type_group }
|
||||
group_tuple = !{"(" ~ value_number ~ "," ~ value_number ~ ")"}
|
||||
group_single_or_tuple = {value_number | group_tuple}
|
||||
|
||||
// Declared in values/address.rs
|
||||
address = @{ "aleo" ~ ASCII_DIGIT ~ (LOWERCASE_LETTER | ASCII_DIGIT){58} }
|
||||
address = @{ "aleo1" ~ (LOWERCASE_LETTER | ASCII_DIGIT){58} }
|
||||
|
||||
// Declared in values/address_value.rs
|
||||
value_address = { type_address ~ "(" ~ address ~ ")" }
|
||||
value_address = ${ type_address ~ "(" ~ address ~ ")" }
|
||||
|
||||
/// Access
|
||||
|
||||
@ -271,6 +285,7 @@ expression_term = {
|
||||
| value
|
||||
| expression_unary // must be defined below value to avoid conflicts with negative values
|
||||
| expression_postfix
|
||||
| value
|
||||
| identifier
|
||||
}
|
||||
|
||||
@ -280,7 +295,7 @@ expression_tuple = _{ (expression ~ ("," ~ expression)*)? }
|
||||
expression = { expression_term ~ (operation_binary ~ expression_term)* }
|
||||
|
||||
// Declared in expressions/array_initializer_expression.rs
|
||||
expression_array_initializer = { "[" ~ spread_or_expression ~ ";" ~ positive_number ~ "]" }
|
||||
expression_array_initializer = { "[" ~ spread_or_expression ~ ";" ~ number_positive ~ "]" }
|
||||
|
||||
// Declared in expressions/array_inline_expression.rs
|
||||
expression_array_inline = { "[" ~ NEWLINE* ~ inline_array_inner ~ NEWLINE* ~ "]"}
|
||||
|
@ -1,4 +1,7 @@
|
||||
use crate::ast::Rule;
|
||||
use crate::{
|
||||
ast::Rule,
|
||||
types::{SignedIntegerType, UnsignedIntegerType},
|
||||
};
|
||||
|
||||
use pest_ast::FromPest;
|
||||
use serde::Serialize;
|
||||
@ -6,59 +9,6 @@ use serde::Serialize;
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
|
||||
#[pest_ast(rule(Rule::type_integer))]
|
||||
pub enum IntegerType {
|
||||
U8Type(U8Type),
|
||||
U16Type(U16Type),
|
||||
U32Type(U32Type),
|
||||
U64Type(U64Type),
|
||||
U128Type(U128Type),
|
||||
|
||||
I8Type(I8Type),
|
||||
I16Type(I16Type),
|
||||
I32Type(I32Type),
|
||||
I64Type(I64Type),
|
||||
I128Type(I128Type),
|
||||
Signed(SignedIntegerType),
|
||||
Unsigned(UnsignedIntegerType),
|
||||
}
|
||||
|
||||
// Unsigned
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
|
||||
#[pest_ast(rule(Rule::type_u8))]
|
||||
pub struct U8Type {}
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
|
||||
#[pest_ast(rule(Rule::type_u16))]
|
||||
pub struct U16Type {}
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
|
||||
#[pest_ast(rule(Rule::type_u32))]
|
||||
pub struct U32Type {}
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
|
||||
#[pest_ast(rule(Rule::type_u64))]
|
||||
pub struct U64Type {}
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
|
||||
#[pest_ast(rule(Rule::type_u128))]
|
||||
pub struct U128Type {}
|
||||
|
||||
// Signed
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
|
||||
#[pest_ast(rule(Rule::type_i8))]
|
||||
pub struct I8Type {}
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
|
||||
#[pest_ast(rule(Rule::type_i16))]
|
||||
pub struct I16Type {}
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
|
||||
#[pest_ast(rule(Rule::type_i32))]
|
||||
pub struct I32Type {}
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
|
||||
#[pest_ast(rule(Rule::type_i64))]
|
||||
pub struct I64Type {}
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
|
||||
#[pest_ast(rule(Rule::type_i128))]
|
||||
pub struct I128Type {}
|
||||
|
@ -25,5 +25,11 @@ pub use integer_type::*;
|
||||
pub mod self_type;
|
||||
pub use self_type::*;
|
||||
|
||||
pub mod signed_integer_type;
|
||||
pub use signed_integer_type::*;
|
||||
|
||||
pub mod type_;
|
||||
pub use type_::*;
|
||||
|
||||
pub mod unsigned_integer_type;
|
||||
pub use unsigned_integer_type::*;
|
||||
|
47
ast/src/types/signed_integer_type.rs
Normal file
47
ast/src/types/signed_integer_type.rs
Normal file
@ -0,0 +1,47 @@
|
||||
use crate::ast::Rule;
|
||||
|
||||
use pest_ast::FromPest;
|
||||
use serde::Serialize;
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
|
||||
#[pest_ast(rule(Rule::type_integer_signed))]
|
||||
pub enum SignedIntegerType {
|
||||
I8Type(I8Type),
|
||||
I16Type(I16Type),
|
||||
I32Type(I32Type),
|
||||
I64Type(I64Type),
|
||||
I128Type(I128Type),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
|
||||
#[pest_ast(rule(Rule::type_i8))]
|
||||
pub struct I8Type {}
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
|
||||
#[pest_ast(rule(Rule::type_i16))]
|
||||
pub struct I16Type {}
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
|
||||
#[pest_ast(rule(Rule::type_i32))]
|
||||
pub struct I32Type {}
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
|
||||
#[pest_ast(rule(Rule::type_i64))]
|
||||
pub struct I64Type {}
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
|
||||
#[pest_ast(rule(Rule::type_i128))]
|
||||
pub struct I128Type {}
|
||||
|
||||
impl fmt::Display for SignedIntegerType {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
SignedIntegerType::I8Type(_) => write!(f, "i8"),
|
||||
SignedIntegerType::I16Type(_) => write!(f, "i16"),
|
||||
SignedIntegerType::I32Type(_) => write!(f, "i32"),
|
||||
SignedIntegerType::I64Type(_) => write!(f, "i64"),
|
||||
SignedIntegerType::I128Type(_) => write!(f, "i128"),
|
||||
}
|
||||
}
|
||||
}
|
47
ast/src/types/unsigned_integer_type.rs
Normal file
47
ast/src/types/unsigned_integer_type.rs
Normal file
@ -0,0 +1,47 @@
|
||||
use crate::ast::Rule;
|
||||
|
||||
use pest_ast::FromPest;
|
||||
use serde::Serialize;
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
|
||||
#[pest_ast(rule(Rule::type_integer_unsigned))]
|
||||
pub enum UnsignedIntegerType {
|
||||
U8Type(U8Type),
|
||||
U16Type(U16Type),
|
||||
U32Type(U32Type),
|
||||
U64Type(U64Type),
|
||||
U128Type(U128Type),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
|
||||
#[pest_ast(rule(Rule::type_u8))]
|
||||
pub struct U8Type {}
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
|
||||
#[pest_ast(rule(Rule::type_u16))]
|
||||
pub struct U16Type {}
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
|
||||
#[pest_ast(rule(Rule::type_u32))]
|
||||
pub struct U32Type {}
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
|
||||
#[pest_ast(rule(Rule::type_u64))]
|
||||
pub struct U64Type {}
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
|
||||
#[pest_ast(rule(Rule::type_u128))]
|
||||
pub struct U128Type {}
|
||||
|
||||
impl fmt::Display for UnsignedIntegerType {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
UnsignedIntegerType::U8Type(_) => write!(f, "u8"),
|
||||
UnsignedIntegerType::U16Type(_) => write!(f, "u16"),
|
||||
UnsignedIntegerType::U32Type(_) => write!(f, "u32"),
|
||||
UnsignedIntegerType::U64Type(_) => write!(f, "u64"),
|
||||
UnsignedIntegerType::U128Type(_) => write!(f, "u128"),
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,7 @@
|
||||
use crate::{ast::Rule, types::IntegerType, values::NumberValue, SpanDef};
|
||||
use crate::{
|
||||
ast::Rule,
|
||||
values::{SignedIntegerValue, UnsignedIntegerValue},
|
||||
};
|
||||
|
||||
use pest::Span;
|
||||
use pest_ast::FromPest;
|
||||
@ -7,16 +10,25 @@ use std::fmt;
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
|
||||
#[pest_ast(rule(Rule::value_integer))]
|
||||
pub struct IntegerValue<'ast> {
|
||||
pub number: NumberValue<'ast>,
|
||||
pub _type: IntegerType,
|
||||
#[pest_ast(outer())]
|
||||
#[serde(with = "SpanDef")]
|
||||
pub span: Span<'ast>,
|
||||
pub enum IntegerValue<'ast> {
|
||||
Signed(SignedIntegerValue<'ast>),
|
||||
Unsigned(UnsignedIntegerValue<'ast>),
|
||||
}
|
||||
|
||||
impl<'ast> IntegerValue<'ast> {
|
||||
pub fn span(&self) -> &Span<'ast> {
|
||||
match self {
|
||||
IntegerValue::Signed(integer) => &integer.span,
|
||||
IntegerValue::Unsigned(integer) => &integer.span,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast> fmt::Display for IntegerValue<'ast> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}", self.number)
|
||||
match self {
|
||||
IntegerValue::Signed(integer) => write!(f, "{}", integer),
|
||||
IntegerValue::Unsigned(integer) => write!(f, "{}", integer),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,14 +16,20 @@ pub use group_value::*;
|
||||
pub mod integer_value;
|
||||
pub use integer_value::*;
|
||||
|
||||
pub mod number_implicit_value;
|
||||
pub use number_implicit_value::*;
|
||||
|
||||
pub mod number_value;
|
||||
pub use number_value::*;
|
||||
|
||||
pub mod positive_number;
|
||||
pub use positive_number::*;
|
||||
|
||||
pub mod negative_number;
|
||||
pub use negative_number::*;
|
||||
|
||||
pub mod signed_integer_value;
|
||||
pub use signed_integer_value::*;
|
||||
|
||||
pub mod unsigned_integer_value;
|
||||
pub use unsigned_integer_value::*;
|
||||
|
||||
pub mod value;
|
||||
pub use value::*;
|
||||
|
25
ast/src/values/negative_number.rs
Normal file
25
ast/src/values/negative_number.rs
Normal file
@ -0,0 +1,25 @@
|
||||
use crate::{
|
||||
ast::{span_into_string, Rule},
|
||||
span::SpanDef,
|
||||
};
|
||||
|
||||
use pest::Span;
|
||||
use pest_ast::FromPest;
|
||||
use serde::Serialize;
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
|
||||
#[pest_ast(rule(Rule::number_negative))]
|
||||
pub struct NegativeNumber<'ast> {
|
||||
#[pest_ast(outer(with(span_into_string)))]
|
||||
pub value: String,
|
||||
#[pest_ast(outer())]
|
||||
#[serde(with = "SpanDef")]
|
||||
pub span: Span<'ast>,
|
||||
}
|
||||
|
||||
impl<'ast> fmt::Display for NegativeNumber<'ast> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}", self.value)
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
use crate::{
|
||||
ast::{span_into_string, Rule},
|
||||
span::SpanDef,
|
||||
ast::Rule,
|
||||
values::{NegativeNumber, PositiveNumber},
|
||||
};
|
||||
|
||||
use pest::Span;
|
||||
@ -10,16 +10,25 @@ use std::fmt;
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
|
||||
#[pest_ast(rule(Rule::value_number))]
|
||||
pub struct NumberValue<'ast> {
|
||||
#[pest_ast(outer(with(span_into_string)))]
|
||||
pub value: String,
|
||||
#[pest_ast(outer())]
|
||||
#[serde(with = "SpanDef")]
|
||||
pub span: Span<'ast>,
|
||||
pub enum NumberValue<'ast> {
|
||||
Negative(NegativeNumber<'ast>),
|
||||
Positive(PositiveNumber<'ast>),
|
||||
}
|
||||
|
||||
impl<'ast> NumberValue<'ast> {
|
||||
pub fn span(&self) -> &Span<'ast> {
|
||||
match self {
|
||||
NumberValue::Negative(number) => &number.span,
|
||||
NumberValue::Positive(number) => &number.span,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast> fmt::Display for NumberValue<'ast> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}", self.value)
|
||||
match self {
|
||||
NumberValue::Negative(number) => write!(f, "{}", number),
|
||||
NumberValue::Positive(number) => write!(f, "{}", number),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ use serde::Serialize;
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
|
||||
#[pest_ast(rule(Rule::positive_number))]
|
||||
#[pest_ast(rule(Rule::number_positive))]
|
||||
pub struct PositiveNumber<'ast> {
|
||||
#[pest_ast(outer(with(span_into_string)))]
|
||||
pub value: String,
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::{ast::Rule, values::NumberValue, SpanDef};
|
||||
use crate::{ast::Rule, types::SignedIntegerType, values::NumberValue, SpanDef};
|
||||
|
||||
use pest::Span;
|
||||
use pest_ast::FromPest;
|
||||
@ -6,16 +6,17 @@ use serde::Serialize;
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
|
||||
#[pest_ast(rule(Rule::value_implicit))]
|
||||
pub struct NumberImplicitValue<'ast> {
|
||||
#[pest_ast(rule(Rule::value_integer_signed))]
|
||||
pub struct SignedIntegerValue<'ast> {
|
||||
pub number: NumberValue<'ast>,
|
||||
pub type_: SignedIntegerType,
|
||||
#[pest_ast(outer())]
|
||||
#[serde(with = "SpanDef")]
|
||||
pub span: Span<'ast>,
|
||||
}
|
||||
|
||||
impl<'ast> fmt::Display for NumberImplicitValue<'ast> {
|
||||
impl<'ast> fmt::Display for SignedIntegerValue<'ast> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}", self.number)
|
||||
write!(f, "{}{}", self.number, self.type_)
|
||||
}
|
||||
}
|
22
ast/src/values/unsigned_integer_value.rs
Normal file
22
ast/src/values/unsigned_integer_value.rs
Normal file
@ -0,0 +1,22 @@
|
||||
use crate::{ast::Rule, types::UnsignedIntegerType, values::PositiveNumber, SpanDef};
|
||||
|
||||
use pest::Span;
|
||||
use pest_ast::FromPest;
|
||||
use serde::Serialize;
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
|
||||
#[pest_ast(rule(Rule::value_integer_unsigned))]
|
||||
pub struct UnsignedIntegerValue<'ast> {
|
||||
pub number: PositiveNumber<'ast>,
|
||||
pub type_: UnsignedIntegerType,
|
||||
#[pest_ast(outer())]
|
||||
#[serde(with = "SpanDef")]
|
||||
pub span: Span<'ast>,
|
||||
}
|
||||
|
||||
impl<'ast> fmt::Display for UnsignedIntegerValue<'ast> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}{}", self.number, self.type_)
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
use crate::{
|
||||
ast::Rule,
|
||||
values::{AddressValue, BooleanValue, FieldValue, GroupValue, IntegerValue, NumberImplicitValue},
|
||||
values::{AddressValue, BooleanValue, FieldValue, GroupValue, IntegerValue, NumberValue},
|
||||
};
|
||||
|
||||
use pest::Span;
|
||||
@ -15,7 +15,7 @@ pub enum Value<'ast> {
|
||||
Boolean(BooleanValue<'ast>),
|
||||
Field(FieldValue<'ast>),
|
||||
Group(GroupValue<'ast>),
|
||||
Implicit(NumberImplicitValue<'ast>),
|
||||
Implicit(NumberValue<'ast>),
|
||||
Integer(IntegerValue<'ast>),
|
||||
}
|
||||
|
||||
@ -26,8 +26,8 @@ impl<'ast> Value<'ast> {
|
||||
Value::Boolean(value) => &value.span,
|
||||
Value::Field(value) => &value.span,
|
||||
Value::Group(value) => &value.span,
|
||||
Value::Implicit(value) => &value.span,
|
||||
Value::Integer(value) => &value.span,
|
||||
Value::Implicit(value) => &value.span(),
|
||||
Value::Integer(value) => &value.span(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,18 +23,13 @@
|
||||
"left": {
|
||||
"Value": {
|
||||
"Implicit": {
|
||||
"number": {
|
||||
"Positive": {
|
||||
"value": "1",
|
||||
"span": {
|
||||
"input": "1",
|
||||
"start": 29,
|
||||
"end": 30
|
||||
}
|
||||
},
|
||||
"span": {
|
||||
"input": "1",
|
||||
"start": 29,
|
||||
"end": 30
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -42,18 +37,13 @@
|
||||
"right": {
|
||||
"Value": {
|
||||
"Implicit": {
|
||||
"number": {
|
||||
"Positive": {
|
||||
"value": "1",
|
||||
"span": {
|
||||
"input": "1",
|
||||
"start": 33,
|
||||
"end": 34
|
||||
}
|
||||
},
|
||||
"span": {
|
||||
"input": "1",
|
||||
"start": 33,
|
||||
"end": 34
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,2 +1,2 @@
|
||||
[main]
|
||||
a: u8[3] = [1u8, 1u8, 1u8];
|
||||
a: u8[3] = [1, 1, 1];
|
@ -5,103 +5,108 @@ use crate::{
|
||||
integers::{expect_computation_error, expect_parsing_error, IntegerTester},
|
||||
parse_program,
|
||||
};
|
||||
use leo_input::types::{I128Type, IntegerType};
|
||||
use leo_input::types::{I128Type, IntegerType, SignedIntegerType};
|
||||
use leo_typed::InputValue;
|
||||
|
||||
test_int!(Testi128, i128, IntegerType::I128Type(I128Type {}), Int128);
|
||||
test_int!(
|
||||
TestI128,
|
||||
i128,
|
||||
IntegerType::Signed(SignedIntegerType::I128Type(I128Type {})),
|
||||
Int128
|
||||
);
|
||||
|
||||
#[test]
|
||||
fn test_i128_min() {
|
||||
Testi128::test_min();
|
||||
TestI128::test_min();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i128_min_fail() {
|
||||
Testi128::test_min_fail();
|
||||
TestI128::test_min_fail();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i128_max() {
|
||||
Testi128::test_max();
|
||||
TestI128::test_max();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i128_max_fail() {
|
||||
Testi128::test_max_fail();
|
||||
TestI128::test_max_fail();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i128_neg() {
|
||||
Testi128::test_negate();
|
||||
TestI128::test_negate();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i128_neg_max_fail() {
|
||||
Testi128::test_negate_min_fail();
|
||||
TestI128::test_negate_min_fail();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i128_neg_zero() {
|
||||
Testi128::test_negate_zero();
|
||||
TestI128::test_negate_zero();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i128_add() {
|
||||
Testi128::test_add();
|
||||
TestI128::test_add();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i128_sub() {
|
||||
Testi128::test_sub();
|
||||
TestI128::test_sub();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i128_mul() {
|
||||
Testi128::test_mul();
|
||||
TestI128::test_mul();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore] // takes several minutes
|
||||
fn test_i128_div() {
|
||||
Testi128::test_div();
|
||||
TestI128::test_div();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i128_pow() {
|
||||
Testi128::test_pow();
|
||||
TestI128::test_pow();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i128_eq() {
|
||||
Testi128::test_eq();
|
||||
TestI128::test_eq();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i128_ge() {
|
||||
Testi128::test_ge();
|
||||
TestI128::test_ge();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i128_gt() {
|
||||
Testi128::test_gt();
|
||||
TestI128::test_gt();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i128_le() {
|
||||
Testi128::test_le();
|
||||
TestI128::test_le();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i128_lt() {
|
||||
Testi128::test_lt();
|
||||
TestI128::test_lt();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i128_assert_eq() {
|
||||
Testi128::test_assert_eq();
|
||||
TestI128::test_assert_eq();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i128_ternary() {
|
||||
Testi128::test_ternary();
|
||||
TestI128::test_ternary();
|
||||
}
|
||||
|
@ -5,102 +5,107 @@ use crate::{
|
||||
integers::{expect_computation_error, expect_parsing_error, IntegerTester},
|
||||
parse_program,
|
||||
};
|
||||
use leo_input::types::{I16Type, IntegerType};
|
||||
use leo_input::types::{I16Type, IntegerType, SignedIntegerType};
|
||||
use leo_typed::InputValue;
|
||||
|
||||
test_int!(Testi16, i16, IntegerType::I16Type(I16Type {}), Int16);
|
||||
test_int!(
|
||||
TestI16,
|
||||
i16,
|
||||
IntegerType::Signed(SignedIntegerType::I16Type(I16Type {})),
|
||||
Int16
|
||||
);
|
||||
|
||||
#[test]
|
||||
fn test_i16_min() {
|
||||
Testi16::test_min();
|
||||
TestI16::test_min();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i16_min_fail() {
|
||||
Testi16::test_min_fail();
|
||||
TestI16::test_min_fail();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i16_max() {
|
||||
Testi16::test_max();
|
||||
TestI16::test_max();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i16_max_fail() {
|
||||
Testi16::test_max_fail();
|
||||
TestI16::test_max_fail();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i16_neg() {
|
||||
Testi16::test_negate();
|
||||
TestI16::test_negate();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i16_neg_max_fail() {
|
||||
Testi16::test_negate_min_fail();
|
||||
TestI16::test_negate_min_fail();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i16_neg_zero() {
|
||||
Testi16::test_negate_zero();
|
||||
TestI16::test_negate_zero();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i16_add() {
|
||||
Testi16::test_add();
|
||||
TestI16::test_add();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i16_sub() {
|
||||
Testi16::test_sub();
|
||||
TestI16::test_sub();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i16_mul() {
|
||||
Testi16::test_mul();
|
||||
TestI16::test_mul();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i16_div() {
|
||||
Testi16::test_div();
|
||||
TestI16::test_div();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i16_pow() {
|
||||
Testi16::test_pow();
|
||||
TestI16::test_pow();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i16_eq() {
|
||||
Testi16::test_eq();
|
||||
TestI16::test_eq();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i16_ge() {
|
||||
Testi16::test_ge();
|
||||
TestI16::test_ge();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i16_gt() {
|
||||
Testi16::test_gt();
|
||||
TestI16::test_gt();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i16_le() {
|
||||
Testi16::test_le();
|
||||
TestI16::test_le();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i16_lt() {
|
||||
Testi16::test_lt();
|
||||
TestI16::test_lt();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i16_assert_eq() {
|
||||
Testi16::test_assert_eq();
|
||||
TestI16::test_assert_eq();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i16_ternary() {
|
||||
Testi16::test_ternary();
|
||||
TestI16::test_ternary();
|
||||
}
|
||||
|
@ -5,102 +5,107 @@ use crate::{
|
||||
integers::{expect_computation_error, expect_parsing_error, IntegerTester},
|
||||
parse_program,
|
||||
};
|
||||
use leo_input::types::{I32Type, IntegerType};
|
||||
use leo_input::types::{I32Type, IntegerType, SignedIntegerType};
|
||||
use leo_typed::InputValue;
|
||||
|
||||
test_int!(Testi32, i32, IntegerType::I32Type(I32Type {}), Int32);
|
||||
test_int!(
|
||||
TestI32,
|
||||
i32,
|
||||
IntegerType::Signed(SignedIntegerType::I32Type(I32Type {})),
|
||||
Int32
|
||||
);
|
||||
|
||||
#[test]
|
||||
fn test_i32_min() {
|
||||
Testi32::test_min();
|
||||
TestI32::test_min();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i32_min_fail() {
|
||||
Testi32::test_min_fail();
|
||||
TestI32::test_min_fail();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i32_max() {
|
||||
Testi32::test_max();
|
||||
TestI32::test_max();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i32_max_fail() {
|
||||
Testi32::test_max_fail();
|
||||
TestI32::test_max_fail();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i32_neg() {
|
||||
Testi32::test_negate();
|
||||
TestI32::test_negate();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i32_neg_max_fail() {
|
||||
Testi32::test_negate_min_fail();
|
||||
TestI32::test_negate_min_fail();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i32_neg_zero() {
|
||||
Testi32::test_negate_zero();
|
||||
TestI32::test_negate_zero();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i32_add() {
|
||||
Testi32::test_add();
|
||||
TestI32::test_add();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i32_sub() {
|
||||
Testi32::test_sub();
|
||||
TestI32::test_sub();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i32_mul() {
|
||||
Testi32::test_mul();
|
||||
TestI32::test_mul();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i32_div() {
|
||||
Testi32::test_div();
|
||||
TestI32::test_div();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i32_pow() {
|
||||
Testi32::test_pow();
|
||||
TestI32::test_pow();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i32_eq() {
|
||||
Testi32::test_eq();
|
||||
TestI32::test_eq();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i32_ge() {
|
||||
Testi32::test_ge();
|
||||
TestI32::test_ge();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i32_gt() {
|
||||
Testi32::test_gt();
|
||||
TestI32::test_gt();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i32_le() {
|
||||
Testi32::test_le();
|
||||
TestI32::test_le();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i32_lt() {
|
||||
Testi32::test_lt();
|
||||
TestI32::test_lt();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i32_assert_eq() {
|
||||
Testi32::test_assert_eq();
|
||||
TestI32::test_assert_eq();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i32_ternary() {
|
||||
Testi32::test_ternary();
|
||||
TestI32::test_ternary();
|
||||
}
|
||||
|
@ -5,103 +5,108 @@ use crate::{
|
||||
integers::{expect_computation_error, expect_parsing_error, IntegerTester},
|
||||
parse_program,
|
||||
};
|
||||
use leo_input::types::{I64Type, IntegerType};
|
||||
use leo_input::types::{I64Type, IntegerType, SignedIntegerType};
|
||||
use leo_typed::InputValue;
|
||||
|
||||
test_int!(Testi64, i64, IntegerType::I64Type(I64Type {}), Int64);
|
||||
test_int!(
|
||||
TestI64,
|
||||
i64,
|
||||
IntegerType::Signed(SignedIntegerType::I64Type(I64Type {})),
|
||||
Int64
|
||||
);
|
||||
|
||||
#[test]
|
||||
fn test_i64_min() {
|
||||
Testi64::test_min();
|
||||
TestI64::test_min();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i64_min_fail() {
|
||||
Testi64::test_min_fail();
|
||||
TestI64::test_min_fail();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i64_max() {
|
||||
Testi64::test_max();
|
||||
TestI64::test_max();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i64_max_fail() {
|
||||
Testi64::test_max_fail();
|
||||
TestI64::test_max_fail();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i64_neg() {
|
||||
Testi64::test_negate();
|
||||
TestI64::test_negate();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i64_neg_max_fail() {
|
||||
Testi64::test_negate_min_fail();
|
||||
TestI64::test_negate_min_fail();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i64_neg_zero() {
|
||||
Testi64::test_negate_zero();
|
||||
TestI64::test_negate_zero();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i64_add() {
|
||||
Testi64::test_add();
|
||||
TestI64::test_add();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i64_sub() {
|
||||
Testi64::test_sub();
|
||||
TestI64::test_sub();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i64_mul() {
|
||||
Testi64::test_mul();
|
||||
TestI64::test_mul();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore] // takes 2 minutes
|
||||
fn test_i64_div() {
|
||||
Testi64::test_div();
|
||||
TestI64::test_div();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i64_pow() {
|
||||
Testi64::test_pow();
|
||||
TestI64::test_pow();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i64_eq() {
|
||||
Testi64::test_eq();
|
||||
TestI64::test_eq();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i64_ge() {
|
||||
Testi64::test_ge();
|
||||
TestI64::test_ge();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i64_gt() {
|
||||
Testi64::test_gt();
|
||||
TestI64::test_gt();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i64_le() {
|
||||
Testi64::test_le();
|
||||
TestI64::test_le();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i64_lt() {
|
||||
Testi64::test_lt();
|
||||
TestI64::test_lt();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i64_assert_eq() {
|
||||
Testi64::test_assert_eq();
|
||||
TestI64::test_assert_eq();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i64_ternary() {
|
||||
Testi64::test_ternary();
|
||||
TestI64::test_ternary();
|
||||
}
|
||||
|
@ -5,102 +5,107 @@ use crate::{
|
||||
integers::{expect_computation_error, expect_parsing_error, IntegerTester},
|
||||
parse_program,
|
||||
};
|
||||
use leo_input::types::{I8Type, IntegerType};
|
||||
use leo_input::types::{I8Type, IntegerType, SignedIntegerType};
|
||||
use leo_typed::InputValue;
|
||||
|
||||
test_int!(Testi8, i8, IntegerType::I8Type(I8Type {}), Int8);
|
||||
test_int!(
|
||||
TestI8,
|
||||
i8,
|
||||
IntegerType::Signed(SignedIntegerType::I8Type(I8Type {})),
|
||||
Int8
|
||||
);
|
||||
|
||||
#[test]
|
||||
fn test_i8_min() {
|
||||
Testi8::test_min();
|
||||
TestI8::test_min();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i8_min_fail() {
|
||||
Testi8::test_min_fail();
|
||||
TestI8::test_min_fail();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i8_max() {
|
||||
Testi8::test_max();
|
||||
TestI8::test_max();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i8_max_fail() {
|
||||
Testi8::test_max_fail();
|
||||
TestI8::test_max_fail();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i8_neg() {
|
||||
Testi8::test_negate();
|
||||
TestI8::test_negate();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i8_neg_max_fail() {
|
||||
Testi8::test_negate_min_fail();
|
||||
TestI8::test_negate_min_fail();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i8_neg_zero() {
|
||||
Testi8::test_negate_zero();
|
||||
TestI8::test_negate_zero();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i8_add() {
|
||||
Testi8::test_add();
|
||||
TestI8::test_add();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i8_sub() {
|
||||
Testi8::test_sub();
|
||||
TestI8::test_sub();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i8_mul() {
|
||||
Testi8::test_mul();
|
||||
TestI8::test_mul();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i8_div() {
|
||||
Testi8::test_div();
|
||||
TestI8::test_div();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i8_pow() {
|
||||
Testi8::test_pow();
|
||||
TestI8::test_pow();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i8_eq() {
|
||||
Testi8::test_eq();
|
||||
TestI8::test_eq();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i8_ge() {
|
||||
Testi8::test_ge();
|
||||
TestI8::test_ge();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i8_gt() {
|
||||
Testi8::test_gt();
|
||||
TestI8::test_gt();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i8_le() {
|
||||
Testi8::test_le();
|
||||
TestI8::test_le();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i8_lt() {
|
||||
Testi8::test_lt();
|
||||
TestI8::test_lt();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i8_assert_eq() {
|
||||
Testi8::test_assert_eq();
|
||||
TestI8::test_assert_eq();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i8_ternary() {
|
||||
Testi8::test_ternary();
|
||||
TestI8::test_ternary();
|
||||
}
|
||||
|
@ -5,10 +5,15 @@ use crate::{
|
||||
integers::{expect_parsing_error, IntegerTester},
|
||||
parse_program,
|
||||
};
|
||||
use leo_input::types::{IntegerType, U128Type};
|
||||
use leo_input::types::{IntegerType, U128Type, UnsignedIntegerType};
|
||||
use leo_typed::InputValue;
|
||||
|
||||
test_uint!(TestU128, u128, IntegerType::U128Type(U128Type {}), UInt128);
|
||||
test_uint!(
|
||||
TestU128,
|
||||
u128,
|
||||
IntegerType::Unsigned(UnsignedIntegerType::U128Type(U128Type {})),
|
||||
UInt128
|
||||
);
|
||||
|
||||
#[test]
|
||||
fn test_u128_min() {
|
||||
|
@ -5,10 +5,15 @@ use crate::{
|
||||
integers::{expect_parsing_error, IntegerTester},
|
||||
parse_program,
|
||||
};
|
||||
use leo_input::types::{IntegerType, U16Type};
|
||||
use leo_input::types::{IntegerType, U16Type, UnsignedIntegerType};
|
||||
use leo_typed::InputValue;
|
||||
|
||||
test_uint!(TestU16, u16, IntegerType::U16Type(U16Type {}), UInt16);
|
||||
test_uint!(
|
||||
TestU16,
|
||||
u16,
|
||||
IntegerType::Unsigned(UnsignedIntegerType::U16Type(U16Type {})),
|
||||
UInt16
|
||||
);
|
||||
|
||||
#[test]
|
||||
fn test_u16_min() {
|
||||
|
@ -5,10 +5,15 @@ use crate::{
|
||||
integers::{expect_parsing_error, IntegerTester},
|
||||
parse_program,
|
||||
};
|
||||
use leo_input::types::{IntegerType, U32Type};
|
||||
use leo_input::types::{IntegerType, U32Type, UnsignedIntegerType};
|
||||
use leo_typed::InputValue;
|
||||
|
||||
test_uint!(TestU32, u32, IntegerType::U32Type(U32Type {}), UInt32);
|
||||
test_uint!(
|
||||
TestU32,
|
||||
u32,
|
||||
IntegerType::Unsigned(UnsignedIntegerType::U32Type(U32Type {})),
|
||||
UInt32
|
||||
);
|
||||
|
||||
#[test]
|
||||
fn test_u32_min() {
|
||||
|
@ -5,10 +5,15 @@ use crate::{
|
||||
integers::{expect_parsing_error, IntegerTester},
|
||||
parse_program,
|
||||
};
|
||||
use leo_input::types::{IntegerType, U64Type};
|
||||
use leo_input::types::{IntegerType, U64Type, UnsignedIntegerType};
|
||||
use leo_typed::InputValue;
|
||||
|
||||
test_uint!(TestU64, u64, IntegerType::U64Type(U64Type {}), UInt64);
|
||||
test_uint!(
|
||||
TestU64,
|
||||
u64,
|
||||
IntegerType::Unsigned(UnsignedIntegerType::U64Type(U64Type {})),
|
||||
UInt64
|
||||
);
|
||||
|
||||
#[test]
|
||||
fn test_u64_min() {
|
||||
|
@ -5,10 +5,15 @@ use crate::{
|
||||
integers::{expect_parsing_error, IntegerTester},
|
||||
parse_program,
|
||||
};
|
||||
use leo_input::types::{IntegerType, U8Type};
|
||||
use leo_input::types::{IntegerType, U8Type, UnsignedIntegerType};
|
||||
use leo_typed::InputValue;
|
||||
|
||||
test_uint!(TestU8, u8, IntegerType::U8Type(U8Type {}), UInt8);
|
||||
test_uint!(
|
||||
TestU8,
|
||||
u8,
|
||||
IntegerType::Unsigned(UnsignedIntegerType::U8Type(U8Type {})),
|
||||
UInt8
|
||||
);
|
||||
|
||||
#[test]
|
||||
fn test_u8_min() {
|
||||
|
@ -20,6 +20,7 @@ use leo_compiler::{
|
||||
ConstrainedValue,
|
||||
OutputBytes,
|
||||
};
|
||||
use leo_input::types::{IntegerType, U32Type, UnsignedIntegerType};
|
||||
use leo_typed::{InputValue, MainInput};
|
||||
|
||||
use snarkos_curves::edwards_bls12::Fq;
|
||||
@ -168,3 +169,10 @@ pub(crate) fn generate_main_input(input: Vec<(&str, Option<InputValue>)>) -> Mai
|
||||
|
||||
main_input
|
||||
}
|
||||
|
||||
pub(crate) fn generate_test_input_u32(number: u32) -> Option<InputValue> {
|
||||
Some(InputValue::Integer(
|
||||
IntegerType::Unsigned(UnsignedIntegerType::U32Type(U32Type {})),
|
||||
number.to_string(),
|
||||
))
|
||||
}
|
||||
|
@ -2,12 +2,12 @@ use crate::{
|
||||
assert_satisfied,
|
||||
expect_synthesis_error,
|
||||
generate_main_input,
|
||||
generate_test_input_u32,
|
||||
get_output,
|
||||
parse_program,
|
||||
parse_program_with_input,
|
||||
EdwardsTestCompiler,
|
||||
};
|
||||
use leo_input::types::{IntegerType, U32Type};
|
||||
use leo_typed::InputValue;
|
||||
|
||||
#[test]
|
||||
@ -19,10 +19,7 @@ fn test_assert() {
|
||||
|
||||
// Check that an input value of 1 satisfies the constraint system
|
||||
|
||||
let main_input = generate_main_input(vec![(
|
||||
"a",
|
||||
Some(InputValue::Integer(IntegerType::U32Type(U32Type {}), 1.to_string())),
|
||||
)]);
|
||||
let main_input = generate_main_input(vec![("a", generate_test_input_u32(1))]);
|
||||
|
||||
program_1_pass.set_main_input(main_input);
|
||||
|
||||
@ -30,10 +27,7 @@ fn test_assert() {
|
||||
|
||||
// Check that an input value of 0 satisfies the constraint system
|
||||
|
||||
let main_input = generate_main_input(vec![(
|
||||
"a",
|
||||
Some(InputValue::Integer(IntegerType::U32Type(U32Type {}), 0.to_string())),
|
||||
)]);
|
||||
let main_input = generate_main_input(vec![("a", generate_test_input_u32(0))]);
|
||||
|
||||
program_0_pass.set_main_input(main_input);
|
||||
|
||||
@ -41,10 +35,7 @@ fn test_assert() {
|
||||
|
||||
// Check that an input value of 2 does not satisfy the constraint system
|
||||
|
||||
let main_input = generate_main_input(vec![(
|
||||
"a",
|
||||
Some(InputValue::Integer(IntegerType::U32Type(U32Type {}), 2.to_string())),
|
||||
)]);
|
||||
let main_input = generate_main_input(vec![("a", generate_test_input_u32(2))]);
|
||||
|
||||
program_2_fail.set_main_input(main_input);
|
||||
|
||||
@ -59,10 +50,7 @@ fn test_mutate() {
|
||||
|
||||
// Check that an input value of 1 satisfies the constraint system
|
||||
|
||||
let main_input = generate_main_input(vec![(
|
||||
"a",
|
||||
Some(InputValue::Integer(IntegerType::U32Type(U32Type {}), 1.to_string())),
|
||||
)]);
|
||||
let main_input = generate_main_input(vec![("a", generate_test_input_u32(1))]);
|
||||
|
||||
program_1_pass.set_main_input(main_input);
|
||||
|
||||
@ -70,10 +58,7 @@ fn test_mutate() {
|
||||
|
||||
// Check that an input value of 0 satisfies the constraint system
|
||||
|
||||
let main_input = generate_main_input(vec![(
|
||||
"a",
|
||||
Some(InputValue::Integer(IntegerType::U32Type(U32Type {}), 0.to_string())),
|
||||
)]);
|
||||
let main_input = generate_main_input(vec![("a", generate_test_input_u32(0))]);
|
||||
|
||||
program_0_pass.set_main_input(main_input);
|
||||
|
||||
@ -113,14 +98,8 @@ fn test_chain() {
|
||||
// Check that an input of 1 outputs 1
|
||||
|
||||
let main_input = generate_main_input(vec![
|
||||
(
|
||||
"a",
|
||||
Some(InputValue::Integer(IntegerType::U32Type(U32Type {}), 1.to_string())),
|
||||
),
|
||||
(
|
||||
"b",
|
||||
Some(InputValue::Integer(IntegerType::U32Type(U32Type {}), 1.to_string())),
|
||||
),
|
||||
("a", generate_test_input_u32(1)),
|
||||
("b", generate_test_input_u32(1)),
|
||||
]);
|
||||
|
||||
program_1_1.set_main_input(main_input);
|
||||
@ -130,14 +109,8 @@ fn test_chain() {
|
||||
// Check that an input of 2 outputs 2
|
||||
|
||||
let main_input = generate_main_input(vec![
|
||||
(
|
||||
"a",
|
||||
Some(InputValue::Integer(IntegerType::U32Type(U32Type {}), 2.to_string())),
|
||||
),
|
||||
(
|
||||
"b",
|
||||
Some(InputValue::Integer(IntegerType::U32Type(U32Type {}), 2.to_string())),
|
||||
),
|
||||
("a", generate_test_input_u32(2)),
|
||||
("b", generate_test_input_u32(2)),
|
||||
]);
|
||||
|
||||
program_2_2.set_main_input(main_input);
|
||||
@ -147,14 +120,8 @@ fn test_chain() {
|
||||
// Check that an input of 4 outputs 3
|
||||
|
||||
let main_input = generate_main_input(vec![
|
||||
(
|
||||
"a",
|
||||
Some(InputValue::Integer(IntegerType::U32Type(U32Type {}), 4.to_string())),
|
||||
),
|
||||
(
|
||||
"b",
|
||||
Some(InputValue::Integer(IntegerType::U32Type(U32Type {}), 3.to_string())),
|
||||
),
|
||||
("a", generate_test_input_u32(4)),
|
||||
("b", generate_test_input_u32(3)),
|
||||
]);
|
||||
|
||||
program_4_3.set_main_input(main_input);
|
||||
@ -174,10 +141,7 @@ fn test_nested() {
|
||||
let main_input = generate_main_input(vec![
|
||||
("a", Some(InputValue::Boolean(true))),
|
||||
("b", Some(InputValue::Boolean(true))),
|
||||
(
|
||||
"c",
|
||||
Some(InputValue::Integer(IntegerType::U32Type(U32Type {}), 3.to_string())),
|
||||
),
|
||||
("c", generate_test_input_u32(3)),
|
||||
]);
|
||||
|
||||
program_true_true_3.set_main_input(main_input);
|
||||
@ -189,10 +153,7 @@ fn test_nested() {
|
||||
let main_input = generate_main_input(vec![
|
||||
("a", Some(InputValue::Boolean(true))),
|
||||
("b", Some(InputValue::Boolean(false))),
|
||||
(
|
||||
"c",
|
||||
Some(InputValue::Integer(IntegerType::U32Type(U32Type {}), 1.to_string())),
|
||||
),
|
||||
("c", generate_test_input_u32(1)),
|
||||
]);
|
||||
|
||||
program_true_false_1.set_main_input(main_input);
|
||||
@ -204,10 +165,7 @@ fn test_nested() {
|
||||
let main_input = generate_main_input(vec![
|
||||
("a", Some(InputValue::Boolean(false))),
|
||||
("b", Some(InputValue::Boolean(false))),
|
||||
(
|
||||
"c",
|
||||
Some(InputValue::Integer(IntegerType::U32Type(U32Type {}), 0.to_string())),
|
||||
),
|
||||
("c", generate_test_input_u32(0)),
|
||||
]);
|
||||
|
||||
program_false_false_0.set_main_input(main_input);
|
||||
|
@ -5,7 +5,7 @@ use crate::{
|
||||
sections::Header,
|
||||
tables::Table,
|
||||
types::{DataType, Type},
|
||||
values::{NumberImplicitValue, NumberValue, Value},
|
||||
values::{NumberValue, PositiveNumber, Value},
|
||||
};
|
||||
|
||||
use pest::{
|
||||
@ -42,10 +42,10 @@ impl InputParserError {
|
||||
InputParserError::SyntaxError(InputSyntaxError::from(error))
|
||||
}
|
||||
|
||||
pub fn implicit_type(data_type: DataType, implicit: NumberImplicitValue) -> Self {
|
||||
pub fn implicit_type(data_type: DataType, implicit: NumberValue) -> Self {
|
||||
let message = format!("expected `{}`, found `{}`", data_type.to_string(), implicit.to_string());
|
||||
|
||||
Self::new_from_span(message, implicit.span)
|
||||
Self::new_from_span(message, implicit.span().clone())
|
||||
}
|
||||
|
||||
pub fn data_type_mismatch(data_type: DataType, value: Value) -> Self {
|
||||
@ -62,7 +62,7 @@ impl InputParserError {
|
||||
Self::new_from_span(message, span)
|
||||
}
|
||||
|
||||
pub fn array_inline_length(number: NumberValue, array: ArrayInlineExpression) -> Self {
|
||||
pub fn array_inline_length(number: PositiveNumber, array: ArrayInlineExpression) -> Self {
|
||||
let message = format!(
|
||||
"expected an array with a fixed size of {} elements, found one with {} elements",
|
||||
number.to_string(),
|
||||
@ -73,7 +73,7 @@ impl InputParserError {
|
||||
Self::new_from_span(message, span)
|
||||
}
|
||||
|
||||
pub fn array_init_length(number: NumberValue, array: ArrayInitializerExpression) -> Self {
|
||||
pub fn array_init_length(number: PositiveNumber, array: ArrayInitializerExpression) -> Self {
|
||||
let message = format!(
|
||||
"expected an array with a fixed size of {} elements, found one with {} elements",
|
||||
number.to_string(),
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::{ast::Rule, expressions::Expression, values::NumberValue};
|
||||
use crate::{ast::Rule, expressions::Expression, values::PositiveNumber};
|
||||
|
||||
use pest::Span;
|
||||
use pest_ast::FromPest;
|
||||
@ -7,7 +7,7 @@ use pest_ast::FromPest;
|
||||
#[pest_ast(rule(Rule::expression_array_initializer))]
|
||||
pub struct ArrayInitializerExpression<'ast> {
|
||||
pub expression: Box<Expression<'ast>>,
|
||||
pub count: NumberValue<'ast>,
|
||||
pub count: PositiveNumber<'ast>,
|
||||
#[pest_ast(outer())]
|
||||
pub span: Span<'ast>,
|
||||
}
|
||||
|
@ -37,32 +37,40 @@ type_ = { type_array | type_data }
|
||||
|
||||
// Declared in types/integer_type.rs
|
||||
type_integer = {
|
||||
type_u8
|
||||
| type_u16
|
||||
| type_u32
|
||||
| type_u64
|
||||
| type_u128
|
||||
| type_i8
|
||||
| type_i16
|
||||
| type_i32
|
||||
| type_i64
|
||||
| type_i128
|
||||
type_integer_signed
|
||||
| type_integer_unsigned
|
||||
}
|
||||
|
||||
// Declared in types/integer_type.rs
|
||||
// Declared in types/unsigned_integer_type.rs
|
||||
type_u8 = { "u8" }
|
||||
type_u16 = { "u16" }
|
||||
type_u32 = { "u32" }
|
||||
type_u64 = { "u64" }
|
||||
type_u128 = { "u128" }
|
||||
|
||||
// Declared in types/integer_type.rs
|
||||
type_integer_unsigned = {
|
||||
type_u8
|
||||
| type_u16
|
||||
| type_u32
|
||||
| type_u64
|
||||
| type_u128
|
||||
}
|
||||
|
||||
// Declared in types/signed_integer_type.rs
|
||||
type_i8 = { "i8" }
|
||||
type_i16 = { "i16" }
|
||||
type_i32 = { "i32" }
|
||||
type_i64 = { "i64" }
|
||||
type_i128 = { "i128" }
|
||||
|
||||
type_integer_signed = {
|
||||
type_i8
|
||||
| type_i16
|
||||
| type_i32
|
||||
| type_i64
|
||||
| type_i128
|
||||
}
|
||||
|
||||
// Declared in types/field_type.rs
|
||||
type_field = { "field" }
|
||||
|
||||
@ -79,7 +87,7 @@ type_address = { "address" }
|
||||
type_data = { type_field | type_group | type_boolean | type_address | type_integer }
|
||||
|
||||
// Declared in types/array_type.rs
|
||||
type_array = { type_data ~ ("[" ~ value_number ~ "]")+ }
|
||||
type_array = { type_data ~ ("[" ~ number_positive ~ "]")+ }
|
||||
|
||||
/// Values
|
||||
|
||||
@ -90,38 +98,49 @@ value = {
|
||||
| value_field
|
||||
| value_group
|
||||
| value_integer
|
||||
| value_implicit // must be last as a catch all
|
||||
| value_number // must be last as a catch all
|
||||
}
|
||||
|
||||
// Declared in values/number_value.rs
|
||||
value_number = @{ (("-" ~ ASCII_NONZERO_DIGIT) | "0" | ASCII_NONZERO_DIGIT) ~ ASCII_DIGIT* }
|
||||
value_number = { number_negative | number_positive }
|
||||
|
||||
// Declared in values/number_negative.rs
|
||||
number_negative = @{ "-" ~ ASCII_DIGIT+ }
|
||||
|
||||
// Declared in values/number_positive.rs
|
||||
number_positive = @{ ASCII_DIGIT+ }
|
||||
|
||||
// Declared in values/number_implicit_value.rs
|
||||
value_implicit = { value_number }
|
||||
|
||||
// Declared in values/integer_value.rs
|
||||
value_integer = { value_number ~ type_integer }
|
||||
value_integer = { value_integer_signed | value_integer_unsigned}
|
||||
|
||||
// Declared in values/signed_integer_value.rs
|
||||
value_integer_signed = ${ value_number ~ type_integer_signed }
|
||||
|
||||
// Declared in values/unsigned_integer_value.rs
|
||||
value_integer_unsigned = ${ number_positive ~ type_integer_unsigned }
|
||||
|
||||
// Declared in values/boolean_value.rs
|
||||
value_boolean = { "true" | "false" }
|
||||
|
||||
// Declared in values/field_value.rs
|
||||
value_field = { value_number ~ type_field }
|
||||
value_field = ${ value_number ~ type_field }
|
||||
|
||||
// Declared in values/group_value.rs
|
||||
value_group = { group_tuple ~ type_group }
|
||||
group_tuple = { "(" ~ NEWLINE* ~ value_number ~ "," ~ NEWLINE* ~ value_number ~ NEWLINE* ~")" }
|
||||
value_group = ${ group_single_or_tuple ~ type_group }
|
||||
group_tuple = !{"(" ~ value_number ~ "," ~ value_number ~ ")"}
|
||||
group_single_or_tuple = {value_number | group_tuple}
|
||||
|
||||
// Declared in values/address.rs
|
||||
address = @{ (LOWERCASE_LETTER | ASCII_DIGIT)* }
|
||||
address = @{ "aleo" ~ ASCII_DIGIT ~ (LOWERCASE_LETTER | ASCII_DIGIT){58} }
|
||||
|
||||
// Declared in values/address_value.rs
|
||||
value_address = { type_address ~ "(" ~ address ~ ")" }
|
||||
value_address = ${ type_address ~ "(" ~ address ~ ")" }
|
||||
|
||||
/// Expressions
|
||||
|
||||
// Declared in expressions/array_initializer_expression.rs
|
||||
expression_array_initializer = { "[" ~ expression ~ ";" ~ value_number ~ "]" }
|
||||
expression_array_initializer = { "[" ~ expression ~ ";" ~ number_positive ~ "]" }
|
||||
|
||||
// Declared in expressions/array_inline_expression.rs
|
||||
expression_array_inline = { "[" ~ NEWLINE* ~ inline_array_inner ~ NEWLINE* ~ "]"}
|
||||
|
@ -1,19 +1,19 @@
|
||||
use crate::{ast::Rule, types::DataType, values::NumberValue};
|
||||
use crate::{ast::Rule, types::DataType, values::PositiveNumber};
|
||||
|
||||
use pest::Span;
|
||||
use pest_ast::FromPest;
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq)]
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Eq)]
|
||||
#[pest_ast(rule(Rule::type_array))]
|
||||
pub struct ArrayType<'ast> {
|
||||
pub _type: DataType,
|
||||
pub dimensions: Vec<NumberValue<'ast>>,
|
||||
pub dimensions: Vec<PositiveNumber<'ast>>,
|
||||
#[pest_ast(outer())]
|
||||
pub span: Span<'ast>,
|
||||
}
|
||||
|
||||
impl<'ast> ArrayType<'ast> {
|
||||
pub fn next_dimension(&mut self) -> Option<NumberValue<'ast>> {
|
||||
pub fn next_dimension(&mut self) -> Option<PositiveNumber<'ast>> {
|
||||
self.dimensions.pop()
|
||||
}
|
||||
}
|
||||
|
@ -1,81 +1,23 @@
|
||||
use crate::ast::Rule;
|
||||
use crate::{
|
||||
ast::Rule,
|
||||
types::{SignedIntegerType, UnsignedIntegerType},
|
||||
};
|
||||
|
||||
use pest_ast::FromPest;
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Eq)]
|
||||
#[pest_ast(rule(Rule::type_integer))]
|
||||
pub enum IntegerType {
|
||||
U8Type(U8Type),
|
||||
U16Type(U16Type),
|
||||
U32Type(U32Type),
|
||||
U64Type(U64Type),
|
||||
U128Type(U128Type),
|
||||
|
||||
I8Type(I8Type),
|
||||
I16Type(I16Type),
|
||||
I32Type(I32Type),
|
||||
I64Type(I64Type),
|
||||
I128Type(I128Type),
|
||||
Signed(SignedIntegerType),
|
||||
Unsigned(UnsignedIntegerType),
|
||||
}
|
||||
|
||||
// Unsigned
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Eq)]
|
||||
#[pest_ast(rule(Rule::type_u8))]
|
||||
pub struct U8Type {}
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Eq)]
|
||||
#[pest_ast(rule(Rule::type_u16))]
|
||||
pub struct U16Type {}
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Eq)]
|
||||
#[pest_ast(rule(Rule::type_u32))]
|
||||
pub struct U32Type {}
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Eq)]
|
||||
#[pest_ast(rule(Rule::type_u64))]
|
||||
pub struct U64Type {}
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Eq)]
|
||||
#[pest_ast(rule(Rule::type_u128))]
|
||||
pub struct U128Type {}
|
||||
|
||||
// Signed
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Eq)]
|
||||
#[pest_ast(rule(Rule::type_i8))]
|
||||
pub struct I8Type {}
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Eq)]
|
||||
#[pest_ast(rule(Rule::type_i16))]
|
||||
pub struct I16Type {}
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Eq)]
|
||||
#[pest_ast(rule(Rule::type_i32))]
|
||||
pub struct I32Type {}
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Eq)]
|
||||
#[pest_ast(rule(Rule::type_i64))]
|
||||
pub struct I64Type {}
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Eq)]
|
||||
#[pest_ast(rule(Rule::type_i128))]
|
||||
pub struct I128Type {}
|
||||
|
||||
impl std::fmt::Display for IntegerType {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
impl fmt::Display for IntegerType {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
IntegerType::U8Type(_) => write!(f, "u8"),
|
||||
IntegerType::U16Type(_) => write!(f, "u16"),
|
||||
IntegerType::U32Type(_) => write!(f, "u32"),
|
||||
IntegerType::U64Type(_) => write!(f, "u64"),
|
||||
IntegerType::U128Type(_) => write!(f, "u128"),
|
||||
|
||||
IntegerType::I8Type(_) => write!(f, "i8"),
|
||||
IntegerType::I16Type(_) => write!(f, "i16"),
|
||||
IntegerType::I32Type(_) => write!(f, "i32"),
|
||||
IntegerType::I64Type(_) => write!(f, "i64"),
|
||||
IntegerType::I128Type(_) => write!(f, "i128"),
|
||||
IntegerType::Signed(integer) => write!(f, "{}", integer),
|
||||
IntegerType::Unsigned(integer) => write!(f, "{}", integer),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,5 +19,11 @@ pub use group_type::*;
|
||||
pub mod integer_type;
|
||||
pub use integer_type::*;
|
||||
|
||||
pub mod signed_integer_type;
|
||||
pub use signed_integer_type::*;
|
||||
|
||||
pub mod type_;
|
||||
pub use type_::*;
|
||||
|
||||
pub mod unsigned_integer_type;
|
||||
pub use unsigned_integer_type::*;
|
||||
|
46
input/src/types/signed_integer_type.rs
Normal file
46
input/src/types/signed_integer_type.rs
Normal file
@ -0,0 +1,46 @@
|
||||
use crate::ast::Rule;
|
||||
|
||||
use pest_ast::FromPest;
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Eq)]
|
||||
#[pest_ast(rule(Rule::type_integer_signed))]
|
||||
pub enum SignedIntegerType {
|
||||
I8Type(I8Type),
|
||||
I16Type(I16Type),
|
||||
I32Type(I32Type),
|
||||
I64Type(I64Type),
|
||||
I128Type(I128Type),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Eq)]
|
||||
#[pest_ast(rule(Rule::type_i8))]
|
||||
pub struct I8Type {}
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Eq)]
|
||||
#[pest_ast(rule(Rule::type_i16))]
|
||||
pub struct I16Type {}
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Eq)]
|
||||
#[pest_ast(rule(Rule::type_i32))]
|
||||
pub struct I32Type {}
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Eq)]
|
||||
#[pest_ast(rule(Rule::type_i64))]
|
||||
pub struct I64Type {}
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Eq)]
|
||||
#[pest_ast(rule(Rule::type_i128))]
|
||||
pub struct I128Type {}
|
||||
|
||||
impl fmt::Display for SignedIntegerType {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
SignedIntegerType::I8Type(_) => write!(f, "i8"),
|
||||
SignedIntegerType::I16Type(_) => write!(f, "i16"),
|
||||
SignedIntegerType::I32Type(_) => write!(f, "i32"),
|
||||
SignedIntegerType::I64Type(_) => write!(f, "i64"),
|
||||
SignedIntegerType::I128Type(_) => write!(f, "i128"),
|
||||
}
|
||||
}
|
||||
}
|
46
input/src/types/unsigned_integer_type.rs
Normal file
46
input/src/types/unsigned_integer_type.rs
Normal file
@ -0,0 +1,46 @@
|
||||
use crate::ast::Rule;
|
||||
|
||||
use pest_ast::FromPest;
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Eq)]
|
||||
#[pest_ast(rule(Rule::type_integer_unsigned))]
|
||||
pub enum UnsignedIntegerType {
|
||||
U8Type(U8Type),
|
||||
U16Type(U16Type),
|
||||
U32Type(U32Type),
|
||||
U64Type(U64Type),
|
||||
U128Type(U128Type),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Eq)]
|
||||
#[pest_ast(rule(Rule::type_u8))]
|
||||
pub struct U8Type {}
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Eq)]
|
||||
#[pest_ast(rule(Rule::type_u16))]
|
||||
pub struct U16Type {}
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Eq)]
|
||||
#[pest_ast(rule(Rule::type_u32))]
|
||||
pub struct U32Type {}
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Eq)]
|
||||
#[pest_ast(rule(Rule::type_u64))]
|
||||
pub struct U64Type {}
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Eq)]
|
||||
#[pest_ast(rule(Rule::type_u128))]
|
||||
pub struct U128Type {}
|
||||
|
||||
impl fmt::Display for UnsignedIntegerType {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
UnsignedIntegerType::U8Type(_) => write!(f, "u8"),
|
||||
UnsignedIntegerType::U16Type(_) => write!(f, "u16"),
|
||||
UnsignedIntegerType::U32Type(_) => write!(f, "u32"),
|
||||
UnsignedIntegerType::U64Type(_) => write!(f, "u64"),
|
||||
UnsignedIntegerType::U128Type(_) => write!(f, "u128"),
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
use crate::{ast::Rule, types::FieldType, values::NumberValue};
|
||||
|
||||
use crate::values::NumberImplicitValue;
|
||||
use pest::Span;
|
||||
use pest_ast::FromPest;
|
||||
use std::fmt;
|
||||
@ -14,16 +13,6 @@ pub struct FieldValue<'ast> {
|
||||
pub span: Span<'ast>,
|
||||
}
|
||||
|
||||
impl<'ast> FieldValue<'ast> {
|
||||
pub fn from_implicit(number: NumberImplicitValue<'ast>, type_: FieldType) -> Self {
|
||||
Self {
|
||||
number: number.number,
|
||||
type_,
|
||||
span: number.span,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast> fmt::Display for FieldValue<'ast> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}", self.number)
|
||||
|
@ -1,7 +1,6 @@
|
||||
use crate::{
|
||||
ast::Rule,
|
||||
types::IntegerType,
|
||||
values::{NumberImplicitValue, NumberValue},
|
||||
values::{SignedIntegerValue, UnsignedIntegerValue},
|
||||
};
|
||||
|
||||
use pest::Span;
|
||||
@ -10,25 +9,25 @@ use std::fmt;
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Eq)]
|
||||
#[pest_ast(rule(Rule::value_integer))]
|
||||
pub struct IntegerValue<'ast> {
|
||||
pub number: NumberValue<'ast>,
|
||||
pub type_: IntegerType,
|
||||
#[pest_ast(outer())]
|
||||
pub span: Span<'ast>,
|
||||
pub enum IntegerValue<'ast> {
|
||||
Signed(SignedIntegerValue<'ast>),
|
||||
Unsigned(UnsignedIntegerValue<'ast>),
|
||||
}
|
||||
|
||||
impl<'ast> IntegerValue<'ast> {
|
||||
pub fn from_implicit(number: NumberImplicitValue<'ast>, type_: IntegerType) -> Self {
|
||||
Self {
|
||||
number: number.number,
|
||||
type_,
|
||||
span: number.span,
|
||||
pub fn span(&self) -> &Span<'ast> {
|
||||
match self {
|
||||
IntegerValue::Signed(integer) => &integer.span,
|
||||
IntegerValue::Unsigned(integer) => &integer.span,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast> fmt::Display for IntegerValue<'ast> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}{}", self.number, self.type_)
|
||||
match self {
|
||||
IntegerValue::Signed(integer) => write!(f, "{}", integer),
|
||||
IntegerValue::Unsigned(integer) => write!(f, "{}", integer),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,11 +16,20 @@ pub use group_value::*;
|
||||
pub mod integer_value;
|
||||
pub use integer_value::*;
|
||||
|
||||
pub mod number_implicit_value;
|
||||
pub use number_implicit_value::*;
|
||||
pub mod negative_number;
|
||||
pub use negative_number::*;
|
||||
|
||||
pub mod number_value;
|
||||
pub use number_value::*;
|
||||
|
||||
pub mod positive_number;
|
||||
pub use positive_number::*;
|
||||
|
||||
pub mod signed_integer_value;
|
||||
pub use signed_integer_value::*;
|
||||
|
||||
pub mod value;
|
||||
pub use value::*;
|
||||
|
||||
pub mod unsigned_integer_value;
|
||||
pub use unsigned_integer_value::*;
|
||||
|
20
input/src/values/negative_number.rs
Normal file
20
input/src/values/negative_number.rs
Normal file
@ -0,0 +1,20 @@
|
||||
use crate::ast::{span_into_string, Rule};
|
||||
|
||||
use pest::Span;
|
||||
use pest_ast::FromPest;
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Eq)]
|
||||
#[pest_ast(rule(Rule::number_negative))]
|
||||
pub struct NegativeNumber<'ast> {
|
||||
#[pest_ast(outer(with(span_into_string)))]
|
||||
pub value: String,
|
||||
#[pest_ast(outer())]
|
||||
pub span: Span<'ast>,
|
||||
}
|
||||
|
||||
impl<'ast> fmt::Display for NegativeNumber<'ast> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}", self.value)
|
||||
}
|
||||
}
|
@ -1,4 +1,7 @@
|
||||
use crate::ast::{span_into_string, Rule};
|
||||
use crate::{
|
||||
ast::Rule,
|
||||
values::{NegativeNumber, PositiveNumber},
|
||||
};
|
||||
|
||||
use pest::Span;
|
||||
use pest_ast::FromPest;
|
||||
@ -6,15 +9,25 @@ use std::fmt;
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Eq)]
|
||||
#[pest_ast(rule(Rule::value_number))]
|
||||
pub struct NumberValue<'ast> {
|
||||
#[pest_ast(outer(with(span_into_string)))]
|
||||
pub value: String,
|
||||
#[pest_ast(outer())]
|
||||
pub span: Span<'ast>,
|
||||
pub enum NumberValue<'ast> {
|
||||
Negative(NegativeNumber<'ast>),
|
||||
Positive(PositiveNumber<'ast>),
|
||||
}
|
||||
|
||||
impl<'ast> NumberValue<'ast> {
|
||||
pub fn span(&self) -> &Span<'ast> {
|
||||
match self {
|
||||
NumberValue::Negative(number) => &number.span,
|
||||
NumberValue::Positive(number) => &number.span,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast> fmt::Display for NumberValue<'ast> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}", self.value)
|
||||
match self {
|
||||
NumberValue::Negative(number) => write!(f, "{}", number),
|
||||
NumberValue::Positive(number) => write!(f, "{}", number),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
20
input/src/values/positive_number.rs
Normal file
20
input/src/values/positive_number.rs
Normal file
@ -0,0 +1,20 @@
|
||||
use crate::ast::{span_into_string, Rule};
|
||||
|
||||
use pest::Span;
|
||||
use pest_ast::FromPest;
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Eq)]
|
||||
#[pest_ast(rule(Rule::number_positive))]
|
||||
pub struct PositiveNumber<'ast> {
|
||||
#[pest_ast(outer(with(span_into_string)))]
|
||||
pub value: String,
|
||||
#[pest_ast(outer())]
|
||||
pub span: Span<'ast>,
|
||||
}
|
||||
|
||||
impl<'ast> fmt::Display for PositiveNumber<'ast> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}", self.value)
|
||||
}
|
||||
}
|
@ -1,18 +1,19 @@
|
||||
use crate::{ast::Rule, values::NumberValue};
|
||||
use crate::{ast::Rule, types::SignedIntegerType, values::NumberValue};
|
||||
|
||||
use pest::Span;
|
||||
use pest_ast::FromPest;
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Eq)]
|
||||
#[pest_ast(rule(Rule::value_implicit))]
|
||||
pub struct NumberImplicitValue<'ast> {
|
||||
#[pest_ast(rule(Rule::value_integer_signed))]
|
||||
pub struct SignedIntegerValue<'ast> {
|
||||
pub number: NumberValue<'ast>,
|
||||
pub type_: SignedIntegerType,
|
||||
#[pest_ast(outer())]
|
||||
pub span: Span<'ast>,
|
||||
}
|
||||
|
||||
impl<'ast> fmt::Display for NumberImplicitValue<'ast> {
|
||||
impl<'ast> fmt::Display for SignedIntegerValue<'ast> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}", self.number)
|
||||
}
|
20
input/src/values/unsigned_integer_value.rs
Normal file
20
input/src/values/unsigned_integer_value.rs
Normal file
@ -0,0 +1,20 @@
|
||||
use crate::{ast::Rule, types::UnsignedIntegerType, values::PositiveNumber};
|
||||
|
||||
use pest::Span;
|
||||
use pest_ast::FromPest;
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Clone, Debug, FromPest, PartialEq, Eq)]
|
||||
#[pest_ast(rule(Rule::value_integer_unsigned))]
|
||||
pub struct UnsignedIntegerValue<'ast> {
|
||||
pub number: PositiveNumber<'ast>,
|
||||
pub type_: UnsignedIntegerType,
|
||||
#[pest_ast(outer())]
|
||||
pub span: Span<'ast>,
|
||||
}
|
||||
|
||||
impl<'ast> fmt::Display for UnsignedIntegerValue<'ast> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}", self.number)
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
use crate::{
|
||||
ast::Rule,
|
||||
values::{BooleanValue, FieldValue, GroupValue, IntegerValue, NumberImplicitValue},
|
||||
values::{BooleanValue, FieldValue, GroupValue, IntegerValue, NumberValue},
|
||||
};
|
||||
|
||||
use crate::values::AddressValue;
|
||||
@ -15,7 +15,7 @@ pub enum Value<'ast> {
|
||||
Boolean(BooleanValue<'ast>),
|
||||
Field(FieldValue<'ast>),
|
||||
Group(GroupValue<'ast>),
|
||||
Implicit(NumberImplicitValue<'ast>),
|
||||
Implicit(NumberValue<'ast>),
|
||||
Integer(IntegerValue<'ast>),
|
||||
}
|
||||
|
||||
@ -26,8 +26,8 @@ impl<'ast> Value<'ast> {
|
||||
Value::Boolean(value) => &value.span,
|
||||
Value::Field(value) => &value.span,
|
||||
Value::Group(value) => &value.span,
|
||||
Value::Implicit(value) => &value.span,
|
||||
Value::Integer(value) => &value.span,
|
||||
Value::Implicit(value) => &value.span(),
|
||||
Value::Integer(value) => &value.span(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::{Error, Expression, Span};
|
||||
use leo_ast::{common::RangeOrExpression as AstRangeOrExpression, values::NumberValue};
|
||||
use crate::Expression;
|
||||
use leo_ast::common::RangeOrExpression as AstRangeOrExpression;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt;
|
||||
@ -11,15 +11,6 @@ pub enum RangeOrExpression {
|
||||
Expression(Expression),
|
||||
}
|
||||
|
||||
pub fn unwrap_bound(bound: Option<NumberValue>) -> Option<usize> {
|
||||
bound.map(|number| {
|
||||
let message = format!("Range bounds should be integers");
|
||||
let error = Error::new_from_span(message, Span::from(number.span.clone()));
|
||||
|
||||
number.value.parse::<usize>().expect(&error.to_string())
|
||||
})
|
||||
}
|
||||
|
||||
impl<'ast> From<AstRangeOrExpression<'ast>> for RangeOrExpression {
|
||||
fn from(range_or_expression: AstRangeOrExpression<'ast>) -> Self {
|
||||
match range_or_expression {
|
||||
|
@ -19,12 +19,12 @@ use leo_ast::{
|
||||
FieldValue,
|
||||
GroupValue,
|
||||
IntegerValue,
|
||||
NumberImplicitValue,
|
||||
PositiveNumber as LeoPositiveNumber,
|
||||
NumberValue as AstNumber,
|
||||
PositiveNumber as AstPositiveNumber,
|
||||
Value,
|
||||
},
|
||||
};
|
||||
use leo_input::values::NumberValue;
|
||||
use leo_input::values::PositiveNumber as InputAstPositiveNumber;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt;
|
||||
@ -113,11 +113,14 @@ impl Expression {
|
||||
}
|
||||
|
||||
impl<'ast> Expression {
|
||||
pub(crate) fn get_count_from_number(number: NumberValue<'ast>) -> usize {
|
||||
number.value.parse::<usize>().expect("Unable to read array size")
|
||||
pub(crate) fn get_count_from_input_ast(number: InputAstPositiveNumber<'ast>) -> usize {
|
||||
number
|
||||
.value
|
||||
.parse::<usize>()
|
||||
.expect("Array size should be a positive number")
|
||||
}
|
||||
|
||||
pub(crate) fn get_count_from_positive_number(number: LeoPositiveNumber<'ast>) -> usize {
|
||||
pub(crate) fn get_count_from_ast(number: AstPositiveNumber<'ast>) -> usize {
|
||||
number
|
||||
.value
|
||||
.parse::<usize>()
|
||||
@ -408,7 +411,7 @@ impl<'ast> From<ArrayInlineExpression<'ast>> for Expression {
|
||||
|
||||
impl<'ast> From<ArrayInitializerExpression<'ast>> for Expression {
|
||||
fn from(array: ArrayInitializerExpression<'ast>) -> Self {
|
||||
let count = Expression::get_count_from_positive_number(array.count);
|
||||
let count = Expression::get_count_from_ast(array.count);
|
||||
let expression = Box::new(SpreadOrExpression::from(*array.expression));
|
||||
|
||||
Expression::Array(vec![expression; count], Span::from(array.span))
|
||||
@ -457,7 +460,7 @@ impl<'ast> From<BooleanValue<'ast>> for Expression {
|
||||
|
||||
impl<'ast> From<FieldValue<'ast>> for Expression {
|
||||
fn from(field: FieldValue<'ast>) -> Self {
|
||||
Expression::Field(field.number.value, Span::from(field.span))
|
||||
Expression::Field(field.number.to_string(), Span::from(field.span))
|
||||
}
|
||||
}
|
||||
|
||||
@ -467,19 +470,39 @@ impl<'ast> From<GroupValue<'ast>> for Expression {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast> From<NumberImplicitValue<'ast>> for Expression {
|
||||
fn from(number: NumberImplicitValue<'ast>) -> Self {
|
||||
Expression::Implicit(number.number.value, Span::from(number.span))
|
||||
impl<'ast> From<AstNumber<'ast>> for Expression {
|
||||
fn from(number: AstNumber<'ast>) -> Self {
|
||||
let (value, span) = match number {
|
||||
AstNumber::Positive(number) => (number.value, number.span),
|
||||
AstNumber::Negative(number) => (number.value, number.span),
|
||||
};
|
||||
|
||||
Expression::Implicit(value, Span::from(span))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ast> From<IntegerValue<'ast>> for Expression {
|
||||
fn from(integer: IntegerValue<'ast>) -> Self {
|
||||
Expression::Integer(
|
||||
IntegerType::from(integer._type),
|
||||
integer.number.value,
|
||||
Span::from(integer.span),
|
||||
)
|
||||
let span = Span::from(integer.span().clone());
|
||||
let (type_, value) = match integer {
|
||||
IntegerValue::Signed(integer) => {
|
||||
let type_ = IntegerType::from(integer.type_);
|
||||
let number = match integer.number {
|
||||
AstNumber::Negative(number) => number.value,
|
||||
AstNumber::Positive(number) => number.value,
|
||||
};
|
||||
|
||||
(type_, number)
|
||||
}
|
||||
IntegerValue::Unsigned(integer) => {
|
||||
let type_ = IntegerType::from(integer.type_);
|
||||
let number = integer.number.value;
|
||||
|
||||
(type_, number)
|
||||
}
|
||||
};
|
||||
|
||||
Expression::Integer(type_, value, span)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@ use leo_input::{
|
||||
errors::InputParserError,
|
||||
expressions::{ArrayInitializerExpression, ArrayInlineExpression, Expression},
|
||||
types::{ArrayType, DataType, IntegerType, Type},
|
||||
values::{BooleanValue, FieldValue, GroupValue, NumberImplicitValue, NumberValue, Value},
|
||||
values::{BooleanValue, FieldValue, GroupValue, NumberValue, Value},
|
||||
};
|
||||
|
||||
use leo_input::values::Address;
|
||||
@ -28,8 +28,8 @@ impl InputValue {
|
||||
Ok(InputValue::Boolean(boolean))
|
||||
}
|
||||
|
||||
fn from_number(integer_type: IntegerType, number: NumberValue) -> Result<Self, InputParserError> {
|
||||
Ok(InputValue::Integer(integer_type, number.value))
|
||||
fn from_number(integer_type: IntegerType, number: String) -> Result<Self, InputParserError> {
|
||||
Ok(InputValue::Integer(integer_type, number))
|
||||
}
|
||||
|
||||
fn from_group(group: GroupValue) -> Self {
|
||||
@ -37,16 +37,16 @@ impl InputValue {
|
||||
}
|
||||
|
||||
fn from_field(field: FieldValue) -> Self {
|
||||
InputValue::Field(field.number.value)
|
||||
InputValue::Field(field.number.to_string())
|
||||
}
|
||||
|
||||
fn from_implicit(data_type: DataType, implicit: NumberImplicitValue) -> Result<Self, InputParserError> {
|
||||
fn from_implicit(data_type: DataType, implicit: NumberValue) -> Result<Self, InputParserError> {
|
||||
match data_type {
|
||||
DataType::Address(_) => Err(InputParserError::implicit_type(data_type, implicit)),
|
||||
DataType::Boolean(_) => Err(InputParserError::implicit_type(data_type, implicit)),
|
||||
DataType::Integer(integer_type) => InputValue::from_number(integer_type, implicit.number),
|
||||
DataType::Group(_) => Ok(InputValue::Group(implicit.number.value)),
|
||||
DataType::Field(_) => Ok(InputValue::Field(implicit.number.value)),
|
||||
DataType::Integer(integer_type) => InputValue::from_number(integer_type, implicit.to_string()),
|
||||
DataType::Group(_) => Ok(InputValue::Group(implicit.to_string())),
|
||||
DataType::Field(_) => Ok(InputValue::Field(implicit.to_string())),
|
||||
}
|
||||
}
|
||||
|
||||
@ -55,7 +55,7 @@ impl InputValue {
|
||||
(DataType::Address(_), Value::Address(address)) => Ok(InputValue::from_address(address.address)),
|
||||
(DataType::Boolean(_), Value::Boolean(boolean)) => InputValue::from_boolean(boolean),
|
||||
(DataType::Integer(integer_type), Value::Integer(integer)) => {
|
||||
InputValue::from_number(integer_type, integer.number)
|
||||
InputValue::from_number(integer_type, integer.to_string())
|
||||
}
|
||||
(DataType::Group(_), Value::Group(group)) => Ok(InputValue::from_group(group)),
|
||||
(DataType::Field(_), Value::Field(field)) => Ok(InputValue::from_field(field)),
|
||||
@ -113,7 +113,7 @@ impl InputValue {
|
||||
mut array_type: ArrayType,
|
||||
initializer: ArrayInitializerExpression,
|
||||
) -> Result<Self, InputParserError> {
|
||||
let initializer_count = initializer.count.value.parse::<usize>()?;
|
||||
let initializer_count = initializer.count.to_string().parse::<usize>()?;
|
||||
|
||||
if let Some(number) = array_type.next_dimension() {
|
||||
let outer_dimension = number.value.parse::<usize>()?;
|
||||
|
@ -1,5 +1,13 @@
|
||||
use leo_ast::types::IntegerType as AstIntegerType;
|
||||
use leo_input::types::IntegerType as InputAstIntegerType;
|
||||
use leo_ast::types::{
|
||||
IntegerType as AstIntegerType,
|
||||
SignedIntegerType as AstSignedIntegerType,
|
||||
UnsignedIntegerType as AstUnsignedIntegerType,
|
||||
};
|
||||
use leo_input::types::{
|
||||
IntegerType as InputAstIntegerType,
|
||||
SignedIntegerType as InputAstSignedIntegerType,
|
||||
UnsignedIntegerType as InputAstUnsignedIntegerType,
|
||||
};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt;
|
||||
@ -23,17 +31,32 @@ pub enum IntegerType {
|
||||
impl From<AstIntegerType> for IntegerType {
|
||||
fn from(integer_type: AstIntegerType) -> Self {
|
||||
match integer_type {
|
||||
AstIntegerType::U8Type(_type) => IntegerType::U8,
|
||||
AstIntegerType::U16Type(_type) => IntegerType::U16,
|
||||
AstIntegerType::U32Type(_type) => IntegerType::U32,
|
||||
AstIntegerType::U64Type(_type) => IntegerType::U64,
|
||||
AstIntegerType::U128Type(_type) => IntegerType::U128,
|
||||
AstIntegerType::Signed(signed) => Self::from(signed),
|
||||
AstIntegerType::Unsigned(unsigned) => Self::from(unsigned),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AstIntegerType::I8Type(_type) => IntegerType::I8,
|
||||
AstIntegerType::I16Type(_type) => IntegerType::I16,
|
||||
AstIntegerType::I32Type(_type) => IntegerType::I32,
|
||||
AstIntegerType::I64Type(_type) => IntegerType::I64,
|
||||
AstIntegerType::I128Type(_type) => IntegerType::I128,
|
||||
impl From<AstUnsignedIntegerType> for IntegerType {
|
||||
fn from(integer_type: AstUnsignedIntegerType) -> Self {
|
||||
match integer_type {
|
||||
AstUnsignedIntegerType::U8Type(_type) => IntegerType::U8,
|
||||
AstUnsignedIntegerType::U16Type(_type) => IntegerType::U16,
|
||||
AstUnsignedIntegerType::U32Type(_type) => IntegerType::U32,
|
||||
AstUnsignedIntegerType::U64Type(_type) => IntegerType::U64,
|
||||
AstUnsignedIntegerType::U128Type(_type) => IntegerType::U128,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<AstSignedIntegerType> for IntegerType {
|
||||
fn from(integer_type: AstSignedIntegerType) -> Self {
|
||||
match integer_type {
|
||||
AstSignedIntegerType::I8Type(_type) => IntegerType::I8,
|
||||
AstSignedIntegerType::I16Type(_type) => IntegerType::I16,
|
||||
AstSignedIntegerType::I32Type(_type) => IntegerType::I32,
|
||||
AstSignedIntegerType::I64Type(_type) => IntegerType::I64,
|
||||
AstSignedIntegerType::I128Type(_type) => IntegerType::I128,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -41,17 +64,32 @@ impl From<AstIntegerType> for IntegerType {
|
||||
impl From<InputAstIntegerType> for IntegerType {
|
||||
fn from(integer_type: InputAstIntegerType) -> Self {
|
||||
match integer_type {
|
||||
InputAstIntegerType::U8Type(_type) => IntegerType::U8,
|
||||
InputAstIntegerType::U16Type(_type) => IntegerType::U16,
|
||||
InputAstIntegerType::U32Type(_type) => IntegerType::U32,
|
||||
InputAstIntegerType::U64Type(_type) => IntegerType::U64,
|
||||
InputAstIntegerType::U128Type(_type) => IntegerType::U128,
|
||||
InputAstIntegerType::Signed(signed) => Self::from(signed),
|
||||
InputAstIntegerType::Unsigned(unsigned) => Self::from(unsigned),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
InputAstIntegerType::I8Type(_type) => IntegerType::I8,
|
||||
InputAstIntegerType::I16Type(_type) => IntegerType::I16,
|
||||
InputAstIntegerType::I32Type(_type) => IntegerType::I32,
|
||||
InputAstIntegerType::I64Type(_type) => IntegerType::I64,
|
||||
InputAstIntegerType::I128Type(_type) => IntegerType::I128,
|
||||
impl From<InputAstUnsignedIntegerType> for IntegerType {
|
||||
fn from(integer_type: InputAstUnsignedIntegerType) -> Self {
|
||||
match integer_type {
|
||||
InputAstUnsignedIntegerType::U8Type(_type) => IntegerType::U8,
|
||||
InputAstUnsignedIntegerType::U16Type(_type) => IntegerType::U16,
|
||||
InputAstUnsignedIntegerType::U32Type(_type) => IntegerType::U32,
|
||||
InputAstUnsignedIntegerType::U64Type(_type) => IntegerType::U64,
|
||||
InputAstUnsignedIntegerType::U128Type(_type) => IntegerType::U128,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<InputAstSignedIntegerType> for IntegerType {
|
||||
fn from(integer_type: InputAstSignedIntegerType) -> Self {
|
||||
match integer_type {
|
||||
InputAstSignedIntegerType::I8Type(_type) => IntegerType::I8,
|
||||
InputAstSignedIntegerType::I16Type(_type) => IntegerType::I16,
|
||||
InputAstSignedIntegerType::I32Type(_type) => IntegerType::I32,
|
||||
InputAstSignedIntegerType::I64Type(_type) => IntegerType::I64,
|
||||
InputAstSignedIntegerType::I128Type(_type) => IntegerType::I128,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ impl<'ast> From<InputArrayType<'ast>> for Type {
|
||||
let dimensions = array_type
|
||||
.dimensions
|
||||
.into_iter()
|
||||
.map(|row| Expression::get_count_from_number(row))
|
||||
.map(|row| Expression::get_count_from_input_ast(row))
|
||||
.collect();
|
||||
|
||||
Type::Array(element_type, dimensions)
|
||||
@ -101,7 +101,7 @@ impl<'ast> From<ArrayType<'ast>> for Type {
|
||||
let dimensions = array_type
|
||||
.dimensions
|
||||
.into_iter()
|
||||
.map(|row| Expression::get_count_from_positive_number(row))
|
||||
.map(|row| Expression::get_count_from_ast(row))
|
||||
.collect();
|
||||
|
||||
Type::Array(element_type, dimensions)
|
||||
|
Loading…
Reference in New Issue
Block a user