mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-11-13 06:43:01 +03:00
add updated values to inputs
This commit is contained in:
parent
1c1822b4ff
commit
648acb7fe3
@ -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 {
|
||||
@ -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(),
|
||||
|
@ -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" }
|
||||
|
||||
@ -90,33 +98,44 @@ 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
|
||||
|
||||
|
@ -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(UnsignedIntegerType),
|
||||
Unsigned(SignedIntegerType),
|
||||
}
|
||||
|
||||
// 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,19 +0,0 @@
|
||||
use crate::{ast::Rule, 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> {
|
||||
pub number: NumberValue<'ast>,
|
||||
#[pest_ast(outer())]
|
||||
pub span: Span<'ast>,
|
||||
}
|
||||
|
||||
impl<'ast> fmt::Display for NumberImplicitValue<'ast> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}", self.number)
|
||||
}
|
||||
}
|
@ -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)
|
||||
}
|
||||
}
|
20
input/src/values/signed_integer_value.rs
Normal file
20
input/src/values/signed_integer_value.rs
Normal file
@ -0,0 +1,20 @@
|
||||
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_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 SignedIntegerValue<'ast> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}{}", self.number, self.type_)
|
||||
}
|
||||
}
|
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, self.type_)
|
||||
}
|
||||
}
|
@ -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(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user