Update to 1.1.0 #5
7 changed files with 95 additions and 3 deletions
13
pkkg
Normal file
13
pkkg
Normal file
|
@ -0,0 +1,13 @@
|
|||
#This is the pkkg template file
|
||||
l Name Bofa
|
||||
|
||||
t Desc A simple object notation
|
||||
|
||||
l Url https://code.booklordofthe.dev/Booklordofthedings/Bofa
|
||||
|
||||
a Authors
|
||||
o Book
|
||||
l Name Booklordofthedings
|
||||
l Url https://Boooklordofthe.dev
|
||||
|
||||
a Dependencies
|
|
@ -91,7 +91,11 @@ class Bofa
|
|||
}
|
||||
|
||||
}
|
||||
}
|
||||
case .RGB:
|
||||
strBuffer.Append(scope $"rgb {Name} {Value.Rgb[0]:X2)} {Value.Rgb[1]:X2)} {Value.Rgb[2]:X2)}");
|
||||
case .RGBA:
|
||||
strBuffer.Append(scope $"rgb {Name} {Value.Rgba[0]:X2)} {Value.Rgba[1]:X2)} {Value.Rgba[2]:X2)} {Value.Rgba[3]:X2)}");
|
||||
}
|
||||
}
|
||||
|
||||
///Deletes this object without filling the stack
|
||||
|
|
|
@ -178,6 +178,10 @@ class BofaParser
|
|||
typeName = "Array";
|
||||
case "o":
|
||||
typeName = "Object";
|
||||
case "rgb":
|
||||
typeName = "RBG";
|
||||
case "rgba":
|
||||
typeName = "RBGA";
|
||||
default:
|
||||
toReturn.Type = .Error;
|
||||
return toReturn; //Unsupported type error
|
||||
|
@ -306,6 +310,24 @@ class BofaParser
|
|||
case "c":
|
||||
bofaRes.Value.Custom = line;
|
||||
bofaRes.Type = .Custom;
|
||||
case "rgb":
|
||||
bofaRes.Type = .RGB;
|
||||
var result = AdditionalParsers.ParseRGB(line);
|
||||
if(result case .Err)
|
||||
{
|
||||
toReturn.Type = .Error;
|
||||
return toReturn;
|
||||
}
|
||||
bofaRes.Value.Rgb = result.Value;
|
||||
case "rgba":
|
||||
bofaRes.Type = .RGBA;
|
||||
var result = AdditionalParsers.ParseRGBA(line);
|
||||
if(result case .Err)
|
||||
{
|
||||
toReturn.Type = .Error;
|
||||
return toReturn;
|
||||
}
|
||||
bofaRes.Value.Rgba = result.Value;
|
||||
default: //Unknown type
|
||||
toReturn.Type = .Error;
|
||||
return toReturn;
|
||||
|
|
|
@ -18,4 +18,6 @@ struct BofaValue
|
|||
public StringView Custom;
|
||||
public Dictionary<StringView, Bofa> Object;
|
||||
public List<Bofa> Array;
|
||||
public uint8[3] Rgb;
|
||||
public uint8[4] Rgba;
|
||||
}
|
43
src/Parser/AdditionalParsers.bf
Normal file
43
src/Parser/AdditionalParsers.bf
Normal file
|
@ -0,0 +1,43 @@
|
|||
namespace Bofa.Parser;
|
||||
|
||||
using System;
|
||||
|
||||
class AdditionalParsers
|
||||
{
|
||||
public static Result<uint8[3]> ParseRGB(StringView pValue)
|
||||
{
|
||||
uint8[3] toReturn = .(0,0,0);
|
||||
var parts = pValue.Split(' ');
|
||||
int idx = 0;
|
||||
for(var part in parts)
|
||||
{
|
||||
defer {idx = idx + 1;}
|
||||
|
||||
var res = uint8.Parse(part, .Hex);
|
||||
if(res case .Err)
|
||||
return .Err;
|
||||
|
||||
toReturn[idx] = res.Value;
|
||||
}
|
||||
return .Ok(toReturn);
|
||||
}
|
||||
|
||||
public static Result<uint8[4]> ParseRGBA(StringView pValue)
|
||||
{
|
||||
uint8[4] toReturn = .(0,0,0,0);
|
||||
var parts = pValue.Split(' ');
|
||||
int idx = 0;
|
||||
for(var part in parts)
|
||||
{
|
||||
defer {idx = idx + 1;}
|
||||
|
||||
var res = uint8.Parse(part, .HexNumber);
|
||||
if(res case .Err)
|
||||
return .Err;
|
||||
|
||||
toReturn[idx] = res.Value;
|
||||
}
|
||||
return .Ok(toReturn);
|
||||
}
|
||||
|
||||
}
|
|
@ -28,12 +28,16 @@ class Default
|
|||
a array
|
||||
b content true
|
||||
b content true
|
||||
|
||||
# 1.1.0
|
||||
rgba color FF FF FF FF
|
||||
rgb c 34 67 EF
|
||||
""";
|
||||
Dictionary<StringView, Bofa> output = new .();
|
||||
List<int64> errors = new .();
|
||||
BofaParser.Parse(content, output, errors);
|
||||
|
||||
Test.Assert(output.Count == 9);
|
||||
Test.Assert(output.Count == 11);
|
||||
Test.Assert(errors.Count == 0);
|
||||
|
||||
DeleteDictionaryAndValues!(output);
|
||||
|
|
|
@ -13,5 +13,9 @@ enum EBofaType
|
|||
Boolean, //8bit true or false
|
||||
Object, // Key-Value container
|
||||
Array, //Numeric container
|
||||
Custom //String with a type attached to it
|
||||
Custom, //String with a type attached to it
|
||||
|
||||
//1.1.0
|
||||
RGB, //3 * 8bit
|
||||
RGBA //4 * 8bit
|
||||
}
|
Loading…
Add table
Reference in a new issue