AuroraRuntime/Include/Aurora/Parse/Parser.hpp
Reece cf70f0d45c [*/+/-] MEGA COMMIT. ~2 weeks compressed.
The intention is to quickly improve and add util apis, enhance functionality given current demands, go back to the build pipeline, finish that, publish runtime tests, and then use what we have to go back to to linux support with a more stable api.

[+] AuMakeSharedArray
[+] Technet ArgvQuote
[+] Grug subsystem (UNIX signal thread async safe ipc + telemetry flusher + log flusher.)
[+] auEndianness -> Endian swap utils
[+] AuGet<N>(...)
[*] AUE_DEFINE conversion for
        ECompresionType, EAnsiColor, EHashType, EStreamError, EHexDump
[+] ConsoleMessage ByteBuffer serialization
[+] CmdLine subsystem for parsing command line arguments and simple switch/flag checks
[*] Split logger from console subsystem
[+] StartupParameters -> A part of a clean up effort under Process
[*] Refactor SysErrors header + get caller hack
[+] Atomic APIs
[+] popcnt
[+] Ring Buffer sink
[+] Added more standard errors
        Catch,
        Submission,
        LockError,
        NoAccess,
        ResourceMissing,
        ResourceLocked,
        MalformedData,
        InSandboxContext,
        ParseError

[+] Added ErrorCategorySet, ErrorCategoryClear, GetStackTrace
[+] IExitSubscriber, ETriggerLevel
[*] Write bias the high performance RWLockImpl read-lock operation operation
[+] ExitHandlerAdd/ExitHandlerRemove (exit subsystem)
[*] Updated API style
        Digests
[+] CpuId::CpuBitCount
[+] GetUserProgramsFolder
[+] GetPackagePath
[*] Split IStreamReader with an inl file
[*] BlobWriter/BlobReader/BlobArbitraryReader can now take shared pointers to bytebuffers. default constructor allocates a new scalable bytebuffer
[+] ICharacterProvider
[+] ICharacterProviderEx
[+] IBufferedCharacterConsumer
[+] ProviderFromSharedString
[+] ProviderFromString
[+] BufferConsumerFromProvider
[*] Parse Subsystem uses character io bufferer
[*] Rewritten NT's high perf semaphore to use userland SRW/ConVars [like mutex, based on generic semaphore]
[+] ByteBuffer::ResetReadPointer
[*] Bug fix bytebuffer base not reset on free and some scaling issues
[+] ProcessMap -> Added kSectionNameStack, kSectionNameFile, kSectionNameHeap for Section
[*] ProcessMap -> Refactor Segment to Section. I was stupid for keeping a type conflict hack API facing
[+] Added 64 *byte* fast RNG seeds
[+] File Advisorys/File Lock Awareness
[+] Added extended IAuroraThread from OS identifier caches for debug purposes
[*] Tweaked how memory is reported on Windows. Better consistency of what values mean across functions.
[*] Broke AuroraUtils/Typedefs out into a separate library
[*] Update build script
[+] Put some more effort into adding detail to the readme before rewriting it, plus, added some media
[*] Improved public API documentation
[*] Bug fix `SetConsoleCtrlHandler`
[+] Locale TimeDateToFileNameISO8601
[+] Console config stdOutShortTime
[*] Begin using internal UTF8/16 decoders when platform support isnt available (instead of stl)
[*] Bug fixes in decoders
[*] Major bug fix, AuMax
[+] RateLimiter
[+] Binary file sink
[+] Log directory sink
[*] Data header usability (more operators)
[+] AuRemoveRange
[+] AuRemove
[+] AuTryRemove
[+] AuTryRemoveRange
[+] auCastUtils
[+] Finish NewLSWin32Source
[+] AuTryFindByTupleN, AuTryRemoveByTupleN
[+] Separated AuRead/Write types, now in auTypeUtils
[+] Added GetPosition/SetPosition to FileWriter
[*] Fix stupid AuMin in place of AuMax in SpawnThread.Unix.Cpp
[*] Refactored Arbitrary readers to SeekingReaders (as in, they could be atomic and/or parallelized, and accept an arbitrary position as a work parameter -> not Seekable, as in, you can simply set the position)
[*] Hack back in the sched deinit
[+] File AIO loop source interop
[+] Begin to prototype a LoopQueue object I had in mind for NT, untested btw
[+] Stub code for networking
[+] Compression BaseStream/IngestableStreamBase
[*] Major: read/write locks now support write-entrant read routines.
[*] Compression subsystem now uses the MemoryView concept
[*] Rewrite the base stream compressions, made them less broken
[*] Update hashing api
[*] WriterTryGoForward and ReaderTryGoForward now revert to the previous relative index instead of panicing
[+] Added new AuByteBuffer apis
    Trim, Pad, WriteFrom, WriteString, [TODO: ReadString]
[+] Added ByteBufferPushReadState
[+] Added ByteBufferPushWriteState
[*] Move from USC-16 to full UTF-16. Win32 can handle full UTF-16.
[*] ELogLevel is now an Aurora enum
[+] Raised arbitrary limit in header to 255, the max filter buffer
[+] Explicit GZip support
[+] Explicit Zip support
[+] Added [some] compressors

et al
2022-02-17 00:11:40 +00:00

195 lines
6.0 KiB
C++

/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: Parser.hpp
Date: 2021-6-9
Author: Reece
***/
#pragma once
#include <Aurora/Data/Data.hpp>
#include <Aurora/IO/Character/ICharacterProvider.hpp>
#include <Aurora/IO/Character/ICharacterProviderEx.hpp>
#include <Aurora/IO/Character/IBufferedCharacterConsumer.hpp>
#include <Aurora/IO/Character/Providers.hpp>
namespace Aurora::Parse
{
enum class ParsableTag
{
kParseUInt = (const int)Data::EDataType::kTypeUInt,
kParseSInt = (const int)Data::EDataType::kTypeSInt,
kParseNumber = (const int)Data::EDataType::kTypeNumber,
kParseString = (const int)Data::EDataType::kTypeString,
kParseBoolean = (const int)Data::EDataType::kTypeBoolean,
kParseUUID = (const int)Data::EDataType::kTypeUUID,
kParseVec3 = (const int)Data::EDataType::kTypeVec3,
kParseVec4 = (const int)Data::EDataType::kTypeVec4,
kParseObject,
kParseStringVararg
};
struct ParseBit;
struct ParsedBit;
using ParseObject = AuList<ParseBit>;
using ParsedObject = AuList<ParsedBit>;
using ParsePrimativeValue = Data::PrimitiveValue;
using ParseValue = Data::Value;
struct ParseValueEx : ParseValue
{
ParsedObject object;
};
struct ParseBit
{
ParseBit(ParsableTag tag, const AuString &label) : tag(tag), label(label)
{}
ParseBit(ParsableTag tag, const AuString &label, bool array, bool optional, bool _vararg) : tag(tag), label(label), array(array), optional(optional), vararg(_vararg)
{}
ParseBit(ParsableTag tag) : tag(tag)
{}
ParseBit(ParsableTag tag, bool array, bool optional, bool _vararg) : tag(tag), array(array), optional(optional), vararg(_vararg)
{}
ParseBit(ParseObject _ObjectParse) : tag(ParsableTag::kParseObject), objectParse(_ObjectParse)
{}
ParseBit(ParseObject _ObjectParse, const AuString &label) : tag(ParsableTag::kParseObject), objectParse(_ObjectParse), label(label)
{}
// marks this "parse bit" and all following part bits optional
bool optional = false;
// if true, the lexer yoinks a length prefix token before iterating over array length
bool array = false;
// if true, the lexer parses tag or object parse until EOS
bool vararg = false;
// parse defintion
ParsableTag tag;
ParseObject objectParse;
// optional:
AuString label = "";
// parse object
// {...}
// single parse bit:
// <tag-label: value>
// optional:
// <max-number: value> <min-number: value> (<min-number: value>)
// var arg:
// <max-number: value> <min-number: value> (<min-number: value> ...)
// arrays
// <max-number: value> <min-number: value> [<array count> <min-number: value>]
};
struct ParsedBit
{
ParsedBit()
{}
ParsedBit(ParsableTag tag) : tag(tag)
{}
AuMach count;
ParsableTag tag;
bool isArray;
struct
{
ParseValueEx single;
AuList<ParseValueEx> array;
} value;
};
struct ParseResult
{
AuString syntaxError;
AuString debugTree;
ParsedObject result;
};
#if 0
using ConsumeStream_cb = AuFunction<bool(AuUInt8 &)>;
static ConsumeStream_cb StringToConsumable(const AuString &str, AuMach &index)
{
auto getc = [&](AuUInt8 &byt) mutable
{
if (index == str.length())
{
return false;
}
byt = str[index];
index++;
return true;
};
return getc;
}
#endif
struct ParseState
{
ParseState(const AuSPtr<Aurora::IO::Character::ICharacterProvider> &stream) : stream(stream)
{}
AuSPtr<Aurora::IO::Character::ICharacterProvider> stream;
AuUInt8 *additionalTokens {};
AuUInt16 countOfTokens {};
bool hasLastToken {};
AuUInt8 lastTokenCharacter {};
AuMach lastTokenAdditional {};
};
AUKN_SYM void VaildateStructure(const ParseObject &object);
AUKN_SYM bool ConsumeToken(ParsableTag type, const AuSPtr<Aurora::IO::Character::ICharacterProvider> &getc, ParseValue &out);
static bool ConsumeToken(ParsableTag type, const AuString &str, AuMach &index, ParseValueEx &out)
{
auto strStream = IO::Character::ProviderFromStringUnique(str, index);
if (!strStream) return false;
if (!ConsumeToken(type, AuUnsafeRaiiToShared(strStream), out)) return false;
index = strStream->GetPosition();
return true;
}
static bool ConsumeToken(ParsableTag type, const AuString &str, ParseValueEx &out)
{
auto strStream = IO::Character::ProviderFromStringUnique(str);
if (!strStream) return false;
return ConsumeToken(type, AuUnsafeRaiiToShared(strStream), out);
}
AUKN_SYM bool Parse(ParseState &state, const ParseObject &structure, ParseResult &result);
static bool Parse(ParseResult &result, const ParseObject &structure, const AuString &str, AuMach &index)
{
auto strStream = IO::Character::ProviderFromStringUnique(str, index);
if (!strStream) return false;
ParseState state(AuUnsafeRaiiToShared(strStream));
if (!Parse(state, structure, result)) return false;
index = strStream->GetPosition();
return true;
}
static bool Parse(ParseResult &result, const ParseObject &structure, const AuString &str)
{
auto strStream = IO::Character::ProviderFromStringUnique(str, 0);
if (!strStream) return false;
ParseState state(AuUnsafeRaiiToShared(strStream));
return Parse(state, structure, result);
}
AUKN_SYM void SerializeToken(ParsableTag type, const ParseValue &value, AuString &str);
AUKN_SYM void Serialize(const ParsedObject &structure, AuString &ret);
}