80 lines
No EOL
1.7 KiB
Beef
80 lines
No EOL
1.7 KiB
Beef
namespace Bofa;
|
|
|
|
using Bofa.Parser;
|
|
|
|
using System;
|
|
|
|
extension Bofa
|
|
{
|
|
[Inline]
|
|
private Result<void> _Insert(ParserEntry* pToAdd)
|
|
{
|
|
Bofa target = this;
|
|
while(!(pToAdd.Depth == 0 || (pToAdd.Type == .Text && pToAdd.Depth == 1)))
|
|
{
|
|
if(target == null || !(target.Type == .Object || target.Type == .Array))
|
|
return .Err;
|
|
|
|
pToAdd.Depth--;
|
|
target = target._lastObject;
|
|
}
|
|
|
|
if(pToAdd.Type == .Text && target.Type == .Text)
|
|
{
|
|
target.Value.Text.Append(scope $"\n{pToAdd.Data.Text}");
|
|
return .Ok;
|
|
}
|
|
else if(target.Type == .Object)
|
|
{
|
|
if(target.Value.Object.ContainsKey(pToAdd.Data.Bofa.Name))
|
|
return .Err;
|
|
target.Value.Object.Add(pToAdd.Data.Bofa.Name, pToAdd.Data.Bofa);
|
|
target._lastObject = pToAdd.Data.Bofa;
|
|
return .Ok;
|
|
|
|
}
|
|
else if(target.Type == .Array)
|
|
{
|
|
target.Value.Array.Add(pToAdd.Data.Bofa);
|
|
target._lastObject = pToAdd.Data.Bofa;
|
|
return .Ok;
|
|
}
|
|
return .Err;
|
|
|
|
/*
|
|
//See if we can insert and do so
|
|
if(pToAdd.Depth == 0 || (pToAdd.Type == .Text && pToAdd.Depth == 1))
|
|
{
|
|
if(pToAdd.Type == .Text && Type == .Text)
|
|
{
|
|
Value.Text.Append(scope $"\n{pToAdd.Data.Text}");
|
|
return .Ok;
|
|
}
|
|
else if(Type == .Object)
|
|
{
|
|
if(Value.Object.ContainsKey(pToAdd.Data.Bofa.Name))
|
|
return .Err;
|
|
Value.Object.Add(pToAdd.Data.Bofa.Name, pToAdd.Data.Bofa);
|
|
_lastObject = pToAdd.Data.Bofa;
|
|
return .Ok;
|
|
|
|
}
|
|
else if(Type == .Array)
|
|
{
|
|
Value.Array.Add(pToAdd.Data.Bofa);
|
|
_lastObject = pToAdd.Data.Bofa;
|
|
return .Ok;
|
|
}
|
|
|
|
return .Err; //Cannot insert here
|
|
}
|
|
|
|
//Can we even go deeper
|
|
if(_lastObject == null || !(_lastObject.Type == .Object || _lastObject.Type == .Array))
|
|
return .Err;
|
|
|
|
pToAdd.Depth--;
|
|
return _lastObject._Insert(pToAdd);
|
|
*/
|
|
}
|
|
} |