diff --git a/Cargo.lock b/Cargo.lock index 594f213..024921a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -27,9 +27,9 @@ dependencies = [ [[package]] name = "adana-script-core" -version = "0.14.2" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23e3ed3e01d63db1361db5c4cf2b1053bdfac8d5e80f70cc25439e40fac842c8" +checksum = "48cb963f08f0acb3c4c5d9dcaa6b3963de537560e50d08c706efe22730b781ce" dependencies = [ "anyhow", "libloading", @@ -297,9 +297,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.14.0" +version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" +checksum = "7dfda62a12f55daeae5015f81b0baea145391cb4520f86c248fc615d72640d12" [[package]] name = "heck" @@ -336,9 +336,9 @@ checksum = "9cdc71e17332e86d2e1d38c1f99edcb6288ee11b815fb1a4b049eaa2114d369b" [[package]] name = "libloading" -version = "0.8.0" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d580318f95776505201b28cf98eb1fa5e4be3b689633ba6a3e6cd880ff22d8cb" +checksum = "c571b676ddfc9a8c12f1f3d3085a7b163966a8fd8098a90640953ce5f6170161" dependencies = [ "cfg-if", "windows-sys", @@ -346,9 +346,9 @@ dependencies = [ [[package]] name = "linux-raw-sys" -version = "0.4.7" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a9bad9f94746442c783ca431b22403b519cd7fbeed0533fdd6328b2f2212128" +checksum = "3852614a3bd9ca9804678ba6be5e3b8ce76dfc902cae004e3e0c44051b6e88db" [[package]] name = "lock_api" @@ -534,9 +534,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.9.5" +version = "1.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "697061221ea1b4a94a624f67d0ae2bfe4e22b8a17b6a192afb11046542cc8c47" +checksum = "ebee201405406dbf528b8b672104ae6d6d63e6d118cb10e4d51abbc7b58044ff" dependencies = [ "aho-corasick", "memchr", @@ -546,9 +546,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.3.8" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2f401f4955220693b56f8ec66ee9c78abffd8d1c4f23dc41a23839eb88f0795" +checksum = "59b23e92ee4318893fa3fe3e6fb365258efbfe6ac6ab30f090cdcbb7aa37efa9" dependencies = [ "aho-corasick", "memchr", @@ -563,9 +563,9 @@ checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da" [[package]] name = "rustix" -version = "0.38.14" +version = "0.38.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "747c788e9ce8e92b12cd485c49ddf90723550b654b32508f979b71a7b1ecda4f" +checksum = "d2f9da0cbd88f9f09e7814e388301c8414c51c62aa6ce1e4b5c551d49d96e531" dependencies = [ "bitflags 2.4.0", "errno", diff --git a/Cargo.toml b/Cargo.toml index ad068dd..ba92cf7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,7 @@ anyhow = "1.0.75" bincode = "1.3.3" dirs = "5.0.1" # todo maybe replace by the home crate log = "0.4.20" -nom = { version = "7.1.3" } +nom = "7.1.3" nu-ansi-term = "0.49.0" rustyline = "12.0.0" rustyline-derive = "0.9.0" @@ -36,8 +36,8 @@ slab_tree = "0.3.2" strum = { version = "0.25.0", features = ["derive"] } ctrlc = "3.4.1" -#adana-script-core = { git = "https://github.com/nbittich/adana-script-core.git" } -adana-script-core = "0.14.2" +#adana-script-core = { git = "https://github.com/nbittich/adana-script-core.git", branch = "feature/bitwise-and-new-ints" } +adana-script-core = "0.15.0" [dependencies.env_logger] default-features = false diff --git a/README.md b/README.md index 2baf3db..e372838 100644 --- a/README.md +++ b/README.md @@ -172,7 +172,7 @@ ${person.wasup(person.age)}""" ### Operators and constants -There are 16 operators & 3 constants: +There are 22 operators & 3 constants: | **operator** | **description** | | ------------ | ---------------- | @@ -190,6 +190,12 @@ There are 16 operators & 3 constants: | `>=` | greater or equal | | `&&` | and | | `\|\|` | or | +| `\|` | bitwise or | +| `~` | bitwise not | +| `@` | bitwise and | +| `$` | bitwise xor | +| `<<` | bitwise lshift | +| `>>` | bitwise rshift | | `==` | equal | | `()` | parenthesis | | `π` | PI number | @@ -482,7 +488,9 @@ Below, is a list of types and how you declare them. You can also define your str | -------- | ------------------------------------------------------------------------------------------------ | | null | `null` | | bool | `true` / `false` | -| int | `5` | +| int | `5000` | +| u8 | `5` | +| i8 | `-5` | | double | `12.` / `12.2` | | string | `"hello"` | | array | `[1,2,"3", true]` | @@ -717,6 +725,8 @@ Here is a list of built-in functions available: | include | include a script | `include("scripts/test_fn.adana")` | | require | load a shared object | `require("my_lib.so")` | | to_int | cast to int | `to_int("2")`
`to_int(2.2)` | +| to_hex | format num to hex | `to_hex(2)`
`to_hex(2.2)` | +| to_binary | format num to binary | `to_binary(2)` | | to_double | cast to double | `to_double("2.2")` | | to_bool | cast to bool | `to_bool("true")` | | to_string | cast to string | `to_string(true)` | diff --git a/dynamic_lib/example_lib_src/Cargo.lock b/dynamic_lib/example_lib_src/Cargo.lock index 7ce8960..18f68ee 100644 --- a/dynamic_lib/example_lib_src/Cargo.lock +++ b/dynamic_lib/example_lib_src/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "adana-script-core" -version = "0.14.1" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67c04fcdd5b5c568011e9f148e9cc45a35db86e63d5c7d632b1eb82790e6edcf" +checksum = "48cb963f08f0acb3c4c5d9dcaa6b3963de537560e50d08c706efe22730b781ce" dependencies = [ "anyhow", "libloading", @@ -35,9 +35,9 @@ checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] name = "libloading" -version = "0.8.0" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d580318f95776505201b28cf98eb1fa5e4be3b689633ba6a3e6cd880ff22d8cb" +checksum = "c571b676ddfc9a8c12f1f3d3085a7b163966a8fd8098a90640953ce5f6170161" dependencies = [ "cfg-if", "windows-sys", diff --git a/dynamic_lib/example_lib_src/Cargo.toml b/dynamic_lib/example_lib_src/Cargo.toml index 2a7df43..69322d5 100644 --- a/dynamic_lib/example_lib_src/Cargo.toml +++ b/dynamic_lib/example_lib_src/Cargo.toml @@ -9,7 +9,9 @@ edition = "2021" crate-type = ["dylib"] [dependencies] -adana-script-core = "0.14.1" +adana-script-core = "0.15.0" +#adana-script-core = { git = "https://github.com/nbittich/adana-script-core.git", branch = "feature/bitwise-and-new-ints" } + anyhow = "1.0.75" [profile.release] diff --git a/dynamic_lib/libplugin_example.so b/dynamic_lib/libplugin_example.so index 325e507..cd0baa3 100755 Binary files a/dynamic_lib/libplugin_example.so and b/dynamic_lib/libplugin_example.so differ diff --git a/src/adana_script/ast.rs b/src/adana_script/ast.rs index 563259d..18a6340 100644 --- a/src/adana_script/ast.rs +++ b/src/adana_script/ast.rs @@ -99,7 +99,7 @@ pub fn to_ast( Value::ImplicitMultiply(v) if matches!( v.borrow(), - &Value::Integer(_) | &Value::Decimal(_) + &Value::Integer(_) | &Value::Decimal(_) | &Value::U8(_) | &Value::I8(_) ) => { operations.insert(pos,*v); @@ -107,11 +107,11 @@ pub fn to_ast( } Value::Operation(Operator::Pow2) => { operations.insert(pos,Value::Operation(Operator::Pow)); - operations.insert(pos+1,Value::Integer(2)); + operations.insert(pos+1,Value::U8(2)); } Value::Operation(Operator::Pow3) => { operations.insert(pos,Value::Operation(Operator::Pow)); - operations.insert(pos+1,Value::Integer(3)); + operations.insert(pos+1,Value::U8(3)); } _ => unreachable!("AST ERROR: unreachable implicit parameter {operation:?}"), } @@ -120,18 +120,24 @@ pub fn to_ast( let get_next_op_pos = |operations: &Vec| { None.or_else(filter_op(Operator::Or, operations)) .or_else(filter_op(Operator::And, operations)) + .or_else(filter_op(Operator::BitwiseOr, operations)) + .or_else(filter_op(Operator::BitwiseXor, operations)) + .or_else(filter_op(Operator::BitwiseAnd, operations)) .or_else(filter_op(Operator::GreaterOrEqual, operations)) .or_else(filter_op(Operator::LessOrEqual, operations)) .or_else(filter_op(Operator::Greater, operations)) .or_else(filter_op(Operator::Less, operations)) .or_else(filter_op(Operator::Equal, operations)) .or_else(filter_op(Operator::NotEqual, operations)) + .or_else(filter_op(Operator::BitwiseLShift, operations)) + .or_else(filter_op(Operator::BitwiseRShift, operations)) .or_else(filter_op(Operator::Add, operations)) .or_else(filter_op(Operator::Subtr, operations)) .or_else(filter_op(Operator::Mult, operations)) .or_else(filter_op(Operator::Mod, operations)) .or_else(filter_op(Operator::Div, operations)) .or_else(filter_op(Operator::Pow, operations)) + .or_else(filter_op(Operator::BitwiseNot, operations)) .or_else(filter_op(Operator::Not, operations)) }; @@ -145,25 +151,55 @@ pub fn to_ast( // handle negation if operation == Value::Operation(Operator::Subtr) - && matches!( - left.last(), - Some( - Value::Operation(Operator::Subtr) + // || operation == Value::Operation(Operator::BitwiseNot) maybe needed + // but maybe not + && matches!( + left.last(), + Some( + Value::Operation(Operator::Subtr) | Value::Operation(Operator::Mult) | Value::Operation(Operator::Pow) + | Value::Operation(Operator::BitwiseNot) + | Value::Operation(Operator::BitwiseAnd) + | Value::Operation(Operator::BitwiseLShift) + | Value::Operation(Operator::BitwiseRShift) + | Value::Operation(Operator::BitwiseOr) + | Value::Operation(Operator::BitwiseXor) | Value::Operation(Operator::Add) // FIXME too tired to think about // it. Is it needed? | Value::Operation(Operator::Mod) | Value::Operation(Operator::Div) + ) ) - ) { - let right_first = match operations.first() { - Some(Value::Decimal(d)) => Some(Value::Decimal(-d)), - Some(Value::Integer(d)) => Some(Value::Integer(-d)), - Some(Value::Variable(d)) => { - Some(Value::VariableNegate(d.to_string())) - } + let right_first = match (&operation, operations.first()) { + ( + Value::Operation(Operator::Subtr), + Some(Value::Decimal(d)), + ) => Some(Value::Decimal(-d)), + ( + Value::Operation(Operator::Subtr), + Some(Value::Integer(d)), + ) => Some(Value::Integer(-d)), + ( + Value::Operation(Operator::Subtr), + Some(Value::U8(d)), + ) => (*d as i8) + .checked_neg() + .map(Value::I8) + .or_else(|| Some(Value::Integer(-(*d as i128)))), + + ( + Value::Operation(Operator::Subtr), + Some(Value::I8(d)), + ) => d + .checked_neg() + .map(Value::I8) + .or_else(|| Some(Value::Integer(-(*d as i128)))), + ( + Value::Operation(Operator::Subtr), + Some(Value::Variable(d)), + ) => Some(Value::VariableNegate(d.to_string())), _ => None, }; if let Some(first) = right_first { @@ -203,7 +239,7 @@ pub fn to_ast( Ok(curr_node_id) } else { Err(anyhow::Error::msg(format!( - "{} invalid expression!", + "{} invalid expression! {op_pos:?}", nu_ansi_term::Color::Red.paint("AST ERROR:") ))) } @@ -246,6 +282,16 @@ pub fn to_ast( tree, curr_node_id, ), + Value::U8(num) => append_to_current_and_return( + TreeNodeValue::Primitive(Primitive::U8(num)), + tree, + curr_node_id, + ), + Value::I8(num) => append_to_current_and_return( + TreeNodeValue::Primitive(Primitive::I8(num)), + tree, + curr_node_id, + ), Value::Bool(bool_v) => append_to_current_and_return( TreeNodeValue::Primitive(Primitive::Bool(bool_v)), tree, @@ -266,16 +312,19 @@ pub fn to_ast( Value::Variable(name) | Value::VariableRef(name) => { let primitive = variable_from_ctx(name.as_str(), false, ctx)?; - if let Primitive::Int(num) = primitive.to_int() { - Ok(num) - } else { - Err(anyhow::format_err!( + match primitive.to_int() { + Primitive::Int(num) => Ok(num), + Primitive::U8(num) => Ok(num as i128), + Primitive::I8(num) => Ok(num as i128), + _ => Err(anyhow::format_err!( "range error: {primitive:?} is not an integer" - )) + )), } } Value::Integer(num) => Ok(num), + Value::U8(num) => Ok(num as i128), + Value::I8(num) => Ok(num as i128), _ => { return Err(anyhow::format_err!( "range error: {start:?} is not an integer" @@ -286,14 +335,17 @@ pub fn to_ast( Value::Variable(name) | Value::VariableRef(name) => { let primitive = variable_from_ctx(name.as_str(), false, ctx)?; - if let Primitive::Int(num) = primitive.to_int() { - Ok(num) - } else { - Err(anyhow::format_err!( + match primitive.to_int() { + Primitive::Int(num) => Ok(num), + Primitive::U8(num) => Ok(num as i128), + Primitive::I8(num) => Ok(num as i128), + _ => Err(anyhow::format_err!( "range error: {primitive:?} is not an integer" - )) + )), } } + Value::U8(num) => Ok(num as i128), + Value::I8(num) => Ok(num as i128), Value::Integer(num) => Ok(num), _ => { return Err(anyhow::format_err!( @@ -465,6 +517,16 @@ pub fn to_ast( tree, curr_node_id, ), + (v, index @ Value::U8(_)) => append_to_current_and_return( + TreeNodeValue::ArrayAccess { index, array: v }, + tree, + curr_node_id, + ), + (v, index @ Value::I8(_)) => append_to_current_and_return( + TreeNodeValue::ArrayAccess { index, array: v }, + tree, + curr_node_id, + ), (v, variable @ Value::Variable(_)) => append_to_current_and_return( TreeNodeValue::ArrayAccess { index: variable, array: v }, tree, diff --git a/src/adana_script/compute.rs b/src/adana_script/compute.rs index 2ec9f22..6bfc6ba 100644 --- a/src/adana_script/compute.rs +++ b/src/adana_script/compute.rs @@ -13,9 +13,9 @@ use crate::{adana_script::parser::parse_instructions, prelude::BTreeMap}; use super::{ast::to_ast, require_dynamic_lib::require_dynamic_lib}; use adana_script_core::{ primitive::{ - Abs, Add, And, Array, Cos, Div, Logarithm, Mul, Neg, Not, Or, Pow, - Primitive, RefPrimitive, Rem, Sin, Sqrt, Sub, Tan, ToBool, ToNumber, - TypeOf, + Abs, Add, And, Array, BitShift, Cos, DisplayBinary, DisplayHex, Div, + Logarithm, Mul, Neg, Not, Or, Pow, Primitive, RefPrimitive, Rem, Sin, + Sqrt, Sub, Tan, ToBool, ToNumber, TypeOf, }, BuiltInFunctionType, Operator, TreeNodeValue, Value, }; @@ -58,6 +58,15 @@ fn compute_recur( let left = compute_recur(node.first_child(), ctx, shared_lib)?; Ok(left.not()) } + TreeNodeValue::Ops(Operator::BitwiseNot) => { + if node.children().count() != 1 { + return Err(Error::msg( + "only one value allowed, no '~' possible", + )); + } + let left = compute_recur(node.first_child(), ctx, shared_lib)?; + Ok(left.bitwise_not()) + } TreeNodeValue::Ops(Operator::Add) => { if node.children().count() == 1 { return compute_recur(node.first_child(), ctx, shared_lib); @@ -141,6 +150,32 @@ fn compute_recur( let right = compute_recur(node.last_child(), ctx, shared_lib)?; Ok(left.and(&right)) } + TreeNodeValue::Ops(Operator::BitwiseAnd) => { + if node.children().count() == 1 { + return Err(Error::msg( + "only one value, no 'AND' comparison possible", + )); + } + let left = compute_recur(node.first_child(), ctx, shared_lib)?; + let right = compute_recur(node.last_child(), ctx, shared_lib)?; + Ok(left.bitwise_and(&right)) + } + TreeNodeValue::Ops(Operator::BitwiseLShift) => { + if node.children().count() == 1 { + return Err(Error::msg("only one value for '<<' ")); + } + let left = compute_recur(node.first_child(), ctx, shared_lib)?; + let right = compute_recur(node.last_child(), ctx, shared_lib)?; + Ok(left.left_shift(&right)) + } + TreeNodeValue::Ops(Operator::BitwiseRShift) => { + if node.children().count() == 1 { + return Err(Error::msg("only one value, for '>>'")); + } + let left = compute_recur(node.first_child(), ctx, shared_lib)?; + let right = compute_recur(node.last_child(), ctx, shared_lib)?; + Ok(left.right_shift(&right)) + } TreeNodeValue::VariableUnused => { Err(Error::msg("forbidden usage of VariableUnused")) } @@ -168,6 +203,28 @@ fn compute_recur( let right = compute_recur(node.last_child(), ctx, shared_lib)?; Ok(left.or(&right)) } + + TreeNodeValue::Ops(Operator::BitwiseOr) => { + if node.children().count() == 1 { + return Err(Error::msg( + "only one value, no '|' comparison possible", + )); + } + let left = compute_recur(node.first_child(), ctx, shared_lib)?; + let right = compute_recur(node.last_child(), ctx, shared_lib)?; + Ok(left.bitwise_or(&right)) + } + + TreeNodeValue::Ops(Operator::BitwiseXor) => { + if node.children().count() == 1 { + return Err(Error::msg( + "only one value, no 'XOR' comparison possible", + )); + } + let left = compute_recur(node.first_child(), ctx, shared_lib)?; + let right = compute_recur(node.last_child(), ctx, shared_lib)?; + Ok(left.bitwise_xor(&right)) + } TreeNodeValue::Ops(Operator::Equal) => { if node.children().count() == 1 { return Err(Error::msg( @@ -273,6 +330,13 @@ fn compute_recur( adana_script_core::BuiltInFunctionType::ToInt => { Ok(v.to_int()) } + adana_script_core::BuiltInFunctionType::ToHex => { + Ok(v.to_hex()) + } + adana_script_core::BuiltInFunctionType::ToBinary => { + Ok(v.to_binary()) + } + adana_script_core::BuiltInFunctionType::ToDouble => { Ok(v.to_double()) } @@ -453,13 +517,19 @@ fn compute_recur( Ok(v.index_at(&index)) } (Value::Array(array), index) => { - let Primitive::Int(index) = - compute_lazy(index.clone(), ctx, shared_lib)? - else { - return Err(anyhow::format_err!( + let index = + match compute_lazy(index.clone(), ctx, shared_lib)? + { + Primitive::Int(index) => index as usize, + Primitive::U8(index) => index as usize, + Primitive::I8(index) => index as usize, + + _ => { + return Err(anyhow::format_err!( "COMPUTE: illegal array access! {index:?}" - )); - }; + )) + } + }; let index = index as usize; let value = array.get(index).context(error_message())?; @@ -764,10 +834,13 @@ fn compute_recur( .ok_or_else(||anyhow::format_err!("ctx doesn't contains array {s}"))?; let mut array = array.write() .map_err(|e| anyhow::format_err!("DROP ARRAY : could not acquire lock {e}"))?; - let Value::Integer(index) = *index.clone() else { - return Ok(PrimErr("index not an int!".to_string())) - }; - array.remove(&Int(index))?; + match index.borrow() { + Value::Integer(i) => { array.remove(&Int(*i))}, + Value::U8(i) => { array.remove(&Primitive::U8(*i))}, + Value::I8(i) => { array.remove(&Primitive::I8(*i))}, + e => return Ok(PrimErr(format!("index not an int! {e:?}"))) + + }?; } _ => return Ok(PrimErr(format!("only primitive within the ctx can be dropped {arr:?}"))) } diff --git a/src/adana_script/parser.rs b/src/adana_script/parser.rs index cc8bb11..9b4be78 100644 --- a/src/adana_script/parser.rs +++ b/src/adana_script/parser.rs @@ -1,11 +1,14 @@ -use nom::error::{Error, ErrorKind}; +use nom::{ + combinator::recognize, + error::{Error, ErrorKind}, +}; use crate::{ prelude::{ all_consuming, alt, delimited, double, many0, many1, map, map_parser, multispace0, one_of, opt, pair, peek, preceded, recognize_float, rest, separated_list0, separated_list1, separated_pair, tag, take_until, - take_while1, terminated, tuple, verify, Res, I128, + take_while1, terminated, tuple, verify, Res, I128, I8, U8, }, reserved_keywords::check_reserved_keyword, }; @@ -26,15 +29,81 @@ pub(super) fn comments(s: &str) -> Res> { fn tag_no_space<'a>(t: &'a str) -> impl Fn(&'a str) -> Res<&'a str> { move |s: &str| delimited(multispace0, tag(t), multispace0)(s) } - +fn recognize_hexadecimal(input: &str) -> Res<&str> { + // <'a, E: ParseError<&'a str>> + preceded( + alt((tag("0x"), tag("0X"))), + recognize(many1(terminated( + one_of("0123456789abcdefABCDEF"), + many0(nom::character::complete::char('_')), + ))), + )(input) +} +fn recognize_binary(input: &str) -> Res<&str> { + preceded( + alt((tag("0b"), tag("0B"))), + recognize(many1(terminated( + one_of("01"), + many0(nom::character::complete::char('_')), + ))), + )(input) +} + +fn parse_u8_binary(s: &str) -> Res { + let r = u8::from_str_radix(s, 2).map_err(|_e| { + nom::Err::Error(nom::error::make_error::<&str, Error<&str>>( + "could not parse radix", + ErrorKind::IsNot, + )) + })?; + Ok(("", Value::U8(r))) +} + +fn parse_i128_binary(s: &str) -> Res { + let r = i128::from_str_radix(s, 2).map_err(|_e| { + nom::Err::Error(nom::error::make_error::<&str, Error<&str>>( + "could not parse radix", + ErrorKind::IsNot, + )) + })?; + Ok(("", Value::Integer(r))) +} + +fn parse_u8_hex(s: &str) -> Res { + let r = u8::from_str_radix(s, 16).map_err(|_e| { + nom::Err::Error(nom::error::make_error::<&str, Error<&str>>( + "could not parse radix", + ErrorKind::IsNot, + )) + })?; + Ok(("", Value::U8(r))) +} + +fn parse_i128_hex(s: &str) -> Res { + let r = i128::from_str_radix(s, 16).map_err(|_e| { + nom::Err::Error(nom::error::make_error::<&str, Error<&str>>( + "could not parse radix", + ErrorKind::IsNot, + )) + })?; + Ok(("", Value::Integer(r))) +} fn parse_number(s: &str) -> Res { - map_parser( - recognize_float, - alt(( - map(all_consuming(I128), Value::Integer), - map(all_consuming(double), Value::Decimal), - )), - )(s) + alt(( + map_parser(recognize_binary, parse_u8_binary), + map_parser(recognize_binary, parse_i128_binary), + map_parser(recognize_hexadecimal, parse_u8_hex), + map_parser(recognize_hexadecimal, parse_i128_hex), + map_parser( + recognize_float, + alt(( + map(all_consuming(U8), Value::U8), + map(all_consuming(I8), Value::I8), + map(all_consuming(I128), Value::Integer), + map(all_consuming(double), Value::Decimal), + )), + ), + ))(s) } fn parse_range(s: &str) -> Res { @@ -333,6 +402,8 @@ fn parse_builtin_fn(s: &str) -> Res { parse_builtin(BuiltInFunctionType::Cos), parse_builtin(BuiltInFunctionType::ToInt), parse_builtin(BuiltInFunctionType::ToDouble), + parse_builtin(BuiltInFunctionType::ToHex), + parse_builtin(BuiltInFunctionType::ToBinary), parse_builtin(BuiltInFunctionType::TypeOf), parse_builtin(BuiltInFunctionType::ToBool), parse_builtin(BuiltInFunctionType::ToString), @@ -443,7 +514,18 @@ fn parse_array_access(s: &str) -> Res { index: Box::new(v), }; } - + v @ Value::U8(_) => { + array_access = Value::ArrayAccess { + arr: Box::new(array_access), + index: Box::new(v), + }; + } + v @ Value::I8(_) => { + array_access = Value::ArrayAccess { + arr: Box::new(array_access), + index: Box::new(v), + }; + } Value::String(s) => { array_access = Value::StructAccess { struc: Box::new(array_access), @@ -511,7 +593,19 @@ fn parse_struct_access(s: &str) -> Res { index: Box::new(v), }; } + v @ Value::U8(_) => { + struc_access = Value::ArrayAccess { + arr: Box::new(struc_access), + index: Box::new(v), + }; + } + v @ Value::I8(_) => { + struc_access = Value::ArrayAccess { + arr: Box::new(struc_access), + index: Box::new(v), + }; + } Value::String(s) => { struc_access = Value::StructAccess { struc: Box::new(struc_access), @@ -582,6 +676,8 @@ fn parse_operation(s: &str) -> Res { parse_op(Operator::Subtr), parse_op(Operator::LessOrEqual), parse_op(Operator::GreaterOrEqual), + parse_op(Operator::BitwiseLShift), + parse_op(Operator::BitwiseRShift), parse_op(Operator::Less), parse_op(Operator::Greater), parse_op(Operator::Equal), @@ -589,6 +685,13 @@ fn parse_operation(s: &str) -> Res { parse_op(Operator::Not), parse_op(Operator::And), parse_op(Operator::Or), + parse_op(Operator::Or), + alt(( + parse_op(Operator::BitwiseNot), + parse_op(Operator::BitwiseAnd), + parse_op(Operator::BitwiseOr), + parse_op(Operator::BitwiseXor), + )), ))(s) } diff --git a/src/adana_script/tests/bitwise.rs b/src/adana_script/tests/bitwise.rs new file mode 100644 index 0000000..53aeaae --- /dev/null +++ b/src/adana_script/tests/bitwise.rs @@ -0,0 +1,139 @@ +use std::collections::BTreeMap; + +use adana_script_core::primitive::Primitive; + +use crate::adana_script::compute; + +#[test] +fn bitwise_or_test() { + let mut ctx = BTreeMap::new(); + + let r = compute(r#"1|2"#, &mut ctx, "N/A").unwrap(); + assert_eq!(r, Primitive::U8(3)); + let r = compute(r#"1|1"#, &mut ctx, "N/A").unwrap(); + assert_eq!(r, Primitive::U8(1)); + let r = compute(r#"1|0"#, &mut ctx, "N/A").unwrap(); + assert_eq!(r, Primitive::U8(1)); + let r = compute(r#"0|0"#, &mut ctx, "N/A").unwrap(); + assert_eq!(r, Primitive::U8(0)); + let r = compute(r#"127|135"#, &mut ctx, "N/A").unwrap(); + assert_eq!(r, Primitive::U8(255)); + let r = compute(r#"127|9"#, &mut ctx, "N/A").unwrap(); + assert_eq!(r, Primitive::U8(127)); + let r = compute(r#"-1|1"#, &mut ctx, "N/A").unwrap(); + assert_eq!(r, Primitive::Int(-1)); + let r = compute(r#"-98|1"#, &mut ctx, "N/A").unwrap(); + assert_eq!(r, Primitive::Int(-97)); +} + +#[test] +fn bitwise_xor_test() { + let mut ctx = BTreeMap::new(); + + let r = compute(r#"1$2"#, &mut ctx, "N/A").unwrap(); + assert_eq!(r, Primitive::U8(3)); + let r = compute(r#"1$1"#, &mut ctx, "N/A").unwrap(); + assert_eq!(r, Primitive::U8(0)); + let r = compute(r#"1$0"#, &mut ctx, "N/A").unwrap(); + assert_eq!(r, Primitive::U8(1)); + let r = compute(r#"0$0"#, &mut ctx, "N/A").unwrap(); + assert_eq!(r, Primitive::U8(0)); + let r = compute(r#"127$135"#, &mut ctx, "N/A").unwrap(); + assert_eq!(r, Primitive::U8(248)); + let r = compute(r#"127$9"#, &mut ctx, "N/A").unwrap(); + assert_eq!(r, Primitive::U8(118)); + let r = compute(r#"-1$1"#, &mut ctx, "N/A").unwrap(); + assert_eq!(r, Primitive::Int(-2)); + let r = compute(r#"-98$1"#, &mut ctx, "N/A").unwrap(); + assert_eq!(r, Primitive::Int(-97)); +} + +#[test] +fn bitwise_not() { + let mut ctx = BTreeMap::new(); + + let r = compute(r#"~255"#, &mut ctx, "N/A").unwrap(); + assert_eq!(r, Primitive::Int(-256)); + let r = compute(r#"~127"#, &mut ctx, "N/A").unwrap(); + assert_eq!(r, Primitive::Int(-128)); + let r = compute(r#"~128"#, &mut ctx, "N/A").unwrap(); + assert_eq!(r, Primitive::Int(-129)); +} + +#[test] +fn bitwise_and() { + let mut ctx = BTreeMap::new(); + + let r = compute(r#"1@2"#, &mut ctx, "N/A").unwrap(); + assert_eq!(r, Primitive::U8(1 & 2)); + let r = compute(r#"1@1"#, &mut ctx, "N/A").unwrap(); + assert_eq!(r, Primitive::U8(1)); + let r = compute(r#"1@0"#, &mut ctx, "N/A").unwrap(); + assert_eq!(r, Primitive::U8(0)); + let r = compute(r#"0@0"#, &mut ctx, "N/A").unwrap(); + assert_eq!(r, Primitive::U8(0)); + let r = compute(r#"127@135"#, &mut ctx, "N/A").unwrap(); + assert_eq!(r, Primitive::U8(127 & 135)); + let r = compute(r#"127@9"#, &mut ctx, "N/A").unwrap(); + assert_eq!(r, Primitive::U8(127 & 9)); + let r = compute(r#"-1@1"#, &mut ctx, "N/A").unwrap(); + assert_eq!(r, Primitive::Int(1)); + let r = compute(r#"-98@1"#, &mut ctx, "N/A").unwrap(); + assert_eq!(r, Primitive::Int(-98 & 1)); +} + +#[test] +fn test_left_shift() { + let mut ctx = BTreeMap::new(); + + let r = compute(r#"1<<2"#, &mut ctx, "N/A").unwrap(); + assert_eq!(r, Primitive::Int(1 << 2)); + let r = compute(r#"1 <<1"#, &mut ctx, "N/A").unwrap(); + assert_eq!(r, Primitive::Int(1 << 1)); + let r = compute(r#"1<< 0"#, &mut ctx, "N/A").unwrap(); + assert_eq!(r, Primitive::Int(1 << 0)); + let r = compute(r#"0 << 0"#, &mut ctx, "N/A").unwrap(); + assert_eq!(r, Primitive::Int(0)); + // FIXME probably need to use a library for this + // let r = compute(r#"127 <<135"#, &mut ctx, "N/A").unwrap(); + // assert_eq!(r, Primitive::Int((127u64 << 135u64) as i128)); + let r = compute(r#"127<<9"#, &mut ctx, "N/A").unwrap(); + assert_eq!(r, Primitive::Int(127 << 9)); + let r = compute(r#"-1 << 1"#, &mut ctx, "N/A").unwrap(); + assert_eq!(r, Primitive::Int(-1 << 1)); + let r = compute(r#"-98 << 1"#, &mut ctx, "N/A").unwrap(); + assert_eq!(r, Primitive::Int(-98 << 1)); +} + +#[test] +fn test_right_shift() { + let mut ctx = BTreeMap::new(); + + let r = compute(r#"1>>2"#, &mut ctx, "N/A").unwrap(); + assert_eq!(r, Primitive::Int(1 >> 2)); + let r = compute(r#"1 >>1"#, &mut ctx, "N/A").unwrap(); + assert_eq!(r, Primitive::Int(1 >> 1)); + let r = compute(r#"1>> 0"#, &mut ctx, "N/A").unwrap(); + assert_eq!(r, Primitive::Int(1)); + let r = compute(r#"0 >> 0"#, &mut ctx, "N/A").unwrap(); + assert_eq!(r, Primitive::Int(0)); + // FIXME probably need to use a library for this + // let r = compute(r#"127 >>135"#, &mut ctx, "N/A").unwrap(); + // assert_eq!(r, Primitive::Int((127u64 >> 135u64) as i128)); + let r = compute(r#"127>>9"#, &mut ctx, "N/A").unwrap(); + assert_eq!(r, Primitive::Int(127 >> 9)); + let r = compute(r#"-1 >> 1"#, &mut ctx, "N/A").unwrap(); + assert_eq!(r, Primitive::Int(-1 >> 1)); + let r = compute(r#"-98 >> 1"#, &mut ctx, "N/A").unwrap(); + assert_eq!(r, Primitive::Int(-98 >> 1)); +} +#[test] +fn test_complex_math_wise() { + let mut ctx = BTreeMap::new(); + + let r = compute(r#"30*9 @9 -5/~3"#, &mut ctx, "N/A").unwrap(); + assert_eq!(r, Primitive::Int(((30 * 9) & (9 - 5 / !3)) as i128)); + + let r = compute(r#"30*9 @9 -5/~3 << 1"#, &mut ctx, "N/A").unwrap(); + assert_eq!(r, Primitive::Int(((30 * 9) & (9 - 5 / !3) << 1) as i128)); +} diff --git a/src/adana_script/tests/builtin.rs b/src/adana_script/tests/builtin.rs index 6135d19..3399dbf 100644 --- a/src/adana_script/tests/builtin.rs +++ b/src/adana_script/tests/builtin.rs @@ -6,9 +6,14 @@ use adana_script_core::primitive::Primitive; fn test_builtin_to_int() { let mut ctx = BTreeMap::new(); let res = compute("to_int(2)", &mut ctx, "N/A").unwrap(); - assert_eq!(res, Primitive::Int(2)); + assert_eq!(res, Primitive::U8(2)); + + let res = compute("to_int(256)", &mut ctx, "N/A").unwrap(); + assert_eq!(res, Primitive::Int(256)); + let res = compute(r#"to_int("2")"#, &mut ctx, "N/A").unwrap(); assert_eq!(res, Primitive::Int(2)); + ctx.insert( "a".to_string(), Primitive::String("123".to_string()).ref_prim(), @@ -45,6 +50,27 @@ fn test_eval() { assert_eq!(*ctx["z"].read().unwrap(), Primitive::Double(3.0)); } +#[test] +fn test_to_hex() { + let mut ctx = BTreeMap::new(); + let r = compute(r#"to_hex(255)"#, &mut ctx, "N/A").unwrap(); + assert_eq!(r, Primitive::String("0xff".into())); + let r = compute(r#"to_hex(1)"#, &mut ctx, "N/A").unwrap(); + assert_eq!(r, Primitive::String("0x1".into())); + let r = compute(r#"to_hex(1024)"#, &mut ctx, "N/A").unwrap(); + assert_eq!(r, Primitive::String("0x400".into())); +} + +#[test] +fn test_to_binary() { + let mut ctx = BTreeMap::new(); + let r = compute(r#"to_binary(255)"#, &mut ctx, "N/A").unwrap(); + assert_eq!(r, Primitive::String("0b11111111".into())); + let r = compute(r#"to_binary(-127)"#, &mut ctx, "N/A").unwrap(); + assert_eq!(r, Primitive::String("0b10000001".into())); + let r = compute(r#"to_binary(127)"#, &mut ctx, "N/A").unwrap(); + assert_eq!(r, Primitive::String("0b1111111".into())); +} #[test] fn test_type_of() { let mut ctx = BTreeMap::new(); diff --git a/src/adana_script/tests/examples.rs b/src/adana_script/tests/examples.rs index 33f5bd9..b4ba9ac 100644 --- a/src/adana_script/tests/examples.rs +++ b/src/adana_script/tests/examples.rs @@ -16,17 +16,17 @@ fn test_example1() { Struct(BTreeMap::from([ ("first_name".into(), String("John".into(),)), ("last_name".into(), String("Doe".into(),)), - ("note".into(), Int(18,)), + ("note".into(), U8(18,)), ])), Struct(BTreeMap::from([ ("first_name".into(), String("Jane".into(),)), ("last_name".into(), String("Dow".into(),)), - ("note".into(), Int(9,)), + ("note".into(), U8(9,)), ])), Struct(BTreeMap::from([ ("first_name".into(), String("Bryan".into(),)), ("last_name".into(), String("Bower".into(),)), - ("note".into(), Int(-10,)), + ("note".into(), I8(-10,)), ])), ],) ); @@ -36,17 +36,17 @@ fn test_example1() { Struct(BTreeMap::from([ ("first_name".into(), String("Bryan".into(),)), ("last_name".into(), String("Bower".into(),)), - ("note".into(), Int(-10,)), + ("note".into(), I8(-10,)), ])), Struct(BTreeMap::from([ ("first_name".into(), String("Jane".into(),)), ("last_name".into(), String("Dow".into(),)), - ("note".into(), Int(9,)), + ("note".into(), U8(9,)), ])), Struct(BTreeMap::from([ ("first_name".into(), String("John".into(),)), ("last_name".into(), String("Doe".into(),)), - ("note".into(), Int(18,)), + ("note".into(), U8(18,)), ])), ],) ); @@ -62,6 +62,6 @@ fn test_example2() { assert_eq!(res, Array(vec![Int(15), Int(1), Int(11), Int(22)])); assert_eq!( compute("fun([1])", &mut ctx, "N/A").unwrap(), - Array(vec![Int(0)]) + Array(vec![U8(0)]) ); } diff --git a/src/adana_script/tests/foreach.rs b/src/adana_script/tests/foreach.rs index f11e9ff..83991f1 100644 --- a/src/adana_script/tests/foreach.rs +++ b/src/adana_script/tests/foreach.rs @@ -169,8 +169,7 @@ fn simple_foreach_return() { assert!(ctx.get("word").is_none()); } #[test] -fn simple_foreach_two_depth() { - use crate::Primitive::Int; +fn simple_foreach_two_depth1() { let expr = r#" x_arr = [5,10,15,20,25] y_arr = [0,1,0,0,1] @@ -188,44 +187,44 @@ fn simple_foreach_two_depth() { assert_eq!( Primitive::Array(vec![ Primitive::Array(vec![ - Primitive::Int(5), - Int(0), - Int(1), - Int(0), - Int(0), - Int(1) + Primitive::U8(5), + Primitive::U8(0), + Primitive::U8(1), + Primitive::U8(0), + Primitive::U8(0), + Primitive::U8(1) ]), Primitive::Array(vec![ - Int(10), - Int(0), - Int(1), - Int(0), - Int(0), - Int(1) + Primitive::U8(10), + Primitive::U8(0), + Primitive::U8(1), + Primitive::U8(0), + Primitive::U8(0), + Primitive::U8(1) ]), Primitive::Array(vec![ - Int(15), - Int(0), - Int(1), - Int(0), - Int(0), - Int(1) + Primitive::U8(15), + Primitive::U8(0), + Primitive::U8(1), + Primitive::U8(0), + Primitive::U8(0), + Primitive::U8(1) ]), Primitive::Array(vec![ - Int(20), - Int(0), - Int(1), - Int(0), - Int(0), - Int(1) + Primitive::U8(20), + Primitive::U8(0), + Primitive::U8(1), + Primitive::U8(0), + Primitive::U8(0), + Primitive::U8(1) ]), Primitive::Array(vec![ - Int(25), - Int(0), - Int(1), - Int(0), - Int(0), - Int(1) + Primitive::U8(25), + Primitive::U8(0), + Primitive::U8(1), + Primitive::U8(0), + Primitive::U8(0), + Primitive::U8(1) ]), ]), ctx["matrix"].read().unwrap().clone() @@ -234,7 +233,7 @@ fn simple_foreach_two_depth() { } #[test] -fn simple_foreach_with_idx() { +fn simple_foreach_with_idx1() { let expr = r#" arr = [1,2,3,4] total = 0 @@ -351,7 +350,7 @@ fn test_handle_error() { let mut ctx = BTreeMap::new(); let r = compute(expr, &mut ctx, "N/A").unwrap(); - assert_eq!(Primitive::Error("not an iterable Int(1)".into()), r); + assert_eq!(Primitive::Error("not an iterable U8(1)".into()), r); } #[test] diff --git a/src/adana_script/tests/funct.rs b/src/adana_script/tests/funct.rs index 6dd5a53..75b8e38 100644 --- a/src/adana_script/tests/funct.rs +++ b/src/adana_script/tests/funct.rs @@ -35,7 +35,7 @@ fn test_anon_func_call() { exprs: vec![ Value::VariableExpr { name: Box::new(Value::Variable("c".to_string(),)), - expr: Box::new(Value::Integer(4,),), + expr: Box::new(Value::U8(4,),), }, Value::Expression(vec![ Value::Variable("a".to_string(),), @@ -89,7 +89,7 @@ fn test_basic_map() { let mut ctx = BTreeMap::new(); let res = compute(script, &mut ctx, "N/A").unwrap(); - assert_eq!(Primitive::Int(34), res); + assert_eq!(Primitive::U8(34), res); let script = r#" include("file_tests/test_fn.adana") m = map() @@ -115,13 +115,13 @@ fn test_override_map() { let mut ctx = BTreeMap::new(); let res = compute(script, &mut ctx, "N/A").unwrap(); - assert_eq!(Primitive::Int(35), res); + assert_eq!(Primitive::U8(35), res); assert_eq!( *ctx["m"].read().unwrap(), Primitive::Array(vec![Primitive::Array(vec![ Primitive::String("nordine".to_string(),), - Primitive::Int(35,), + Primitive::U8(35,), ],),],) ); } @@ -142,7 +142,7 @@ fn test_drop() { let res = compute(script, &mut ctx, "N/A").unwrap(); assert_eq!(Primitive::Unit, res); - assert_eq!(*ctx["z"].read().unwrap(), Primitive::Int(35,)); + assert_eq!(*ctx["z"].read().unwrap(), Primitive::U8(35,)); assert!(!ctx.contains_key("m")); } diff --git a/src/adana_script/tests/misc.rs b/src/adana_script/tests/misc.rs index 7c5d838..f47476e 100644 --- a/src/adana_script/tests/misc.rs +++ b/src/adana_script/tests/misc.rs @@ -60,13 +60,13 @@ fn test_variable() { vec![Value::Expression(vec![ Value::Variable("x".to_string(),), Value::Operation(Mult,), - Value::Integer(5,), + Value::U8(5,), Value::Operation(Add,), - Value::Integer(9,), + Value::U8(9,), Value::Operation(Mult,), Value::Variable("y".to_string(),), Value::Operation(Div,), - Value::Integer(8,), + Value::U8(8,), ],)], ); } @@ -81,13 +81,13 @@ fn test_variable_expr() { expr: Box::new(Value::Expression(vec![ Value::Variable("x".to_string(),), Value::Operation(Mult,), - Value::Integer(5,), + Value::U8(5,), Value::Operation(Add,), - Value::Integer(9,), + Value::U8(9,), Value::Operation(Mult,), Value::Variable("y".to_string(),), Value::Operation(Div,), - Value::Integer(8,), + Value::U8(8,), ])) },] ); @@ -103,13 +103,13 @@ fn test_variable_expr_2() { expr: Box::new(Value::Expression(vec![ Value::Variable("x_3".to_string(),), Value::Operation(Mult,), - Value::Integer(5,), + Value::U8(5,), Value::Operation(Add,), - Value::Integer(9,), + Value::U8(9,), Value::Operation(Mult,), Value::Variable("y_1_2".to_string(),), Value::Operation(Div,), - Value::Integer(8,), + Value::U8(8,), ])) },] ); @@ -118,7 +118,7 @@ fn test_variable_expr_2() { #[test] fn test_modulo() { let mut ctx = BTreeMap::new(); - assert_eq!(Primitive::Int(1), compute("3%2", &mut ctx, "N/A").unwrap()); + assert_eq!(Primitive::U8(1), compute("3%2", &mut ctx, "N/A").unwrap()); assert_eq!( Primitive::Double(1.), compute("3%2.", &mut ctx, "N/A").unwrap() @@ -173,9 +173,11 @@ fn test_compute() { Primitive::Double(37736.587719298244), compute("f = 1988*19-(((((((9*2))))+2*4)-3))/6.-1^2*1000/(7-4*(3/9.-(9+3/2.-4)))", &mut ctx, "N/A").unwrap() ); - assert_eq!(Primitive::Int(0), compute("0", &mut ctx, "N/A").unwrap()); - assert_eq!(Primitive::Int(9), compute("9", &mut ctx, "N/A").unwrap()); - assert_eq!(Primitive::Int(-9), compute("-9", &mut ctx, "N/A").unwrap()); + assert_eq!(Primitive::U8(0), compute("0", &mut ctx, "N/A").unwrap()); + assert_eq!(Primitive::U8(9), compute("9", &mut ctx, "N/A").unwrap()); + assert_eq!(Primitive::I8(-9), compute("-9", &mut ctx, "N/A").unwrap()); + assert_eq!(Primitive::Int(-255), compute("-255", &mut ctx, "N/A").unwrap()); + assert_eq!(Primitive::I8(-127), compute("-127", &mut ctx, "N/A").unwrap()); assert_eq!( Primitive::Int(6 / 2 * (2 + 1)), compute("6/2*(2+1)", &mut ctx, "N/A").unwrap() @@ -193,7 +195,7 @@ fn test_compute() { Primitive::Int(2 * 4), compute("2* ** *4", &mut ctx, "N/A").unwrap() ); - assert_eq!(Primitive::Int(4), compute("*4", &mut ctx, "N/A").unwrap()); + assert_eq!(Primitive::U8(4), compute("*4", &mut ctx, "N/A").unwrap()); // compute with variables assert_eq!( @@ -224,7 +226,7 @@ fn test_negate() { Primitive::Int(5 / -1), compute("5/-1", &mut ctx, "N/A").unwrap() ); - assert_eq!(Primitive::Int(5), compute("--5", &mut ctx, "N/A").unwrap()); + assert_eq!(Primitive::I8(5), compute("--5", &mut ctx, "N/A").unwrap()); } #[test] fn test_pow() { @@ -286,7 +288,7 @@ fn test_fn_sqrt() { #[test] fn test_fn_abs() { let mut ctx = BTreeMap::new(); - assert_eq!(Primitive::Int(5), compute("abs(5)", &mut ctx, "N/A").unwrap()); + assert_eq!(Primitive::U8(5), compute("abs(5)", &mut ctx, "N/A").unwrap()); assert_eq!( Primitive::Int(25), compute("abs(-5*5)", &mut ctx, "N/A").unwrap() @@ -647,10 +649,7 @@ fn test_op_pow_sugar() { #[test] fn test_implicit_multiply() { let mut ctx = BTreeMap::new(); - assert_eq!( - Primitive::Int(2), - compute(r#"x = 2"#, &mut ctx, "N/A").unwrap() - ); + assert_eq!(Primitive::U8(2), compute(r#"x = 2"#, &mut ctx, "N/A").unwrap()); assert_eq!(Primitive::Int(4), compute(r#"2x"#, &mut ctx, "N/A").unwrap()); assert_eq!( Primitive::Double(1.), diff --git a/src/adana_script/tests/mod.rs b/src/adana_script/tests/mod.rs index b74ab7b..10f2acc 100644 --- a/src/adana_script/tests/mod.rs +++ b/src/adana_script/tests/mod.rs @@ -1,3 +1,4 @@ +mod bitwise; mod builtin; mod dynload; mod examples; diff --git a/src/adana_script/tests/range.rs b/src/adana_script/tests/range.rs index 50d480d..7ed2f8c 100644 --- a/src/adana_script/tests/range.rs +++ b/src/adana_script/tests/range.rs @@ -44,9 +44,9 @@ fn simple_range_in_array() { let _ = compute(expr, &mut ctx, "N/A").unwrap(); assert_eq!( Primitive::Array(vec![ - Primitive::Int(9), - Primitive::Int(1), - Primitive::Int(3), + Primitive::U8(9), + Primitive::U8(1), + Primitive::U8(3), Primitive::Bool(true), Primitive::Array(vec![ Primitive::Int(1), @@ -59,9 +59,9 @@ fn simple_range_in_array() { ); assert_eq!( Primitive::Array(vec![ - Primitive::Int(9), - Primitive::Int(1), - Primitive::Int(3), + Primitive::U8(9), + Primitive::U8(1), + Primitive::U8(3), Primitive::Bool(true), Primitive::Array(vec![ Primitive::Int(1), @@ -129,7 +129,7 @@ fn simple_range_struct() { ]) ), ("b".into(), Primitive::String("s".into())), - ("c".to_string(), Primitive::Int(4)), + ("c".to_string(), Primitive::U8(4)), ( "d".to_string(), Primitive::Array(vec![ @@ -138,7 +138,7 @@ fn simple_range_struct() { Primitive::Int(3), ]) ), - ("x".to_string(), Primitive::Int(2)), + ("x".to_string(), Primitive::U8(2)), ])), ctx["s"].read().unwrap().clone() ); diff --git a/src/adana_script/tests/struc.rs b/src/adana_script/tests/struc.rs index f6e6876..eb33b6e 100644 --- a/src/adana_script/tests/struc.rs +++ b/src/adana_script/tests/struc.rs @@ -16,7 +16,7 @@ fn test_simple_struc() { ctx["x"].read().unwrap().clone(), Primitive::Struct(BTreeMap::from([( "x".to_string(), - Primitive::Int(8) + Primitive::U8(8) )])) ); } @@ -35,7 +35,7 @@ fn test_simple_struc_with_more_stuff_in_it() { assert_eq!( ctx["x"].read().unwrap().clone(), Primitive::Struct(BTreeMap::from([ - ("x".to_string(), Primitive::Int(8)), + ("x".to_string(), Primitive::U8(8)), ("y".to_string(), Primitive::String("hello;".to_string())), ( "z".to_string(), @@ -104,7 +104,7 @@ fn test_struct_access() { person.age "#; let res = compute(expr, &mut ctx, "N/A").unwrap(); - assert_eq!(res, Primitive::Int(20)); + assert_eq!(res, Primitive::U8(20)); } #[test] @@ -120,7 +120,7 @@ fn test_struct_variable_assign() { person.age "#; let res = compute(expr, &mut ctx, "N/A").unwrap(); - assert_eq!(res, Primitive::Int(34)); + assert_eq!(res, Primitive::U8(34)); } #[test] #[serial] diff --git a/src/adana_script/tests/test_array.rs b/src/adana_script/tests/test_array.rs index bfb3871..b2256ba 100644 --- a/src/adana_script/tests/test_array.rs +++ b/src/adana_script/tests/test_array.rs @@ -5,7 +5,7 @@ use serial_test::serial; use crate::adana_script::compute; use adana_script_core::primitive::{ Array as Arr, - Primitive::{self, Array, Bool, Double, Int, String as Str}, + Primitive::{self, Array, Bool, Double, Int, String as Str, I8, U8}, }; #[test] #[serial] @@ -26,7 +26,7 @@ fn test_simple_array() { "x".to_string(), Array(vec![ Str("hello".to_string()), - Int(1), + U8(1), Str("World".to_string()), Bool(true) ]) @@ -35,23 +35,23 @@ fn test_simple_array() { "y".to_string(), Array(vec![ Str("hello".to_string()), - Int(1), + U8(1), Str("World".to_string()), Bool(true), Str("hello".to_string()), - Int(1), + U8(1), Str("World".to_string()), Bool(true), Str("hello".to_string()), - Int(1), + U8(1), Str("World".to_string()), Bool(true), Str("hello".to_string()), - Int(1), + U8(1), Str("World".to_string()), Bool(true), Str("hello".to_string()), - Int(1), + U8(1), Str("World".to_string()), Bool(true) ]) @@ -77,45 +77,48 @@ fn test_file_array() { Bool(true), Str("bababa".to_string()), Str("zezezeze".to_string()), - Int(1), + Primitive::U8(1), Double(2.1), Double(3.0), - Int(69), + Primitive::U8(69), Int(420), Str("Yolo".to_string()), Bool(true), Str("bababa".to_string()), Str("zezezeze".to_string()), - Int(1), + Primitive::U8(1), Double(2.1), Double(3.0), - Int(69), + Primitive::U8(69), Int(420), ]); let mut copy = arr.clone(); - copy.swap_mem(&mut Str("a".to_string()), &Int(9)); + copy.swap_mem(&mut Str("a".to_string()), &Primitive::U8(9)); assert_eq!(ctx["arr"].read().unwrap().clone(), arr); assert_eq!(ctx["copy"].read().unwrap().clone(), copy); let fancy_list = Array(vec![ - Int(1), + Primitive::U8(1), Array(vec![ - Int(2), + Primitive::U8(2), Array(vec![ - Int(3), + Primitive::U8(3), Array(vec![ - Int(4), + Primitive::U8(4), Array(vec![ - Int(5), + Primitive::U8(5), Array(vec![ - Int(6), + Primitive::U8(6), Array(vec![ - Int(7), + Primitive::U8(7), Array(vec![ - Int(8), - Array(vec![Int(9), Array(vec![])]), + Primitive::U8(8), + Array(vec![ + Primitive::U8(9), + Array(vec![]), + ]), ]), ]), ]), @@ -163,8 +166,8 @@ fn test_array_expr_access() { "#; let mut ctx = BTreeMap::new(); let r = compute(expr, &mut ctx, "N/A").unwrap(); - assert_eq!(ctx["x"].read().unwrap().clone(), Primitive::Int(1)); - assert_eq!(r, Primitive::Int(1)); + assert_eq!(ctx["x"].read().unwrap().clone(), Primitive::U8(1)); + assert_eq!(r, Primitive::U8(1)); } #[test] @@ -175,7 +178,7 @@ fn test_array_expr_access_not_assigned() { "#; let mut ctx = BTreeMap::new(); let r = compute(expr, &mut ctx, "N/A").unwrap(); - assert_eq!(r, Primitive::Int(2)); + assert_eq!(r, Primitive::U8(2)); } #[test] #[serial] @@ -193,15 +196,15 @@ fn test_array_access_expr() { assert_eq!( ctx["arr_ints"].read().unwrap().clone(), Array(vec![ - Int(-1), - Int(1), - Int(2), - Int(3), - Int(7), - Int(8), - Int(9), - Int(12), - Int(19), + I8(-1), + U8(1), + U8(2), + U8(3), + U8(7), + U8(8), + U8(9), + U8(12), + U8(19), ]) ); diff --git a/src/adana_script/tests/test_drop.rs b/src/adana_script/tests/test_drop.rs index b2a59b9..9aea4a6 100644 --- a/src/adana_script/tests/test_drop.rs +++ b/src/adana_script/tests/test_drop.rs @@ -16,9 +16,9 @@ fn test_drop_arr_access() { assert_eq!( ctx["arr"].read().unwrap().clone(), Primitive::Array(vec![ - Primitive::Int(1), - Primitive::Int(2), - Primitive::Int(4), + Primitive::U8(1), + Primitive::U8(2), + Primitive::U8(4), ]) ); } diff --git a/src/adana_script/tests/test_parser.rs b/src/adana_script/tests/test_parser.rs index 8a050bc..a3a0e74 100644 --- a/src/adana_script/tests/test_parser.rs +++ b/src/adana_script/tests/test_parser.rs @@ -4,8 +4,8 @@ use crate::adana_script::parser::parse_instructions; use adana_script_core::{ BuiltInFunctionType, Operator, Value::{ - self, BlockParen, Expression, Function, Integer, Operation, Variable, - VariableExpr, WhileExpr, + self, BlockParen, Expression, Function, Operation, Variable, + VariableExpr, WhileExpr, U8, }, }; @@ -44,7 +44,7 @@ fn test_parse_fn() { ),],)), exprs: vec![Value::VariableExpr { name: Box::new(Value::Variable("x".to_string(),)), - expr: Box::new(Value::Integer(0,)), + expr: Box::new(Value::U8(0,)), },], }), },] @@ -67,7 +67,7 @@ fn test_parse_fn() { ],)), exprs: vec![Value::VariableExpr { name: Box::new(Value::Variable("x".to_string(),)), - expr: Box::new(Value::Integer(0,)), + expr: Box::new(Value::U8(0,)), },], },] ); @@ -91,7 +91,7 @@ fn test_parse_fn() { exprs: vec![ Value::VariableExpr { name: Box::new(Value::Variable("x".to_string(),)), - expr: Box::new(Value::Integer(0,),), + expr: Box::new(Value::U8(0,),), }, Value::BuiltInFunction { fn_type: BuiltInFunctionType::Println, @@ -138,13 +138,13 @@ fn test_parse_break() { exprs: vec![ VariableExpr { name: Box::new(Variable("count".to_string(),)), - expr: Box::new(Integer(0)) + expr: Box::new(Value::U8(0)) }, VariableExpr { name: Box::new(Variable("res".to_string(),)), expr: Box::new(Expression(vec![ Operation(Operator::Subtr,), - Integer(1,), + Value::U8(1,), ],),) }, WhileExpr { @@ -174,7 +174,7 @@ fn test_parse_break() { arr: Box::new(Variable( "k".to_string(), )), - index: Box::new(Integer(0,)), + index: Box::new(U8(0,)), }, Operation(Operator::Equal,), Variable("key".to_string(),), @@ -197,7 +197,7 @@ fn test_parse_break() { expr: Box::new(Expression(vec![ Variable("count".to_string(),), Operation(Operator::Add,), - Integer(1,), + Value::U8(1,), ],)), },],), }, @@ -218,14 +218,14 @@ fn test_paren_bug_2023() { assert_eq!( instructions, vec![Value::BlockParen(vec![ - Value::Integer(4,), + Value::U8(4,), Value::Operation(Operator::Mult,), - Value::Integer(3,), + Value::U8(3,), Value::Operation(Operator::Mult,), Value::BlockParen(vec![ - Value::Integer(2,), + Value::U8(2,), Value::Operation(Operator::Add,), - Value::Integer(2,), + Value::U8(2,), ],), ],),] ); @@ -237,7 +237,7 @@ fn test_struct1() { let (res, struc) = parse_instructions(expr).unwrap(); assert_eq!("", res); assert_eq!( - vec![Value::Struct(BTreeMap::from([("x".into(), Value::Integer(99))]))], + vec![Value::Struct(BTreeMap::from([("x".into(), Value::U8(99))]))], struc ); } @@ -251,8 +251,8 @@ fn test_struct_array() { vec![Value::VariableExpr { name: Box::new(Value::Variable("x".into(),)), expr: Box::new(Value::Array(vec![ - Value::Integer(1,), - Value::Integer(2,), + Value::U8(1,), + Value::U8(2,), Value::Struct(BTreeMap::from([( "x".to_string(), Value::Function { @@ -289,8 +289,8 @@ fn test_struct_array2() { vec![Value::VariableExpr { name: Box::new(Value::Variable("x".into(),)), expr: Box::new(Value::Array(vec![ - Value::Integer(1,), - Value::Integer(2,), + Value::U8(1,), + Value::U8(2,), Value::Struct(BTreeMap::from([( "x".to_string(), Value::Function { @@ -348,7 +348,7 @@ fn test_struct2() { vec![Value::VariableExpr { name: Box::new(Value::Variable("my".to_string(),)), expr: Box::new(Value::Struct(BTreeMap::from([ - ("a".into(), Value::Integer(7,)), + ("a".into(), Value::U8(7,)), ( "aa".into(), Value::Function { @@ -371,9 +371,9 @@ fn test_struct2() { ( "c".into(), Value::Array(vec![ - Value::Integer(1,), - Value::Integer(2,), - Value::Integer(3,), + Value::U8(1,), + Value::U8(2,), + Value::U8(3,), ],) ), ("d".into(), Value::Decimal(1.0,)), @@ -382,19 +382,17 @@ fn test_struct2() { "i".into(), Value::Function { parameters: Box::new(Value::BlockParen(vec![],)), - exprs: vec![Value::BlockParen(vec![ - Value::Integer(1,), - ],),], + exprs: vec![Value::BlockParen(vec![Value::U8(1,),],),], } ), ( "j".into(), Value::Expression(vec![ - Value::Integer(4,), + Value::U8(4,), Value::Operation(Operator::Mult,), - Value::Integer(2,), + Value::U8(2,), Value::Operation(Operator::Add,), - Value::Integer(1,), + Value::U8(1,), Value::Operation(Operator::Mult,), Value::BuiltInFunction { fn_type: BuiltInFunctionType::Sqrt, @@ -407,9 +405,9 @@ fn test_struct2() { ( "mm".into(), Value::BlockParen(vec![ - Value::Integer(2,), + Value::U8(2,), Value::Operation(Operator::Mult,), - Value::Integer(2,), + Value::U8(2,), ],) ), ( @@ -459,18 +457,16 @@ fn test_array_fn_access() { Value::VariableExpr { name: Box::new(Value::Variable("n".into())), expr: Box::new(Value::Array(vec![ - Value::Integer(1), - Value::Integer(2), + Value::U8(1), + Value::U8(2), Value::Variable("x".into()) ])) }, Value::FunctionCall { - parameters: Box::new(Value::BlockParen(vec![Value::Integer( - 5 - )])), + parameters: Box::new(Value::BlockParen(vec![Value::U8(5)])), function: Box::new(Value::ArrayAccess { arr: Box::new(Value::Variable("n".into())), - index: Box::new(Value::Integer(2)) + index: Box::new(Value::U8(2)) }) } ] @@ -495,7 +491,7 @@ fn test_inline_fn1() { Value::VariableExpr { name: Box::new(Value::Variable("s".into())), expr: Box::new(Value::Array(vec![ - Value::Integer(1), + Value::U8(1), Value::Function { parameters: Box::new(Value::BlockParen(vec![ Value::Variable("i".into()) @@ -509,7 +505,7 @@ fn test_inline_fn1() { } ])] }, - Value::Integer(2) + Value::U8(2) ])) }, Value::VariableExpr { @@ -517,9 +513,9 @@ fn test_inline_fn1() { expr: Box::new(Value::Function { parameters: Box::new(BlockParen(vec![],)), exprs: vec![Value::BlockParen(vec![ - Value::Integer(1,), + Value::U8(1,), Value::Operation(Operator::Add,), - Value::Integer(2,), + Value::U8(2,), ],),], }), }, @@ -553,7 +549,7 @@ fn test_comments_end_arr() { parameters: Box::new(Value::BlockParen(vec![],)), function: Box::new(Value::ArrayAccess { arr: Box::new(Value::Variable("x".to_string(),)), - index: Box::new(Value::Integer(1,)), + index: Box::new(Value::U8(1,)), }), }] ); @@ -565,7 +561,7 @@ fn test_comments_end_arr() { vec![Value::VariableExpr { name: Box::new(Value::Variable("x".into())), expr: Box::new(Value::Array(vec![ - Value::Integer(1,), + Value::U8(1,), Value::Function { parameters: Box::new(Value::BlockParen(vec![],)), exprs: vec![Value::BlockParen(vec![ @@ -601,7 +597,7 @@ fn test_struct_access_1() { name: Box::new(Value::Variable("person".to_string(),)), expr: Box::new(Value::Struct(BTreeMap::from([ ("name".to_string(), Value::String("nordine".to_string(),)), - ("age".to_string(), Value::Integer(34,),) + ("age".to_string(), Value::U8(34,),) ]),)), }, Value::BuiltInFunction { @@ -614,7 +610,7 @@ fn test_struct_access_1() { Value::VariableExpr { name: Box::new(Value::Variable("x".to_string())), expr: Box::new(Value::Array(vec![ - Value::Integer(9), + Value::U8(9), Value::StructAccess { struc: Box::new(Value::Variable("person".to_string())), key: "name".to_string() @@ -636,12 +632,8 @@ fn test_parser_array_directly_access() { vec![VariableExpr { name: Box::new(Variable("x".into()),), expr: Box::new(ArrayAccess { - arr: Box::new(Array(vec![ - Integer(1,), - Integer(2,), - Integer(3,), - ],)), - index: Box::new(Integer(0,)), + arr: Box::new(Array(vec![U8(1,), U8(2,), U8(3,),],)), + index: Box::new(U8(0,)), }), }] ) diff --git a/src/adana_script/tests/test_reference.rs b/src/adana_script/tests/test_reference.rs index aeb481f..804ea4c 100644 --- a/src/adana_script/tests/test_reference.rs +++ b/src/adana_script/tests/test_reference.rs @@ -35,7 +35,7 @@ fn test_simple_modify() { ctx["y"].read().unwrap().clone() ); assert!(matches!(ctx["y"].read().unwrap().clone(), Primitive::Ref(_))); - assert_eq!(ctx["y"].read().unwrap().clone(), Primitive::Int(100)); + assert_eq!(ctx["y"].read().unwrap().clone(), Primitive::U8(100)); } #[test] fn test_simple_struct_ref() { @@ -81,7 +81,7 @@ fn test_simple_array_ref() { ); } #[test] -fn test_forin_range_ref() { +fn test_forin_range_ref1() { let expr = r#" x = 100 y = &x diff --git a/src/adana_script/tests/test_scope_ctx.rs b/src/adana_script/tests/test_scope_ctx.rs index 1c1183d..7fc676d 100644 --- a/src/adana_script/tests/test_scope_ctx.rs +++ b/src/adana_script/tests/test_scope_ctx.rs @@ -16,7 +16,7 @@ fn test_if_scope_simple() { "#; let _ = compute(program, &mut ctx, "N/A").unwrap(); assert!(!ctx.contains_key("z")); - assert_eq!(Primitive::Int(4), ctx["x"].read().unwrap().clone()); + assert_eq!(Primitive::U8(4), ctx["x"].read().unwrap().clone()); } #[test] @@ -66,7 +66,7 @@ fn test_if_scope_complex() { assert!(!ctx.contains_key("h")); assert!(!ctx.contains_key("f")); assert_eq!(Primitive::Int(8), ctx["x"].read().unwrap().clone()); - assert_eq!(Primitive::Int(6), ctx["y"].read().unwrap().clone()); + assert_eq!(Primitive::U8(6), ctx["y"].read().unwrap().clone()); } #[test] fn test_if_else_scope_complex() { @@ -106,7 +106,7 @@ fn test_if_else_scope_complex() { assert!(!ctx.contains_key("f")); assert!(!ctx.contains_key("t")); assert_eq!(Primitive::Int(7), ctx["x"].read().unwrap().clone()); - assert_eq!(Primitive::Int(4), ctx["y"].read().unwrap().clone()); + assert_eq!(Primitive::U8(4), ctx["y"].read().unwrap().clone()); } #[test] @@ -121,7 +121,7 @@ fn test_while_scope_simple() { "#; let _ = compute(program, &mut ctx, "N/A").unwrap(); assert!(!ctx.contains_key("z")); - assert_eq!(Primitive::Int(4), ctx["x"].read().unwrap().clone()); + assert_eq!(Primitive::U8(4), ctx["x"].read().unwrap().clone()); } #[test] fn test_while_scope_complex() { @@ -149,5 +149,5 @@ fn test_while_scope_complex() { assert!(!ctx.contains_key("p")); assert!(!ctx.contains_key("d")); assert_eq!(Primitive::Int(-5), ctx["x"].read().unwrap().clone()); - assert_eq!(Primitive::Int(8), ctx["g"].read().unwrap().clone()); + assert_eq!(Primitive::U8(8), ctx["g"].read().unwrap().clone()); } diff --git a/src/adana_script/tests/tests_file.rs b/src/adana_script/tests/tests_file.rs index fdfe3cc..2a738d1 100644 --- a/src/adana_script/tests/tests_file.rs +++ b/src/adana_script/tests/tests_file.rs @@ -46,15 +46,15 @@ fn test_if_statement() { assert_eq!( &BTreeMap::from([ ("a".to_string(), Primitive::Int(25)), - ("b".to_string(), Primitive::Int(12)), - ("c".to_string(), Primitive::Int(20)), - ("x".to_string(), Primitive::Int(15)), - ("r".to_string(), Primitive::Int(11)), - ("z".to_string(), Primitive::Int(18)), + ("b".to_string(), Primitive::U8(12)), + ("c".to_string(), Primitive::U8(20)), + ("x".to_string(), Primitive::U8(15)), + ("r".to_string(), Primitive::U8(11)), + ("z".to_string(), Primitive::U8(18)), ]), &ctx ); - assert_eq!(Primitive::Int(20), r); + assert_eq!(Primitive::U8(20), r); } #[test] #[serial] @@ -109,9 +109,9 @@ fn test_nested_file() { .collect(); assert_eq!( &BTreeMap::from([ - ("a".to_string(), Primitive::Int(0)), + ("a".to_string(), Primitive::U8(0)), ("b".to_string(), Primitive::Int(240)), - ("x".to_string(), Primitive::Int(50)), + ("x".to_string(), Primitive::U8(50)), ("s".to_string(), Primitive::String("mod 3".to_string())), ("z".to_string(), Primitive::String("mod 1".to_string())), ]), @@ -156,24 +156,24 @@ fn test_includes() { ( "arr".to_string(), Primitive::Array(vec![ - Primitive::Int(1,), - Primitive::Int(2,), - Primitive::Int(3,), + Primitive::U8(1,), + Primitive::U8(2,), + Primitive::U8(3,), ],) ), ( "arr2".to_string(), Primitive::Array(vec![ - Primitive::Int(4,), - Primitive::Int(5,), - Primitive::Int(6,), + Primitive::U8(4,), + Primitive::U8(5,), + Primitive::U8(6,), ],) ), ("b".to_string(), Primitive::Int(233,)), - ("bfr".to_string(), Primitive::Int(2,)), + ("bfr".to_string(), Primitive::U8(2,)), ("c".to_string(), Primitive::Int(233,)), - ("n".to_string(), Primitive::Int(1,)), - ("x".to_string(), Primitive::Int(4,)) + ("n".to_string(), Primitive::U8(1,)), + ("x".to_string(), Primitive::U8(4,)) ]), ); } @@ -202,14 +202,14 @@ fn test_multiline_file() { Some(&Primitive::String("sincostanmultiline".to_string())), ctx.get("x") ); - assert_eq!(Some(&Primitive::Int(1)), ctx.get("xy")); - assert_eq!(Some(&Primitive::Int(2)), ctx.get("ze")); - assert_eq!(Some(&Primitive::Int(3)), ctx.get("de")); + assert_eq!(Some(&Primitive::U8(1)), ctx.get("xy")); + assert_eq!(Some(&Primitive::U8(2)), ctx.get("ze")); + assert_eq!(Some(&Primitive::U8(3)), ctx.get("de")); } #[test] #[serial] -fn test_if_else_file() { +fn test_if_else_file1() { let file_path = r#" include("file_tests/test_if_else.adana") "#; diff --git a/src/adana_script/tests/unused.rs b/src/adana_script/tests/unused.rs index b54ae25..c41ddb7 100644 --- a/src/adana_script/tests/unused.rs +++ b/src/adana_script/tests/unused.rs @@ -16,10 +16,10 @@ fn test_simple_unused_array() { assert_eq!( r, Primitive::Array(vec![ - Primitive::Int(1), - Primitive::Int(2), - Primitive::Int(3), - Primitive::Int(4), + Primitive::U8(1), + Primitive::U8(2), + Primitive::U8(3), + Primitive::U8(4), ]) ); } diff --git a/src/main.rs b/src/main.rs index 19b7d21..bf45769 100644 --- a/src/main.rs +++ b/src/main.rs @@ -196,6 +196,9 @@ fn start_app( Ok(Primitive::Unit) => {} Ok(calc) => println!("{calc}"), Err(calc_err) => { + if cfg!(debug_assertions) { + eprintln!("Error: {calc_err:?}"); + } match process_command( db, &mut script_context, diff --git a/src/prelude.rs b/src/prelude.rs index de6e7fe..8520cc6 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -5,8 +5,8 @@ pub use nom::{ take_while1, }, character::complete::{ - alpha1, alphanumeric1, i128 as I128, line_ending, multispace0, - multispace1, none_of, one_of, space1, + alpha1, alphanumeric1, i128 as I128, i8 as I8, line_ending, + multispace0, multispace1, none_of, one_of, space1, u8 as U8, }, combinator::{ all_consuming, consumed, cut, eof, fail, map, map_parser, map_res, opt, diff --git a/src/reserved_keywords.rs b/src/reserved_keywords.rs index d0f86ff..5ea2e53 100644 --- a/src/reserved_keywords.rs +++ b/src/reserved_keywords.rs @@ -17,6 +17,8 @@ pub const FORBIDDEN_VARIABLE_NAME: &[&str] = &[ LOG, TO_INT, TO_DOUBLE, + TO_HEX, + TO_BINARY, TO_STRING, EVAL, TO_BOOL, @@ -56,6 +58,12 @@ pub const FORBIDDEN_VARIABLE_NAME: &[&str] = &[ Operator::NotEqual.as_str(), Operator::And.as_str(), Operator::Or.as_str(), + Operator::BitwiseNot.as_str(), + Operator::BitwiseAnd.as_str(), + Operator::BitwiseOr.as_str(), + Operator::BitwiseXor.as_str(), + Operator::BitwiseLShift.as_str(), + Operator::BitwiseRShift.as_str(), ]; pub fn check_reserved_keyword(aliases: &[&str]) -> bool {