Rename (Un)TypedExpr.Int -> (Un)TypedExpr.UInt
We do not actually every parse negative values in there, as a negative value is a combination of a 'Negate' and 'UInt' expression. However, for patterns and constant, it'll be simpler to parse whole Int values as there's no ambiguity with arithmetic operations there. To avoid confusion of having some 'Int' constructors containing only non-negative values, and some being on the whole range, I've renamed the constructor to 'UInt' to make this more obvious.
This commit is contained in:
@@ -2,9 +2,7 @@ use chumsky::prelude::*;
|
||||
|
||||
use crate::{
|
||||
ast,
|
||||
parser::{
|
||||
annotation, error::ParseError, literal::bytearray::parser as bytearray, token::Token, utils,
|
||||
},
|
||||
parser::{annotation, error::ParseError, literal::bytearray, token::Token, utils},
|
||||
};
|
||||
|
||||
pub fn parser() -> impl Parser<Token, ast::UntypedDefinition, Error = ParseError> {
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
use chumsky::prelude::*;
|
||||
|
||||
use crate::parser::{
|
||||
error::ParseError, expr::UntypedExpr, literal::bytearray::parser as bytearray, token::Token,
|
||||
};
|
||||
use crate::parser::{error::ParseError, expr::UntypedExpr, literal::bytearray, token::Token};
|
||||
|
||||
pub fn parser() -> impl Parser<Token, UntypedExpr, Error = ParseError> {
|
||||
bytearray(|bytes, preferred_format, location| UntypedExpr::ByteArray {
|
||||
|
||||
@@ -2,11 +2,11 @@ use chumsky::prelude::*;
|
||||
|
||||
use crate::{
|
||||
expr::UntypedExpr,
|
||||
parser::{error::ParseError, literal::int::parser as int, token::Token},
|
||||
parser::{error::ParseError, literal::uint, token::Token},
|
||||
};
|
||||
|
||||
pub fn parser() -> impl Parser<Token, UntypedExpr, Error = ParseError> {
|
||||
int().map_with_span(|(value, base), span| UntypedExpr::Int {
|
||||
uint().map_with_span(|(value, base), span| UntypedExpr::UInt {
|
||||
location: span,
|
||||
value,
|
||||
base,
|
||||
|
||||
@@ -32,7 +32,7 @@ Fn {
|
||||
location: 21..22,
|
||||
name: "a",
|
||||
},
|
||||
right: Int {
|
||||
right: UInt {
|
||||
location: 25..26,
|
||||
value: "1",
|
||||
base: Decimal {
|
||||
|
||||
@@ -9,7 +9,7 @@ Assignment {
|
||||
expressions: [
|
||||
Assignment {
|
||||
location: 12..21,
|
||||
value: Int {
|
||||
value: UInt {
|
||||
location: 20..21,
|
||||
value: "4",
|
||||
base: Decimal {
|
||||
@@ -30,7 +30,7 @@ Assignment {
|
||||
location: 25..26,
|
||||
name: "x",
|
||||
},
|
||||
right: Int {
|
||||
right: UInt {
|
||||
location: 29..30,
|
||||
value: "5",
|
||||
base: Decimal {
|
||||
|
||||
@@ -12,7 +12,7 @@ Sequence {
|
||||
CallArg {
|
||||
label: None,
|
||||
location: 16..17,
|
||||
value: Int {
|
||||
value: UInt {
|
||||
location: 16..17,
|
||||
value: "3",
|
||||
base: Decimal {
|
||||
@@ -124,21 +124,21 @@ Sequence {
|
||||
value: List {
|
||||
location: 77..88,
|
||||
elements: [
|
||||
Int {
|
||||
UInt {
|
||||
location: 79..80,
|
||||
value: "1",
|
||||
base: Decimal {
|
||||
numeric_underscore: false,
|
||||
},
|
||||
},
|
||||
Int {
|
||||
UInt {
|
||||
location: 82..83,
|
||||
value: "2",
|
||||
base: Decimal {
|
||||
numeric_underscore: false,
|
||||
},
|
||||
},
|
||||
Int {
|
||||
UInt {
|
||||
location: 85..86,
|
||||
value: "3",
|
||||
base: Decimal {
|
||||
|
||||
@@ -13,14 +13,14 @@ If {
|
||||
body: BinOp {
|
||||
location: 12..17,
|
||||
name: AddInt,
|
||||
left: Int {
|
||||
left: UInt {
|
||||
location: 12..13,
|
||||
value: "1",
|
||||
base: Decimal {
|
||||
numeric_underscore: false,
|
||||
},
|
||||
},
|
||||
right: Int {
|
||||
right: UInt {
|
||||
location: 16..17,
|
||||
value: "1",
|
||||
base: Decimal {
|
||||
@@ -38,7 +38,7 @@ If {
|
||||
location: 28..29,
|
||||
name: "a",
|
||||
},
|
||||
right: Int {
|
||||
right: UInt {
|
||||
location: 32..33,
|
||||
value: "1",
|
||||
base: Decimal {
|
||||
@@ -46,7 +46,7 @@ If {
|
||||
},
|
||||
},
|
||||
},
|
||||
body: Int {
|
||||
body: UInt {
|
||||
location: 38..39,
|
||||
value: "3",
|
||||
base: Decimal {
|
||||
@@ -56,7 +56,7 @@ If {
|
||||
location: 28..41,
|
||||
},
|
||||
],
|
||||
final_else: Int {
|
||||
final_else: UInt {
|
||||
location: 51..52,
|
||||
value: "4",
|
||||
base: Decimal {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
source: crates/aiken-lang/src/parser/expr/int.rs
|
||||
description: "Code:\n\n0x01"
|
||||
---
|
||||
Int {
|
||||
UInt {
|
||||
location: 0..4,
|
||||
value: "1",
|
||||
base: Hexadecimal,
|
||||
|
||||
@@ -5,21 +5,21 @@ description: "Code:\n\n[1, 2, 3]"
|
||||
List {
|
||||
location: 0..9,
|
||||
elements: [
|
||||
Int {
|
||||
UInt {
|
||||
location: 1..2,
|
||||
value: "1",
|
||||
base: Decimal {
|
||||
numeric_underscore: false,
|
||||
},
|
||||
},
|
||||
Int {
|
||||
UInt {
|
||||
location: 4..5,
|
||||
value: "2",
|
||||
base: Decimal {
|
||||
numeric_underscore: false,
|
||||
},
|
||||
},
|
||||
Int {
|
||||
UInt {
|
||||
location: 7..8,
|
||||
value: "3",
|
||||
base: Decimal {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
source: crates/aiken-lang/src/parser/expr/int.rs
|
||||
description: "Code:\n\n1"
|
||||
---
|
||||
Int {
|
||||
UInt {
|
||||
location: 0..1,
|
||||
value: "1",
|
||||
base: Decimal {
|
||||
|
||||
@@ -5,7 +5,7 @@ description: "Code:\n\n-1"
|
||||
UnOp {
|
||||
op: Negate,
|
||||
location: 0..2,
|
||||
value: Int {
|
||||
value: UInt {
|
||||
location: 1..2,
|
||||
value: "1",
|
||||
base: Decimal {
|
||||
|
||||
@@ -7,7 +7,7 @@ Sequence {
|
||||
expressions: [
|
||||
Assignment {
|
||||
location: 4..21,
|
||||
value: Int {
|
||||
value: UInt {
|
||||
location: 12..21,
|
||||
value: "1234567",
|
||||
base: Decimal {
|
||||
@@ -23,7 +23,7 @@ Sequence {
|
||||
},
|
||||
Assignment {
|
||||
location: 24..41,
|
||||
value: Int {
|
||||
value: UInt {
|
||||
location: 32..41,
|
||||
value: "1000000",
|
||||
base: Decimal {
|
||||
@@ -42,7 +42,7 @@ Sequence {
|
||||
value: UnOp {
|
||||
op: Negate,
|
||||
location: 52..59,
|
||||
value: Int {
|
||||
value: UInt {
|
||||
location: 53..59,
|
||||
value: "10000",
|
||||
base: Decimal {
|
||||
|
||||
@@ -7,14 +7,14 @@ Assignment {
|
||||
value: List {
|
||||
location: 12..23,
|
||||
elements: [
|
||||
Int {
|
||||
UInt {
|
||||
location: 14..15,
|
||||
value: "1",
|
||||
base: Decimal {
|
||||
numeric_underscore: false,
|
||||
},
|
||||
},
|
||||
Int {
|
||||
UInt {
|
||||
location: 17..18,
|
||||
value: "2",
|
||||
base: Decimal {
|
||||
|
||||
@@ -5,14 +5,14 @@ description: "Code:\n\n[1, 2, ..[]]"
|
||||
List {
|
||||
location: 0..12,
|
||||
elements: [
|
||||
Int {
|
||||
UInt {
|
||||
location: 1..2,
|
||||
value: "1",
|
||||
base: Decimal {
|
||||
numeric_underscore: false,
|
||||
},
|
||||
},
|
||||
Int {
|
||||
UInt {
|
||||
location: 4..5,
|
||||
value: "2",
|
||||
base: Decimal {
|
||||
|
||||
@@ -10,28 +10,28 @@ Sequence {
|
||||
value: Tuple {
|
||||
location: 12..24,
|
||||
elems: [
|
||||
Int {
|
||||
UInt {
|
||||
location: 13..14,
|
||||
value: "1",
|
||||
base: Decimal {
|
||||
numeric_underscore: false,
|
||||
},
|
||||
},
|
||||
Int {
|
||||
UInt {
|
||||
location: 16..17,
|
||||
value: "2",
|
||||
base: Decimal {
|
||||
numeric_underscore: false,
|
||||
},
|
||||
},
|
||||
Int {
|
||||
UInt {
|
||||
location: 19..20,
|
||||
value: "3",
|
||||
base: Decimal {
|
||||
numeric_underscore: false,
|
||||
},
|
||||
},
|
||||
Int {
|
||||
UInt {
|
||||
location: 22..23,
|
||||
value: "4",
|
||||
base: Decimal {
|
||||
|
||||
@@ -12,7 +12,7 @@ Sequence {
|
||||
CallArg {
|
||||
label: None,
|
||||
location: 12..14,
|
||||
value: Int {
|
||||
value: UInt {
|
||||
location: 12..14,
|
||||
value: "14",
|
||||
base: Decimal {
|
||||
@@ -41,7 +41,7 @@ Sequence {
|
||||
location: 17..18,
|
||||
name: "a",
|
||||
},
|
||||
Int {
|
||||
UInt {
|
||||
location: 20..22,
|
||||
value: "42",
|
||||
base: Decimal {
|
||||
|
||||
@@ -11,7 +11,7 @@ PipeLine {
|
||||
location: 0..1,
|
||||
name: "a",
|
||||
},
|
||||
right: Int {
|
||||
right: UInt {
|
||||
location: 4..5,
|
||||
value: "2",
|
||||
base: Decimal {
|
||||
|
||||
@@ -9,7 +9,7 @@ BinOp {
|
||||
location: 0..1,
|
||||
name: "a",
|
||||
},
|
||||
right: Int {
|
||||
right: UInt {
|
||||
location: 4..5,
|
||||
value: "1",
|
||||
base: Decimal {
|
||||
|
||||
@@ -36,7 +36,7 @@ Call {
|
||||
"thing",
|
||||
),
|
||||
location: 27..35,
|
||||
value: Int {
|
||||
value: UInt {
|
||||
location: 34..35,
|
||||
value: "2",
|
||||
base: Decimal {
|
||||
|
||||
@@ -36,7 +36,7 @@ Call {
|
||||
"thing",
|
||||
),
|
||||
location: 39..47,
|
||||
value: Int {
|
||||
value: UInt {
|
||||
location: 46..47,
|
||||
value: "2",
|
||||
base: Decimal {
|
||||
|
||||
@@ -7,7 +7,7 @@ Call {
|
||||
CallArg {
|
||||
label: None,
|
||||
location: 18..19,
|
||||
value: Int {
|
||||
value: UInt {
|
||||
location: 18..19,
|
||||
value: "1",
|
||||
base: Decimal {
|
||||
|
||||
@@ -2,10 +2,7 @@ use chumsky::prelude::*;
|
||||
|
||||
use crate::{
|
||||
expr::UntypedExpr,
|
||||
parser::{
|
||||
error::ParseError, literal::bytearray::utf8_string, literal::string::parser as string,
|
||||
token::Token,
|
||||
},
|
||||
parser::{error::ParseError, literal::string, literal::utf8_string, token::Token},
|
||||
};
|
||||
|
||||
pub fn parser() -> impl Parser<Token, UntypedExpr, Error = ParseError> {
|
||||
|
||||
@@ -39,7 +39,7 @@ When {
|
||||
),
|
||||
},
|
||||
),
|
||||
then: Int {
|
||||
then: UInt {
|
||||
location: 28..29,
|
||||
value: "3",
|
||||
base: Decimal {
|
||||
@@ -78,7 +78,7 @@ When {
|
||||
expressions: [
|
||||
Assignment {
|
||||
location: 51..66,
|
||||
value: Int {
|
||||
value: UInt {
|
||||
location: 65..66,
|
||||
value: "5",
|
||||
base: Decimal {
|
||||
@@ -111,7 +111,7 @@ When {
|
||||
},
|
||||
],
|
||||
guard: None,
|
||||
then: Int {
|
||||
then: UInt {
|
||||
location: 90..91,
|
||||
value: "9",
|
||||
base: Decimal {
|
||||
@@ -128,7 +128,7 @@ When {
|
||||
},
|
||||
],
|
||||
guard: None,
|
||||
then: Int {
|
||||
then: UInt {
|
||||
location: 99..100,
|
||||
value: "4",
|
||||
base: Decimal {
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
pub(crate) mod bytearray;
|
||||
pub(crate) mod int;
|
||||
pub(crate) mod string;
|
||||
mod bytearray;
|
||||
mod string;
|
||||
mod uint;
|
||||
|
||||
pub use bytearray::{array_of_bytes, hex_string, parser as bytearray, utf8_string};
|
||||
pub use string::parser as string;
|
||||
pub use uint::parser as uint;
|
||||
|
||||
Reference in New Issue
Block a user