diff --git a/hexparser/src/tests.rs b/hexparser/src/tests.rs index 3c2a6ff..4c0b6c3 100644 --- a/hexparser/src/tests.rs +++ b/hexparser/src/tests.rs @@ -2,9 +2,9 @@ use std::{cell::RefCell, collections::HashMap, env::args}; -use nom::multi::separated_list1; +use nom::{multi::separated_list1, Err}; use nom::bytes::complete::tag as just; -use crate::{m_lexer, m_parser::{self, token_parse, parse_namespace, ident, parse_struct, BinaryOp, HexTypeDef, Endianness, HexType, FuncArgument, UnaryOp, Statement, FuncCall, Definition}, simple_debug::SimpleDebug, token::{Token, Tokens, ValueType}, expand_preprocessor_tokens, Expr, Value, parse}; +use crate::{m_lexer, m_parser::{self, token_parse, parse_namespace, ident, parse_struct, BinaryOp, HexTypeDef, Endianness, HexType, FuncArgument, UnaryOp, Statement, FuncCall, Definition}, simple_debug::SimpleDebug, token::{Token, Tokens, ValueType, Spanned}, expand_preprocessor_tokens, Expr, Value, parse}; macro_rules! get_tokens { ( $test_str:expr, $var:ident ) => { @@ -81,7 +81,7 @@ fn test1() { /*#[test] fn test2() { - let test_str = " + let test_str = " type != LSTrigger::VariableValue "; get_tokens!(test_str, tokens); @@ -108,14 +108,70 @@ fn eq_hextype(ht1: &HexType, ht2: &HexType) -> bool { (HexType::Null, HexType::Null) => true, _ => false } -} +} + +fn func_arg_comparer(a1: &FuncArgument, a2: &FuncArgument) -> Result<(), CompErr> { + match (a1, a2) { + (FuncArgument::Parameter(e1), FuncArgument::Parameter(e2)) => expr_comparer(&e1.0, &e2.0), + (FuncArgument::ParameterPack((s1, _)), FuncArgument::ParameterPack((s2, _))) => match s1 == s2 { + true => Ok(()), + false => {println!("Differently named parameter pack |{s1:?}, {s2:?}|");Err(CompErr)}, + }, + (e1, e2) => {println!("Expected {e1:?}.\nGot {e2:?}");Err(CompErr)} + } +} + +fn func_arguments_comparer(list1: &Vec>, list2: &Vec>) -> Result<(), CompErr> { + for ((l1, _), (l2, _)) in list1.iter().zip(list2.iter()) { + match func_arg_comparer(l1, l2) { + Ok(_) => (), + Err(e) => return Err(e), + } + }; + if list1.len() == list2.len() { + Ok(()) + } else { + println!("Diferent length function arguments"); + Err(CompErr) + } +} + +fn vec_expr_comparer(list1: &Vec>, list2: &Vec>) -> Result<(), CompErr>{ + for ((l1, _), (l2, _)) in list1.iter().zip(list2.iter()) { + match expr_comparer(l1, l2) { + Ok(_) => (), + Err(e) => return Err(e), + } + }; + if list1.len() == list2.len() { + Ok(()) + } else { + println!("Diferent length expr list"); + Err(CompErr) + } +} + +fn vec_stmnt_comparer(list1: &Vec>, list2: &Vec>) -> Result<(), CompErr>{ + for ((l1, _), (l2, _)) in list1.iter().zip(list2.iter()) { + match stmnt_comparer(l1, l2) { + Ok(_) => (), + Err(e) => return Err(e), + } + }; + if list1.len() == list2.len() { + Ok(()) + } else { + println!("Diferent length ExprList"); + Err(CompErr) + } +} fn stmnt_comparer(stmnt1: &Statement, stmnt2: &Statement) -> Result<(), CompErr> { match (stmnt1, stmnt2) { (Statement::If { test: test1, consequent: cons1 }, Statement::If { test: test2, consequent: cons2 } ) => match expr_comparer(&test1.0, &test2.0) { - Ok(_) => match expr_comparer(&cons1.0, &cons2.0) { + Ok(_) => match vec_stmnt_comparer(&cons1.0, &cons2.0) { Ok(_) => Ok(()), Err(e) => Err(e), }, @@ -124,7 +180,7 @@ fn stmnt_comparer(stmnt1: &Statement, stmnt2: &Statement) -> Result<(), CompErr> (Statement::IfBlock { ifs: if1, alternative: alt1 }, Statement::IfBlock { ifs: if2, alternative: alt2 } ) => match expr_comparer(&if1.0, &if2.0) { - Ok(_) => match expr_comparer(&alt1.0, &alt2.0) { + Ok(_) => match vec_stmnt_comparer(&alt1.0, &alt2.0) { Ok(_) => Ok(()), Err(e) => Err(e), }, @@ -161,7 +217,7 @@ fn stmnt_comparer(stmnt1: &Statement, stmnt2: &Statement) -> Result<(), CompErr> ) => match stmnt_comparer(&v_i1.0, &v_i2.0) { Ok(_) => match expr_comparer(&v_t1.0, &v_t2.0) { Ok(_) => match stmnt_comparer(&v_c1.0, &v_c2.0) { - Ok(_) => match expr_comparer(&b1.0, &b2.0) { + Ok(_) => match vec_stmnt_comparer(&b1.0, &b2.0) { Ok(_) => Ok(()), Err(e) => Err(e), }, @@ -202,6 +258,96 @@ fn stmnt_comparer(stmnt1: &Statement, stmnt2: &Statement) -> Result<(), CompErr> }, false => {println!("Different endianness |{e1:?}, {e2:?}|");Err(CompErr)}, }, + (Statement::Func { name: (n1, _), args: a1, body: b1 }, + Statement::Func { name: (n2, _), args: a2, body: b2 } + ) => match n1 == n2 { + true => match func_arguments_comparer(&a1.0, &a2.0) { + Ok(_) => match expr_comparer(&b1.0, &b2.0) { + Ok(_) => Ok(()), + Err(e) => Err(e), + }, + Err(e) => Err(e), + }, + false => {println!("Different names |{n1:?}, {n2:?}|");Err(CompErr)}, + }, + (Statement::Return { value: v1 }, + Statement::Return { value: v2 } + ) => match expr_comparer(&v1.0, &v2.0) { + Ok(_) => Ok(()), + Err(e) => Err(e), + }, + (Statement::Struct { name: (n1, _), body: b1, template_parameters: None }, + Statement::Struct { name: (n2, _), body: b2, template_parameters: None } + ) => match n1 == n2 { + true => match expr_comparer(&b1.0, &b2.0) { + Ok(_) => Ok(()), + Err(e) => Err(e), + }, + false => {println!("Different names |{n1:?}, {n2:?}|");Err(CompErr)}, + }, + (Statement::Namespace { name: n1, body: b1 }, + Statement::Namespace { name: n2, body: b2 } + ) => match expr_comparer(&n1.0, &n2.0) { + Ok(_) => match expr_comparer(&b1.0, &b2.0) { + Ok(_) => Ok(()), + Err(e) => Err(e), + }, + Err(e) => Err(e), + }, + (Statement::Enum { name: (n1, _), value_type: ( + HexTypeDef { endianness: e1, name: (hn1, _) }, _ + ), body: b1 }, + Statement::Enum { name: (n2, _), value_type: ( + HexTypeDef { endianness: e2, name: (hn2, _) }, _ + ), body: b2 } + ) => match n1 == n2 { + true => match e1 == e2 { + true => match eq_hextype(hn1, hn2) { + true => match vec_expr_comparer(&b1.0, &b2.0) { + Ok(_) => Ok(()), + Err(e) => {println!("Different enum bodies");Err(e)}, + }, + false => {println!("Different types");Err(CompErr)}, + }, + false => {println!("Different endianness");Err(CompErr)}, + }, + false => {println!("Different enum names");Err(CompErr)}, + }, + (Statement::Bitfield { name: (n1, _), body: b1 }, + Statement::Bitfield { name: (n2, _), body: b2 } + ) => match n1 == n2 { + true => match expr_comparer(&b1.0, &b2.0) { + Ok(_) => Ok(()), + Err(e) => Err(e), + }, + false => {println!("Different names |{n1:?}, {n2:?}|");Err(CompErr)}, + }, + ( + Statement::Definition(Definition { value_type: ( + HexTypeDef { endianness: e1, name: (hn1, _) }, _ + ), name: n1, body: b1 }), + Statement::Definition(Definition { value_type: ( + HexTypeDef { endianness: e2, name: (hn2, _) }, _ + ), name: n2, body: b2 }) + ) => match e1 == e2 { + true => match eq_hextype(hn1, hn2) { + true => match expr_comparer(&n1.0, &n2.0) { + Ok(_) => match expr_comparer(&b1.0, &b2.0) { + Ok(_) => Ok(()), + Err(e) => Err(e), + }, + Err(e) => Err(e), + }, + false =>{println!("Different types |{hn1:?}, {hn2:?}|");Err(CompErr)}, + }, + false => {println!("Different endianness");Err(CompErr)}, + }, + (Statement::Padding { padding_body: pb1 }, + Statement::Padding { padding_body: pb2 } + ) => match expr_comparer(&pb1.0, &pb2.0) { + Ok(_) => Ok(()), + Err(e) => Err(e), + }, (e1, e2) => {println!("Expected {e1:?}.\nGot {e2:?}");Err(CompErr)} } } @@ -213,20 +359,8 @@ fn expr_comparer(expr1: &Expr, expr2: &Expr) -> Result<(), CompErr> { true => Ok(()), false => {println!("Different values |{val1:?} {val2:?}|");Err(CompErr)}, }, - (Expr::StatementList { list: list1 }, Expr::StatementList { list: list2 }) => { - for ((l1, _), (l2, _)) in list1.iter().zip(list2.iter()) { - match stmnt_comparer(l1, l2) { - Ok(_) => (), - Err(e) => return Err(e), - } - }; - if list1.len() == list2.len() { - Ok(()) - } else { - println!("Diferent length ExprList"); - Err(CompErr) - } - }, + (Expr::StatementList { list: list1 }, Expr::StatementList { list: list2 }) => vec_stmnt_comparer(list1, list2), + (Expr::ExprList { list: list1 }, Expr::ExprList { list: list2 }) => vec_expr_comparer(list1, list2), (Expr::UnnamedParameter { type_: (type1, _) }, Expr::UnnamedParameter { type_: (type2, _) }) => match eq_hextype(type1, type2) { true => Ok(()), false => {println!("Different types |{type1:?}, {type2:?}|");Err(CompErr)}, @@ -271,18 +405,7 @@ fn expr_comparer(expr1: &Expr, expr2: &Expr) -> Result<(), CompErr> { (Expr::Call(FuncCall { func_name: fname1, arguments: (args1, _) }), Expr::Call(FuncCall { func_name: fname2, arguments: (args2, _) }) ) => match expr_comparer(&fname1.0, &fname2.0) { - Ok(_) => { - for ((a1, _), (a2, _)) in args1.iter().zip(args2.iter()) { - match expr_comparer(a1, a2) { - Ok(_) => (), - Err(e) => return Err(e), - } - } - match args1.len() == args2.len() { - true => Ok(()), - false => {println!("Diferent length call arguments");Err(CompErr)}, - } - }, + Ok(_) => vec_expr_comparer(args1, args2), Err(e) => Err(e), }, ( @@ -449,10 +572,10 @@ fn test_pattern_arrays() { size: spanbox!(Expr::WhileLoop { condition: spanbox!(Expr::Unary { operation: UnaryOp::LNot, - operand: spanbox!(Expr::Call { + operand: spanbox!(Expr::Call(FuncCall { func_name: blocal!("end_of_signature"), arguments: (vec![], 0..0) - }) + })) }), body: bnull!() }), @@ -462,14 +585,14 @@ fn test_pattern_arrays() { }), template_parameters: None }, 0..0), - (Statement::Definition { + (Statement::Definition(Definition { value_type: (HexTypeDef { endianness: Endianness::Unkown, name: (HexType::Custom(String::from("Signature")), 0..0) }, 0..0), name: blocal!("sign"), body: bnum!() - }, 0..0) + }), 0..0) ] }; @@ -524,56 +647,56 @@ fn test_pattern_attributes() { "; let expected_output = Expr::StatementList { list: vec![ - (Expr::Struct { + (Statement::Struct { name: (String::from("FormatTransformTest"), 0..0), body: spanbox!(Expr::StatementList { list: vec![ - (Expr::Definition { + (Statement::Definition(Definition { value_type: (HexTypeDef { endianness: Endianness::Unkown, name: (HexType::V(ValueType::U32), 0..0) }, 0..0), - name: spanbox!(Expr::StatementList { list: vec![ + name: spanbox!(Expr::ExprList { list: vec![ local!("x"), local!("y"), local!("z") ] }), body: bnull!() - }, 0..0) + }), 0..0) ] }), template_parameters: None }, 0..0), - (Expr::Struct { + (Statement::Struct { name: (String::from("SealedTest"), 0..0), body: spanbox!(Expr::StatementList { list: vec![ - (Expr::Definition { + (Statement::Definition(Definition { value_type: (HexTypeDef { endianness: Endianness::Unkown, name: (HexType::V(ValueType::Float), 0..0) }, 0..0), name: blocal!("f"), body: bnull!() - }, 0..0) + }), 0..0) ] }), template_parameters: None }, 0..0), - (Expr::Struct { + (Statement::Struct { name: (String::from("HiddenTest"), 0..0), body: spanbox!(Expr::StatementList { list: vec![ - (Expr::Definition { + (Statement::Definition(Definition { value_type: (HexTypeDef { endianness: Endianness::Unkown, name: (HexType::V(ValueType::Double), 0..0) }, 0..0), name: blocal!("f"), body: bnull!() - }, 0..0) + }), 0..0) ] }), template_parameters: None }, 0..0), - (Expr::Struct { + (Statement::Struct { name: (String::from("ColorTest"), 0..0), body: spanbox!(Expr::StatementList { list: vec![ - (Expr::ArrayDefinition { + (Statement::ArrayDefinition { value_type: (HexTypeDef { endianness: Endianness::Unkown, name: (HexType::V(ValueType::Character), 0..0) @@ -585,90 +708,90 @@ fn test_pattern_attributes() { ] }), template_parameters: None }, 0..0), - (Expr::Struct { + (Statement::Struct { name: (String::from("NoUniqueAddressTest"), 0..0), body: spanbox!(Expr::StatementList { list: vec![ - (Expr::Definition { + (Statement::Definition(Definition { value_type: (HexTypeDef { endianness: Endianness::Unkown, name: (HexType::V(ValueType::U32), 0..0) }, 0..0), name: blocal!("x"), body: bnull!() - }, 0..0), - (Expr::Definition { + }), 0..0), + (Statement::Definition(Definition { value_type: (HexTypeDef { endianness: Endianness::Unkown, name: (HexType::V(ValueType::U32), 0..0) }, 0..0), name: blocal!("y"), body: bnull!() - }, 0..0) + }), 0..0) ] }), template_parameters: None }, 0..0), - (Expr::Func { + (Statement::Func { name: (String::from("format_test"), 0..0), - args: (vec![(FuncArgument::Parameter(spanbox!(Expr::Definition { + args: (vec![(FuncArgument::Parameter(spanbox!(Expr::Definition(Definition { value_type: (HexTypeDef { endianness: Endianness::Unkown, name: (HexType::Custom(String::from("FormatTransformTest")), 0..0) }, 0..0), name: blocal!("value"), body: bnull!() - })), 0..0)], 0..0), + }))), 0..0)], 0..0), body: spanbox!(Expr::StatementList { list: vec![ - (Expr::Return { value: spanbox!(Expr::Value { val: Value::Str(String::from("Hello World")) }) }, 0..0) + (Statement::Return { value: spanbox!(Expr::Value { val: Value::Str(String::from("Hello World")) }) }, 0..0) ] }) }, 0..0), - (Expr::Func { + (Statement::Func { name: (String::from("transform_test"), 0..0), - args: (vec![(FuncArgument::Parameter(spanbox!(Expr::Definition { + args: (vec![(FuncArgument::Parameter(spanbox!(Expr::Definition(Definition { value_type: (HexTypeDef { endianness: Endianness::Unkown, name: (HexType::Custom(String::from("FormatTransformTest")), 0..0) }, 0..0), name: blocal!("value"), body: bnull!() - })), 0..0)], 0..0), + }))), 0..0)], 0..0), body: spanbox!(Expr::StatementList { list: vec![ - (Expr::Return { value: bnum!() }, 0..0) + (Statement::Return { value: bnum!() }, 0..0) ] }) }, 0..0), - (Expr::Definition { + (Statement::Definition(Definition { value_type: (HexTypeDef { endianness: Endianness::Unkown, name: (HexType::Custom(String::from("FormatTransformTest")), 0..0) }, 0..0), name: blocal!("formatTransformTest"), body: bnum!() - }, 0..0), - (Expr::Definition { + }), 0..0), + (Statement::Definition(Definition { value_type: (HexTypeDef { endianness: Endianness::Unkown, name: (HexType::Custom(String::from("SealedTest")), 0..0) }, 0..0), name: blocal!("sealedTest"), body: bnum!() - }, 0..0), - (Expr::Definition { + }), 0..0), + (Statement::Definition(Definition { value_type: (HexTypeDef { endianness: Endianness::Unkown, name: (HexType::Custom(String::from("HiddenTest")), 0..0) }, 0..0), name: blocal!("hiddenTest"), body: bnum!() - }, 0..0), - (Expr::Definition { + }), 0..0), + (Statement::Definition(Definition { value_type: (HexTypeDef { endianness: Endianness::Unkown, name: (HexType::Custom(String::from("ColorTest")), 0..0) }, 0..0), name: blocal!("colorTest"), body: bnum!() - }, 0..0), - (Expr::Definition { + }), 0..0), + (Statement::Definition(Definition { value_type: (HexTypeDef { endianness: Endianness::Unkown, name: (HexType::Custom(String::from("NoUniqueAddressTest")), 0..0) }, 0..0), name: blocal!("noUniqueAddressTest"), body: bnum!() - }, 0..0) + }), 0..0) ] }; let includeable_folders = vec![ @@ -696,37 +819,37 @@ fn test_pattern_bitfields() { "; let expected_output = Expr::StatementList { list: vec![ - (Expr::Bitfield { + (Statement::Bitfield { name: (String::from("TestBitfield"), 0..0), body: spanbox!(Expr::StatementList { list: vec![ - (Expr::BitFieldEntry { + (Statement::BitFieldEntry { name: (String::from("a"), 0..0), length: bnum!() }, 0..0), - (Expr::BitFieldEntry { + (Statement::BitFieldEntry { name: (String::from("b"), 0..0), length: bnum!() }, 0..0), - (Expr::BitFieldEntry { + (Statement::BitFieldEntry { name: (String::from("c"), 0..0), length: bnum!() }, 0..0), - (Expr::BitFieldEntry { + (Statement::BitFieldEntry { name: (String::from("d"), 0..0), length: bnum!() }, 0..0) ] }) }, 0..0), - (Expr::Definition { + (Statement::Definition(Definition { value_type: (HexTypeDef { endianness: Endianness::Big, name: (HexType::Custom(String::from("TestBitfield")), 0..0) }, 0..0), name: blocal!("testBitfield"), body: bnum!() - }, 0..0) + }), 0..0) ] }; let includeable_folders = vec![ @@ -761,13 +884,13 @@ fn test_pattern_enums() { ]; let expected_output = Expr::StatementList { list: vec![ - (Expr::Enum { + (Statement::Enum { name: (String::from("TestEnum"), 0..0), value_type: (HexTypeDef { endianness: Endianness::Unkown, name: (HexType::V(ValueType::U32), 0..0) }, 0..0), - body: spanbox!(Expr::StatementList { list: vec![ + body: (vec![ (Expr::EnumEntry { name: (String::from("A"), 0..0), value: bnull!() @@ -784,16 +907,16 @@ fn test_pattern_enums() { name: (String::from("D"), 0..0), value: bnull!() }, 0..0) - ] }) + ], 0..0) }, 0..0), - (Expr::Definition { + (Statement::Definition(Definition { value_type: (HexTypeDef { endianness: Endianness::Big, name: (HexType::Custom(String::from("TestEnum")), 0..0) }, 0..0), name: blocal!("testEnum"), body: bnum!() - }, 0..0) + }), 0..0) ] }; let ((ex, _), _, _) = parse(test_str, &includeable_folders); @@ -843,74 +966,74 @@ fn test_pattern_extra_semicolon() { ]; let expected_output = Expr::StatementList { list: vec![ - (Expr::Struct { + (Statement::Struct { name: (String::from("Test"), 0..0), body: spanbox!(Expr::StatementList { list: vec![ - (Expr::Definition { + (Statement::Definition(Definition { value_type: (HexTypeDef { endianness: Endianness::Unkown, name: (HexType::V(ValueType::U32), 0..0) }, 0..0), name: blocal!("x"), body: bnull!() - }, 0..0), - (Expr::Definition { + }), 0..0), + (Statement::Definition(Definition { value_type: (HexTypeDef { endianness: Endianness::Unkown, name: (HexType::V(ValueType::U8), 0..0) }, 0..0), name: blocal!("y"), body: bnull!() - }, 0..0), - (Expr::Definition { + }), 0..0), + (Statement::Definition(Definition { value_type: (HexTypeDef { endianness: Endianness::Unkown, name: (HexType::V(ValueType::Float), 0..0) }, 0..0), name: blocal!("z"), body: bnull!() - }, 0..0) + }), 0..0) ] }), template_parameters: None }, 0..0), - (Expr::Struct { + (Statement::Struct { name: (String::from("Test2"), 0..0), body: spanbox!(Expr::StatementList { list: vec![ - (Expr::Definition { + (Statement::Definition(Definition { value_type: (HexTypeDef { endianness: Endianness::Unkown, name: (HexType::V(ValueType::U32), 0..0) }, 0..0), name: blocal!("x"), body: bnull!() - }, 0..0), - (Expr::Definition { + }), 0..0), + (Statement::Definition(Definition { value_type: (HexTypeDef { endianness: Endianness::Unkown, name: (HexType::V(ValueType::U32), 0..0) }, 0..0), name: blocal!("y"), body: bnull!() - }, 0..0) + }), 0..0) ] }), template_parameters: None }, 0..0), - (Expr::Definition { + (Statement::Definition(Definition { value_type: (HexTypeDef { endianness: Endianness::Unkown, name: (HexType::Custom(String::from("Test")), 0..0) }, 0..0), name: blocal!("test"), body: bnum!() - }, 0..0), - (Expr::Definition { + }), 0..0), + (Statement::Definition(Definition { value_type: (HexTypeDef { endianness: Endianness::Unkown, name: (HexType::Custom(String::from("Test")), 0..0) }, 0..0), name: blocal!("test2"), body: bnum!() - }, 0..0) + }), 0..0) ] }; let ((ex, _), _, _) = parse(test_str, &includeable_folders); @@ -947,41 +1070,41 @@ fn test_pattern_namespaces() { ]; let expected_output = Expr::StatementList { list: vec![ - (Expr::Namespace { + (Statement::Namespace { name: blocal!("A"), body: spanbox!(Expr::StatementList { list: vec![ - (Expr::Struct { name: (String::from("Test"), 0..0), body: spanbox!(Expr::StatementList { list: vec![ - (Expr::Definition { + (Statement::Struct { name: (String::from("Test"), 0..0), body: spanbox!(Expr::StatementList { list: vec![ + (Statement::Definition(Definition { value_type: (HexTypeDef { endianness: Endianness::Unkown, name: (HexType::V(ValueType::U32), 0..0) }, 0..0), name: blocal!("x"), body: bnull!() - }, 0..0) + }), 0..0) ] }), template_parameters: None }, 0..0) ] }) }, 0..0), - (Expr::Namespace { + (Statement::Namespace { name: blocal!("B"), body: spanbox!(Expr::StatementList { list: vec![ - (Expr::Struct { name: (String::from("Test"), 0..0), body: spanbox!(Expr::StatementList { list: vec![ - (Expr::Definition { + (Statement::Struct { name: (String::from("Test"), 0..0), body: spanbox!(Expr::StatementList { list: vec![ + (Statement::Definition(Definition { value_type: (HexTypeDef { endianness: Endianness::Unkown, name: (HexType::V(ValueType::U16), 0..0) }, 0..0), name: blocal!("x"), body: bnull!() - }, 0..0) + }), 0..0) ] }), template_parameters: None }, 0..0) ] }) }, 0..0), - (Expr::Using { + (Statement::Using { new_name: (String::from("ATest"), 0..0), template_parameters: None, old_name: (HexTypeDef { @@ -992,7 +1115,7 @@ fn test_pattern_namespaces() { ]), 0..0) }, 0..0) }, 0..0), - (Expr::Definition { + (Statement::Definition(Definition { value_type: (HexTypeDef { endianness: Endianness::Unkown, name: (HexType::Path(vec![ @@ -1002,16 +1125,16 @@ fn test_pattern_namespaces() { }, 0..0), name: blocal!("test1"), body: bnum!() - }, 0..0), - (Expr::Definition { + }), 0..0), + (Statement::Definition(Definition { value_type: (HexTypeDef { endianness: Endianness::Unkown, name: (HexType::Custom(String::from("ATest")), 0..0) }, 0..0), name: blocal!("test2"), body: bnum!() - }, 0..0), - (Expr::Definition { + }), 0..0), + (Statement::Definition(Definition { value_type: (HexTypeDef { endianness: Endianness::Unkown, name: (HexType::Path(vec![ @@ -1021,7 +1144,7 @@ fn test_pattern_namespaces() { }, 0..0), name: blocal!("test3"), body: bnum!() - }, 0..0) + }), 0..0) ] }; let ((ex, _), _, _) = parse(test_str, &includeable_folders); @@ -1063,17 +1186,17 @@ fn test_pattern_nested_structs() { ]; let expected_output = Expr::StatementList { list: vec![ - (Expr::Func { + (Statement::Func { name: (String::from("end_of_body"), 0..0), args: (vec![], 0..0), body: spanbox!(Expr::StatementList { list: vec![ - (Expr::Definition { + (Statement::Definition(Definition { value_type: (HexTypeDef { endianness: Endianness::Unkown, name: (HexType::V(ValueType::U32), 0..0) }, 0..0), name: blocal!("start"), - body: spanbox!(Expr::Call { + body: spanbox!(Expr::Call(FuncCall { func_name: blocal!("addressof"), arguments: (vec![ (Expr::Access { @@ -1084,9 +1207,9 @@ fn test_pattern_nested_structs() { }) }, 0..0) ], 0..0) - }) - }, 0..0), - (Expr::Definition { + })) + }), 0..0), + (Statement::Definition(Definition { value_type: (HexTypeDef { endianness: Endianness::Unkown, name: (HexType::V(ValueType::U32), 0..0) @@ -1102,8 +1225,8 @@ fn test_pattern_nested_structs() { }) }) }) - }, 0..0), - (Expr::Definition { + }), 0..0), + (Statement::Definition(Definition { value_type: (HexTypeDef { endianness: Endianness::Unkown, name: (HexType::V(ValueType::U32), 0..0) @@ -1114,32 +1237,32 @@ fn test_pattern_nested_structs() { operator: BinaryOp::Add, roperand: blocal!("len"), }) - }, 0..0), - (Expr::Return { value: spanbox!(Expr::Binary { + }), 0..0), + (Statement::Return { value: spanbox!(Expr::Binary { loperand: blocal!("$"), operator: BinaryOp::GreaterEqual, roperand: blocal!("end"), }) }, 0..0) ] }) }, 0..0), - (Expr::Struct { + (Statement::Struct { name: (String::from("Header"), 0..0), body: spanbox!(Expr::StatementList { list: vec![ - (Expr::Definition { + (Statement::Definition(Definition { value_type: (HexTypeDef { endianness: Endianness::Unkown, name: (HexType::V(ValueType::U8), 0..0) }, 0..0), name: blocal!("len"), body: bnull!() - }, 0..0) + }), 0..0) ] }), template_parameters: None }, 0..0), - (Expr::Struct { + (Statement::Struct { name: (String::from("Body"), 0..0), body: spanbox!(Expr::StatementList { list: vec![ - (Expr::ArrayDefinition { + (Statement::ArrayDefinition { value_type: (HexTypeDef { endianness: Endianness::Unkown, name: (HexType::V(ValueType::U8), 0..0) @@ -1148,10 +1271,10 @@ fn test_pattern_nested_structs() { size: spanbox!(Expr::WhileLoop { condition: spanbox!(Expr::Unary { operation: UnaryOp::LNot, - operand: spanbox!(Expr::Call { + operand: spanbox!(Expr::Call(FuncCall { func_name: blocal!("end_of_body"), arguments: (vec![], 0..0) - }) + })) }), body: bnull!() }), @@ -1160,36 +1283,36 @@ fn test_pattern_nested_structs() { ] }), template_parameters: None }, 0..0), - (Expr::Struct { + (Statement::Struct { name: (String::from("Data"), 0..0), body: spanbox!(Expr::StatementList { list: vec![ - (Expr::Definition { + (Statement::Definition(Definition { value_type: (HexTypeDef { endianness: Endianness::Unkown, name: (HexType::Custom(String::from("Header")), 0..0) }, 0..0), name: blocal!("hdr"), body: bnull!() - }, 0..0), - (Expr::Definition { + }), 0..0), + (Statement::Definition(Definition { value_type: (HexTypeDef { endianness: Endianness::Unkown, name: (HexType::Custom(String::from("Body")), 0..0) }, 0..0), name: blocal!("body"), body: bnull!() - }, 0..0) + }), 0..0) ] }), template_parameters: None }, 0..0), - (Expr::Definition { + (Statement::Definition(Definition { value_type: (HexTypeDef { endianness: Endianness::Unkown, name: (HexType::Custom(String::from("Data")), 0..0) }, 0..0), name: blocal!("data"), body: bnum!() - }, 0..0) + }), 0..0) ] }; let ((ex, _), _, _) = parse(test_str, &includeable_folders); @@ -1216,20 +1339,20 @@ fn test_pattern_padding() { ]; let expected_output = Expr::StatementList { list: vec![ - (Expr::Struct { + (Statement::Struct { name: (String::from("TestStruct"), 0..0), body: spanbox!(Expr::StatementList { list: vec![ - (Expr::Definition { + (Statement::Definition(Definition { value_type: (HexTypeDef { endianness: Endianness::Unkown, name: (HexType::V(ValueType::S32), 0..0) }, 0..0), name: blocal!("variable"), body: bnull!() - }, 0..0), - (Expr::Value { val: Value::Num(0.0) }, 0..0), // padding // TODO: Expr for padding instead of value - (Expr::ArrayDefinition { + }), 0..0), + (Statement::Padding { padding_body: (Expr::Value { val: Value::Num(0.0) }, 0..0) }, 0..0), + (Statement::ArrayDefinition { value_type: (HexTypeDef { endianness: Endianness::Unkown, name: (HexType::V(ValueType::U8), 0..0) @@ -1242,14 +1365,14 @@ fn test_pattern_padding() { }), template_parameters: None }, 0..0), - (Expr::Definition { + (Statement::Definition(Definition { value_type: (HexTypeDef { endianness: Endianness::Unkown, name: (HexType::Custom(String::from("TestStruct")), 0..0) }, 0..0), name: blocal!("testStruct"), body: bnum!() - }, 0..0) + }), 0..0) ] }; let ((ex, _), _, _) = parse(test_str, &includeable_folders); @@ -1271,15 +1394,15 @@ fn test_pattern_placement() { ]; let expected_output = Expr::StatementList { list: vec![ - (Expr::Definition { + (Statement::Definition(Definition { value_type: (HexTypeDef { endianness: Endianness::Unkown, name: (HexType::V(ValueType::U32), 0..0) }, 0..0), name: blocal!("placementVar"), body: bnum!() - }, 0..0), - (Expr::ArrayDefinition { + }), 0..0), + (Statement::ArrayDefinition { value_type: (HexTypeDef { endianness: Endianness::Unkown, name: (HexType::V(ValueType::U8), 0..0) @@ -1312,41 +1435,41 @@ fn test_pattern_pointers() { ]; let expected_output = Expr::StatementList { list: vec![ - (Expr::Definition { + (Statement::Definition(Definition { value_type: (HexTypeDef { endianness: Endianness::Unkown, name: (HexType::V(ValueType::U32), 0..0) }, 0..0), name: blocal!("placementPointer"), body: bnum!() - }, 0..0), - (Expr::Definition { + }), 0..0), + (Statement::Definition(Definition { value_type: (HexTypeDef { endianness: Endianness::Unkown, name: (HexType::V(ValueType::U32), 0..0) }, 0..0), name: blocal!("pointerToArray"), body: blocal!("$"), - }, 0..0), - (Expr::Func { + }), 0..0), + (Statement::Func { name: (String::from("Rel"), 0..0), args: (vec![(FuncArgument::Parameter(spanbox!(Expr::UnnamedParameter { type_: (HexType::V(ValueType::U128), 0..0) })), 0..0)], 0..0), body: spanbox!(Expr::StatementList { list: vec![ - (Expr::Return { + (Statement::Return { value: bnum!() }, 0..0) ] }) }, 0..0), - (Expr::Definition { + (Statement::Definition(Definition { value_type: (HexTypeDef { endianness: Endianness::Unkown, name: (HexType::V(ValueType::U32), 0..0) }, 0..0), name: blocal!("pointerRelativeSigned"), body: bnum!() - }, 0..0) + }), 0..0) ] }; let ((ex, _), _, _) = parse(test_str, &includeable_folders); @@ -1372,7 +1495,7 @@ fn test_pattern_rvalues() { A a @ 0x00; "; - + let includeable_folders = vec![ String::from("~/.local/share/imhex"), String::from("/usr/share/imhex"), @@ -1381,18 +1504,18 @@ fn test_pattern_rvalues() { ]; let expected_output = Expr::StatementList { list: vec![ - (Expr::Union { + (Statement::Union { name: (String::from("C"), 0..0), body: spanbox!(Expr::StatementList { list: vec![ - (Expr::Definition { + (Statement::Definition(Definition { value_type: (HexTypeDef { endianness: Endianness::Unkown, name: (HexType::V(ValueType::U8), 0..0) }, 0..0), name: blocal!("y"), body: bnull!() - }, 0..0), - (Expr::ArrayDefinition { + }), 0..0), + (Statement::ArrayDefinition { value_type: (HexTypeDef { endianness: Endianness::Unkown, name: (HexType::V(ValueType::U8), 0..0) @@ -1410,54 +1533,54 @@ fn test_pattern_rvalues() { ] }), template_parameters: None }, 0..0), - (Expr::Struct { + (Statement::Struct { name: (String::from("B"), 0..0), body: spanbox!(Expr::StatementList { list: vec![ - (Expr::Definition { + (Statement::Definition(Definition { value_type: (HexTypeDef { endianness: Endianness::Unkown, name: (HexType::Custom(String::from("C")), 0..0) }, 0..0), name: blocal!("c"), body: bnull!() - }, 0..0) + }), 0..0) ] }), template_parameters: None }, 0..0), - (Expr::Struct { + (Statement::Struct { name: (String::from("A"), 0..0), body: spanbox!(Expr::StatementList { list: vec![ - (Expr::Definition { + (Statement::Definition(Definition { value_type: (HexTypeDef { endianness: Endianness::Unkown, name: (HexType::V(ValueType::U8), 0..0) }, 0..0), name: blocal!("x"), body: bnull!() - }, 0..0), - (Expr::Definition { + }), 0..0), + (Statement::Definition(Definition { value_type: (HexTypeDef { endianness: Endianness::Unkown, name: (HexType::Custom(String::from("B")), 0..0) }, 0..0), name: blocal!("b"), body: bnull!() - }, 0..0) + }), 0..0) ] }), template_parameters: None }, 0..0), - (Expr::Definition { + (Statement::Definition(Definition { value_type: (HexTypeDef { endianness: Endianness::Unkown, name: (HexType::Custom(String::from("A")), 0..0) }, 0..0), name: blocal!("a"), body: bnum!() - }, 0..0) + }), 0..0) ] }; let ((ex, _), _, _) = parse(test_str, &includeable_folders); @@ -1474,7 +1597,7 @@ fn test_pattern_structs() { TestStruct testStruct @ 0x100; "; - + let includeable_folders = vec![ String::from("~/.local/share/imhex"), String::from("/usr/share/imhex"), @@ -1483,19 +1606,19 @@ fn test_pattern_structs() { ]; let expected_output = Expr::StatementList { list: vec![ - (Expr::Struct { + (Statement::Struct { name: (String::from("TestStruct"), 0..0), body: spanbox!(Expr::StatementList { list: vec![ - (Expr::Definition { + (Statement::Definition(Definition { value_type: (HexTypeDef { endianness: Endianness::Unkown, name: (HexType::V(ValueType::S32), 0..0) }, 0..0), name: blocal!("variable"), body: bnull!() - }, 0..0), - (Expr::ArrayDefinition { + }), 0..0), + (Statement::ArrayDefinition { value_type: (HexTypeDef { endianness: Endianness::Unkown, name: (HexType::V(ValueType::U8), 0..0) @@ -1508,14 +1631,14 @@ fn test_pattern_structs() { }), template_parameters: None }, 0..0), - (Expr::Definition { + (Statement::Definition(Definition { value_type: (HexTypeDef { endianness: Endianness::Unkown, name: (HexType::Custom(String::from("TestStruct")), 0..0) }, 0..0), name: blocal!("testStruct"), body: bnum!() - }, 0..0) + }), 0..0) ] }; let ((ex, _), _, _) = parse(test_str, &includeable_folders); @@ -1541,10 +1664,10 @@ fn test_pattern_unions() { ]; let expected_output = Expr::StatementList { list: vec![ - (Expr::Union { + (Statement::Union { name: (String::from("TestUnion"), 0..0), body: spanbox!(Expr::StatementList { list: vec![ - (Expr::ArrayDefinition { + (Statement::ArrayDefinition { value_type: (HexTypeDef { endianness: Endianness::Unkown, name: (HexType::V(ValueType::S32), 0..0) @@ -1553,25 +1676,25 @@ fn test_pattern_unions() { size: bnum!(), body: bnull!() }, 0..0), - (Expr::Definition { + (Statement::Definition(Definition { value_type: (HexTypeDef { endianness: Endianness::Unkown, name: (HexType::V(ValueType::U128), 0..0) }, 0..0), name: blocal!("variable"), body: bnull!() - }, 0..0) + }), 0..0) ] }), template_parameters: None }, 0..0), - (Expr::Definition { + (Statement::Definition(Definition { value_type: (HexTypeDef { endianness: Endianness::Unkown, name: (HexType::Custom(String::from("TestUnion")), 0..0) }, 0..0), name: blocal!("testUnion"), body: bnum!() - }, 0..0) + }), 0..0) ] }; let ((ex, _), _, _) = parse(test_str, &includeable_folders); @@ -1587,14 +1710,14 @@ fn test_pattern_at_in_function() { "; let expected_output = Expr::StatementList { - list: vec![ + list: vec![ ( - Expr::Func { + Statement::Func { name: (String::from("func_with_at"), 0..0), args: (vec![], 0..0), body: spanbox!(Expr::StatementList { list: vec![( - Expr::Definition { + Statement::Definition(Definition { value_type: ( HexTypeDef { endianness: Endianness::Unkown, @@ -1604,7 +1727,7 @@ fn test_pattern_at_in_function() { ), name: blocal!("contents"), body: bnum!(), - }, + }), 0..0, )] })