diff --git a/BeefProj.toml b/BeefProj.toml index ddfd45a..0d15fdc 100644 --- a/BeefProj.toml +++ b/BeefProj.toml @@ -2,4 +2,5 @@ FileVersion = 1 [Project] Name = "Bofa" +TargetType = "BeefLib" StartupObject = "Bofa.Program" diff --git a/src/Bofa.bf b/src/Bofa.bf index 779fd58..1dc3fb3 100644 --- a/src/Bofa.bf +++ b/src/Bofa.bf @@ -6,7 +6,7 @@ using System.Collections; class Bofa { - private String _line = null ~ if(_ != null) delete _; //The actual line + private String _line = null ~ delete _; //The actual line private Bofa _lastObject = null; //If we are a container we keep track of the last container inside of us public StringView Name; @@ -29,13 +29,13 @@ class Bofa if(target.Type == .Array) { depth++; - for(var i in Value.Array.Reversed) + for(var i in target.Value.Array.Reversed) toProcess.Add((depth, i)); } else if(target.Type == .Object) { depth++; - for(var i in Value.Object) + for(var i in target.Value.Object) toProcess.Add((depth, i.value)); } @@ -60,6 +60,8 @@ class Bofa strBuffer.Append(scope $"a {Name}"); case .BigInteger: strBuffer.Append(scope $"bi {Name} {Value.BigInteger}"); + case .BigUnsignedInteger: + strBuffer.Append(scope $"bui {Name} {Value.BigUnsignedInteger}"); case .BigNumber: strBuffer.Append(scope $"bn {Name} {Value.BigNumber:R}"); case .Boolean: @@ -68,6 +70,8 @@ class Bofa strBuffer.Append(scope $"c {Typename} {Name} {Value.Custom}"); case .Integer: strBuffer.Append(scope $"i {Name} {Value.Integer}"); + case .UnsignedInteger: + strBuffer.Append(scope $"ui {Name} {Value.UnsignedInteger}"); case .Line: strBuffer.Append(scope $"l {Name} {Value.Line}"); case .Number: diff --git a/src/BofaParser.bf b/src/BofaParser.bf index ab8272c..64c3f7e 100644 --- a/src/BofaParser.bf +++ b/src/BofaParser.bf @@ -50,7 +50,7 @@ class BofaParser } if (entry.Type == .Error) { - if(entry.Data.Bofa != null) + if (entry.Data.Bofa != null) delete entry.Data.Bofa; pErrors.Add(line); continue; @@ -168,6 +168,10 @@ class BofaParser typeName = "Integer"; case "bi": typeName = "BigInteger"; + case "ui": + typeName = "UnsignedInteger"; + case "bui": + typeName = "BigUnsignedInteger"; case "t": typeName = "Text"; case "a": @@ -208,7 +212,7 @@ class BofaParser bofaRes.Type = .Array; bofaRes.Value.Array = new .(); } - + return toReturn; } #endregion @@ -278,7 +282,24 @@ class BofaParser toReturn.Type = .Error; return toReturn; } - bofaRes.Value.BigInteger = result.Value; + case "ui": + bofaRes.Type = .UnsignedInteger; + var result = uint32.Parse(line); + if (result case .Err) + { + toReturn.Type = .Error; + return toReturn; + } + bofaRes.Value.UnsignedInteger = result.Value; + case "bui": + bofaRes.Type = .BigUnsignedInteger; + var result = uint64.Parse(line); + if (result case .Err) + { + toReturn.Type = .Error; + return toReturn; + } + bofaRes.Value.BigUnsignedInteger = result.Value; case "t": bofaRes.Value.Text = new String(line); bofaRes.Type = .Text; diff --git a/src/BofaValue.bf b/src/BofaValue.bf index ad60bd0..2399e0e 100644 --- a/src/BofaValue.bf +++ b/src/BofaValue.bf @@ -12,6 +12,8 @@ struct BofaValue public double BigNumber; public int32 Integer; public int64 BigInteger; + public uint32 UnsignedInteger; + public uint64 BigUnsignedInteger; public bool Boolean; public StringView Custom; public Dictionary Object; diff --git a/src/Extension.bf b/src/Extension.bf index bacdd8c..606e67d 100644 --- a/src/Extension.bf +++ b/src/Extension.bf @@ -1,4 +1,8 @@ using Bofa.Serialization; +using Bofa; +using System; +using System.Collections; + namespace System { @@ -11,6 +15,63 @@ namespace System } extension Int : IBofaParseable + { + public bool Serialize(Bofa.Bofa pTarget) + { + pTarget.Type = .Integer; + pTarget.Typename = "Integer"; + pTarget.Value.Integer = (.)Math.Clamp(this, int32.MinValue, int32.MaxValue); + return true; + } + + public bool Deserialize(Bofa.Bofa pInput) mut + { + if(pInput.Type != .Integer) + return false; + this = Math.Clamp(pInput.Value.Integer, int.MaxValue, int.MinValue); + return true; + } + } + + extension Int8 : IBofaParseable + { + public bool Serialize(Bofa.Bofa pTarget) + { + pTarget.Type = .Integer; + pTarget.Typename = "Integer"; + pTarget.Value.Integer = (.)Math.Clamp(this, int8.MinValue, int8.MaxValue); + return true; + } + + public bool Deserialize(Bofa.Bofa pInput) mut + { + if(pInput.Type != .Integer) + return false; + this = (.)Math.Clamp(pInput.Value.Integer, int8.MaxValue, int8.MinValue); + return true; + } + } + + extension Int16 : IBofaParseable + { + public bool Serialize(Bofa.Bofa pTarget) + { + pTarget.Type = .Integer; + pTarget.Typename = "Integer"; + pTarget.Value.Integer = (.)Math.Clamp(this, int16.MinValue, int16.MaxValue); + return true; + } + + public bool Deserialize(Bofa.Bofa pInput) mut + { + if(pInput.Type != .Integer) + return false; + this = (.)Math.Clamp(pInput.Value.Integer, int16.MaxValue, int16.MinValue); + return true; + } + } + + extension Int32 : IBofaParseable { public bool Serialize(Bofa.Bofa pTarget) { @@ -28,4 +89,425 @@ namespace System return true; } } + + extension Int64 : IBofaParseable + { + public bool Serialize(Bofa.Bofa pTarget) + { + pTarget.Type = .BigInteger; + pTarget.Typename = "BigInteger"; + pTarget.Value.BigInteger = (.)this; + return true; + } + + public bool Deserialize(Bofa.Bofa pInput) mut + { + if(pInput.Type != .BigInteger) + return false; + this = (.)pInput.Value.BigInteger; + return true; + } + } + + extension UInt : IBofaParseable + { + public bool Serialize(Bofa.Bofa pTarget) + { + pTarget.Type = .UnsignedInteger; + pTarget.Typename = "UnsignedInteger"; + pTarget.Value.UnsignedInteger = (.)Math.Clamp(this, uint32.MinValue, uint32.MaxValue); + return true; + } + + public bool Deserialize(Bofa.Bofa pInput) mut + { + if(pInput.Type != .UnsignedInteger) + return false; + this = (.)Math.Clamp(pInput.Value.UnsignedInteger, uint.MaxValue, uint.MinValue); + return true; + } + } + + extension UInt8 : IBofaParseable + { + public bool Serialize(Bofa.Bofa pTarget) + { + pTarget.Type = .UnsignedInteger; + pTarget.Typename = "UnsignedInteger"; + pTarget.Value.UnsignedInteger = (.)Math.Clamp(this, uint8.MinValue, uint8.MaxValue); + return true; + } + + public bool Deserialize(Bofa.Bofa pInput) mut + { + if(pInput.Type != .UnsignedInteger) + return false; + this = (.)Math.Clamp(pInput.Value.UnsignedInteger, uint8.MaxValue, uint8.MinValue); + return true; + } + } + + extension UInt16 : IBofaParseable + { + public bool Serialize(Bofa.Bofa pTarget) + { + pTarget.Type = .UnsignedInteger; + pTarget.Typename = "UnsignedInteger"; + pTarget.Value.UnsignedInteger = (.)Math.Clamp(this, uint16.MinValue, uint16.MaxValue); + return true; + } + + public bool Deserialize(Bofa.Bofa pInput) mut + { + if(pInput.Type != .UnsignedInteger) + return false; + this = (.)Math.Clamp(pInput.Value.UnsignedInteger, uint16.MaxValue, uint16.MinValue); + return true; + } + } + + extension UInt32 : IBofaParseable + { + public bool Serialize(Bofa.Bofa pTarget) + { + pTarget.Type = .UnsignedInteger; + pTarget.Typename = "UnsignedInteger"; + pTarget.Value.UnsignedInteger = (.)Math.Clamp(this, uint32.MinValue, uint32.MaxValue); + return true; + } + + public bool Deserialize(Bofa.Bofa pInput) mut + { + if(pInput.Type != .UnsignedInteger) + return false; + this = (.)Math.Clamp(pInput.Value.UnsignedInteger, uint32.MaxValue, uint32.MinValue); + return true; + } + } + + extension UInt64 : IBofaParseable + { + public bool Serialize(Bofa.Bofa pTarget) + { + pTarget.Type = .BigUnsignedInteger; + pTarget.Typename = "BigUnsignedInteger"; + pTarget.Value.BigUnsignedInteger = (.)Math.Clamp(this, uint64.MinValue, uint64.MaxValue); + return true; + } + + public bool Deserialize(Bofa.Bofa pInput) mut + { + if(pInput.Type != .BigUnsignedInteger) + return false; + this = (.)Math.Clamp(pInput.Value.BigUnsignedInteger, uint64.MaxValue, uint64.MinValue); + return true; + } + } + + extension Char8 : IBofaParseable + { + public bool Serialize(Bofa.Bofa pTarget) + { + pTarget.Type = .Text; + pTarget.Typename = "Text"; + pTarget.Value.Text = new String()..Append(this); + return true; + } + + public bool Deserialize(Bofa.Bofa pInput) mut + { + if(pInput.Type == .Text) + this = pInput.Value.Text[0]; + else if(pInput.Type == .Line) + this = pInput.Value.Line[0]; + else + return false; + return true; + } + } + + extension Char16 : IBofaParseable + { + public bool Serialize(Bofa.Bofa pTarget) + { + pTarget.Type = .Text; + pTarget.Typename = "Text"; + pTarget.Value.Text = new String()..Append(this); + return true; + } + + public bool Deserialize(Bofa.Bofa pInput) mut + { + if(pInput.Type == .Text) + this = pInput.Value.Text[0]; + else if(pInput.Type == .Line) + this = pInput.Value.Line[0]; + else + return false; + return true; + } + } + + extension Char32 : IBofaParseable + { + public bool Serialize(Bofa.Bofa pTarget) + { + pTarget.Type = .Text; + pTarget.Typename = "Text"; + pTarget.Value.Text = new String()..Append(this); + return true; + } + + public bool Deserialize(Bofa.Bofa pInput) mut + { + if(pInput.Type == .Text) + this = pInput.Value.Text[0]; + else if(pInput.Type == .Line) + this = pInput.Value.Line[0]; + else + return false; + return true; + } + } + + extension Float : IBofaParseable + { + public bool Serialize(Bofa.Bofa pTarget) + { + pTarget.Type = .Number; + pTarget.Typename = "Number"; + pTarget.Value.Number = (.)this; + return true; + } + + public bool Deserialize(Bofa.Bofa pInput) mut + { + if(pInput.Type != .Number) + return false; + this = (.)pInput.Value.Number; + return true; + } + } + + extension Double : IBofaParseable + { + public bool Serialize(Bofa.Bofa pTarget) + { + pTarget.Type = .BigNumber; + pTarget.Typename = "BigNumber"; + pTarget.Value.BigNumber = (.)this; + return true; + } + + public bool Deserialize(Bofa.Bofa pInput) mut + { + if(pInput.Type != .BigNumber) + return false; + this = (.)pInput.Value.BigNumber; + return true; + } + } + + extension String : IBofaParseable + { + public bool Serialize(Bofa.Bofa pTarget) + { + if(this.Contains('\n')) + { + pTarget.Type = .Text; + pTarget.Typename = "Text"; + pTarget.Value.Text = new .(this); + } + else + { + pTarget.Type = .Line; + pTarget.Typename = "Line"; + pTarget.Value.Line = this; + } + return true; + } + + public bool Deserialize(Bofa.Bofa pInput) + { + this.Clear(); + if(pInput.Type == .Line) + this.Append(pInput.Value.Line); + else if(pInput.Type == .Text) + this.Append(pInput.Value.Text); + else + return false; + return true; + } + + } +} + +namespace System.Collections +{ + extension List : IBofaParseable where T : IBofaParseable where T : new where T : delete where T : class + { + public bool Serialize(Bofa.Bofa pTarget) + { + pTarget.Type = .Array; + pTarget.Typename = "Array"; + pTarget.Value.Array = new .(this.Count); + for(var i in this) + { + Bofa toAdd = new .(); + toAdd.[Friend]_line = new .(@i.Index); + toAdd.Name = toAdd.[Friend]_line; + if(!i.Serialize(toAdd)) + { + delete toAdd; + continue; + } + else + { + pTarget.Value.Array.Add(toAdd); + continue; + } + } + return true; + } + + public bool Deserialize(Bofa.Bofa pInput) + { + if(pInput.Type != .Array) + return false; + for(var i in pInput.Value.Array) + { + var toParse = new T(); + if(!toParse.Deserialize(i)) + delete toParse; + else + this.Add((.)toParse); + + } + return true; + } + } + + extension List : IBofaParseable where T : IBofaParseable where T : struct where T : new + { + public bool Serialize(Bofa.Bofa pTarget) + { + pTarget.Type = .Array; + pTarget.Typename = "Array"; + pTarget.Value.Array = new .(this.Count); + for(var i in this) + { + Bofa toAdd = new .(); + toAdd.[Friend]_line = new .(@i.Index); + toAdd.Name = toAdd.[Friend]_line; + if(!i.Serialize(toAdd)) + { + delete toAdd; + continue; + } + else + { + pTarget.Value.Array.Add(toAdd); + continue; + } + } + return true; + } + + public bool Deserialize(Bofa.Bofa pInput) + { + if(pInput.Type != .Array) + return false; + for(var i in pInput.Value.Array) + { + var toParse = T(); + if(toParse.Deserialize(i)) + this.Add((.)toParse); + + } + return true; + } + } + + extension Dictionary : IBofaParseable where TKey : String where TValue : IBofaParseable where TValue : new where TValue : delete where TValue : class + { + public bool Serialize(Bofa.Bofa pTarget) + { + pTarget.Type = .Object; + pTarget.Typename = "Object"; + pTarget.Value.Object = new .(); + for(var i in this) + { + Bofa toAdd = new .(); + toAdd.[Friend]_line = new .(@i.Key); + toAdd.Name = toAdd.[Friend]_line; + if(!i.value.Serialize(toAdd)) + { + delete toAdd; + continue; + } + else + { + pTarget.Value.Array.Add(toAdd); + continue; + } + } + return true; + } + + public bool Deserialize(Bofa.Bofa pInput) + { + if(pInput.Type != .Object) + return false; + for(var i in pInput.Value.Object) + { + var toParse = new TValue(); + if(toParse.Deserialize(i.value)) + this.Add(new .(i.key), toParse); + else + delete toParse; + + } + return true; + } + } + + extension Dictionary : IBofaParseable where TKey : String where TValue : IBofaParseable where TValue : new where TValue : struct + { + public bool Serialize(Bofa.Bofa pTarget) + { + pTarget.Type = .Object; + pTarget.Typename = "Object"; + pTarget.Value.Object = new .(); + for(var i in this) + { + Bofa toAdd = new .(); + toAdd.[Friend]_line = new .(@i.Key); + toAdd.Name = toAdd.[Friend]_line; + if(!i.value.Serialize(toAdd)) + { + delete toAdd; + continue; + } + else + { + pTarget.Value.Array.Add(toAdd); + continue; + } + } + return true; + } + + public bool Deserialize(Bofa.Bofa pInput) + { + if(pInput.Type != .Object) + return false; + for(var i in pInput.Value.Object) + { + var toParse = TValue(); + if(toParse.Deserialize(i.value)) + this.Add(new .(i.key), toParse); + } + return true; + } + } } \ No newline at end of file diff --git a/src/Program.bf b/src/Program.bf deleted file mode 100644 index 8db8381..0000000 --- a/src/Program.bf +++ /dev/null @@ -1,21 +0,0 @@ -namespace Bofa; - -using System; -using System.Collections; - -class Program -{ - - public static void Main() - { - Bofa.Testing.Profiling.Profiling_Depth_Testing(); - Bofa.Testing.Profiling.Profiling_Depth_Testing_Medium(); - Bofa.Testing.Profiling.Profiling_Normal(); - Bofa.Testing.Profiling.Profiling_Normal_Medium(); - Bofa.Testing.Profiling.Profiling_Normal_Large(); - Bofa.Testing.Profiling.Profiling_Texts(); - Bofa.Testing.Profiling.Profiling_Texts_Large(); - - Console.Read(); - } -} \ No newline at end of file diff --git a/src/Testing/Consistency.bf b/src/Testing/Consistency.bf deleted file mode 100644 index 6541d4d..0000000 --- a/src/Testing/Consistency.bf +++ /dev/null @@ -1,45 +0,0 @@ -namespace Bofa.Testing; - -using Bofa; - -using System; -using System.Collections; - -class Consistency -{ - [Test(Name="Reverse simple")] - public static void Standart() - { - String content = """ - l one line of text - b bool true - t textgoes here - - Text addendum - n tone 12.5 - bn biggie 65645654535.553001 - i int 234345 - bi bint 38432847329847329 - o object - b content true - a array - b content true - b content true - """; - Dictionary output = new .(); - List errors = new .(); - BofaParser.Parse(content, output, errors); - - String s = scope .(); - for(var i in output) - { - i.value.ToString(s); - s.Append('\n'); - } - s.RemoveFromEnd(1); - - Test.Assert(content == s); - - DeleteDictionaryAndValues!(output); - delete errors; - } -} \ No newline at end of file diff --git a/src/Testing/Fuzzing.bf b/src/Testing/Fuzzing.bf index 08ddd0a..4374964 100644 --- a/src/Testing/Fuzzing.bf +++ b/src/Testing/Fuzzing.bf @@ -7,7 +7,7 @@ using System.Collections; class Fuzzing { - //[Test(Name = "Fuzzing - 10 * 1000000 random characters")] + [Test(Name = "Fuzzing - 10 * 1000000 random characters")] public static void Fuzzin_Random() { for (int i < 10) @@ -25,7 +25,7 @@ class Fuzzing } } - //[Test(Name = "Fuzzing - 10 * 10000000 random characters")] + [Test(Name = "Fuzzing - 10 * 10000000 random characters")] public static void Fuzzin_Random_Large() { for (int i < 10) diff --git a/src/Testing/Serialization.bf b/src/Testing/Serialization.bf index 6baaa0a..6c21d96 100644 --- a/src/Testing/Serialization.bf +++ b/src/Testing/Serialization.bf @@ -1,6 +1,7 @@ namespace Bofa.Testing; using System; +using System.Collections; using Bofa; using Bofa.Serialization; @@ -8,18 +9,19 @@ using Bofa.Serialization; [BofaSerialize] class Serialization { - public int anInteger = (.)1; + public int anInteger = 1; + public String aString = "Value"; + public List listOfStrings = new .() ~ DeleteContainerAndItems!(_); [Test] public static void Test() { Serialization s = scope .(); + s.listOfStrings.Add(new .("dfdsfdsfdsf")); Bofa b = scope .(); b.Name = "s"; s.Serialize(b); - Console.WriteLine(b.ToString(.. scope .())); - //Console.Read(); } } \ No newline at end of file diff --git a/src/eBofaType.bf b/src/eBofaType.bf index d3e253c..d3dab82 100644 --- a/src/eBofaType.bf +++ b/src/eBofaType.bf @@ -8,6 +8,8 @@ enum EBofaType BigNumber, //64bit floating point number Integer, //32bit signed integer BigInteger, //64bit signed integer + UnsignedInteger, //32bit unsigned integer + BigUnsignedInteger, //64bit unsigned integer Boolean, //8bit true or false Object, // Key-Value container Array, //Numeric container