About to overhaul WingTypes
This commit is contained in:
@@ -44,11 +44,11 @@ WingCharacterClasses::WingCharacterClasses()
|
|||||||
|
|
||||||
WingCharacterClasses WingCharacterClasses::TheSet;
|
WingCharacterClasses WingCharacterClasses::TheSet;
|
||||||
|
|
||||||
void WingTokenizer::Add(TCHAR Type, FName InternalID)
|
void WingTokenizer::Add(TCHAR Type, FName Name)
|
||||||
{
|
{
|
||||||
Token T;
|
Token T;
|
||||||
T.Type = Type;
|
T.Type = Type;
|
||||||
T.InternalID = InternalID;
|
T.Name = Name;
|
||||||
Tokens.Add(T);
|
Tokens.Add(T);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -211,6 +211,11 @@ WingTokenizer::WingTokenizer(const FString& In)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!Error.IsEmpty()) Tokens.Empty();
|
if (!Error.IsEmpty()) Tokens.Empty();
|
||||||
|
|
||||||
|
// Two sentinels means we can safely do lookahead 2 without risk.
|
||||||
|
Add(0, FName());
|
||||||
|
Add(0, FName());
|
||||||
|
Next = Tokens.GetData();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WingTokenizer::PrintEverything(FStringBuilderBase &Out) const
|
void WingTokenizer::PrintEverything(FStringBuilderBase &Out) const
|
||||||
@@ -224,7 +229,7 @@ void WingTokenizer::PrintEverything(FStringBuilderBase &Out) const
|
|||||||
Out.Appendf(TEXT("Token '%c': "), T.Type);
|
Out.Appendf(TEXT("Token '%c': "), T.Type);
|
||||||
if (T.Type == Identifier)
|
if (T.Type == Identifier)
|
||||||
{
|
{
|
||||||
for (TCHAR Ch : T.InternalID.ToString())
|
for (TCHAR Ch : T.Name.ToString())
|
||||||
{
|
{
|
||||||
if (Ch >= 0x20 && Ch <= 0x7E)
|
if (Ch >= 0x20 && Ch <= 0x7E)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -97,37 +97,47 @@ private:
|
|||||||
|
|
||||||
struct WingTokenizer
|
struct WingTokenizer
|
||||||
{
|
{
|
||||||
using Cat = WingCharacterClasses::Cat;
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Tokenizer Accessors.
|
||||||
|
//
|
||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
const TCHAR Identifier = 'i';
|
const TCHAR Identifier = 'i';
|
||||||
const TCHAR RestOfLine = 'r';
|
const TCHAR RestOfLine = 'r';
|
||||||
|
|
||||||
// A token has a token type which can be Identifier,
|
// Get the next token.
|
||||||
// RestOfLine, or a single-character punctuation mark.
|
TCHAR NextType() const { return Next[0].Type; }
|
||||||
// The InternalID field contains the result of converting
|
FName NextName() const { return Next[0].Name; }
|
||||||
// the token from an external ID to an internal ID.
|
FStringView NextRest() const { return Next[0].Rest; }
|
||||||
// Rest is only populated if it's a rest-of-line token.
|
|
||||||
struct Token
|
|
||||||
{
|
|
||||||
TCHAR Type;
|
|
||||||
FName InternalID;
|
|
||||||
FStringView Rest;
|
|
||||||
};
|
|
||||||
|
|
||||||
// The string that we tokenized.
|
// Check the next token.
|
||||||
FString Input;
|
bool TokenIs(TCHAR Type) const { return Next[0].Type == Type; }
|
||||||
|
|
||||||
// If the tokenization failed, an error message.
|
// Check the next token.
|
||||||
FString Error;
|
bool TokenIs(FName Name) const { return Next[0].Name == Name; }
|
||||||
|
|
||||||
// The result, an array of tokens.
|
// Check the next two tokens.
|
||||||
TArray<Token> Tokens;
|
bool TokenIs(FName Name, TCHAR Type) const { return Next[0].Name == Name && Next[1].Type == Type; }
|
||||||
|
|
||||||
|
// Advance the cursor. Don't move past the two sentinels.
|
||||||
|
void Advance() { int I = Next-Tokens.GetData(); if (I + 2 < Tokens.Num()) Next++; }
|
||||||
|
|
||||||
// Tokenize a line of input. The tokens are stored in
|
// Tokenize a line of input. The tokens are stored in
|
||||||
// the token array. If there's an error, the error is
|
// the token array, and the cursor is positioned on the first
|
||||||
// stored in the error field, and the token array is
|
// token. If there's an error, the error is stored in the
|
||||||
// cleared. If the tokens contain identifiers,
|
// error field and the cursor points to the empty token.
|
||||||
WingTokenizer(const FString& Input);
|
WingTokenizer(const FString& Input);
|
||||||
|
|
||||||
|
// Print all tokens into a string builder for debugging.
|
||||||
|
void PrintEverything(FStringBuilderBase &Out) const;
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Static functions for internalizing an externalizing IDs.
|
||||||
|
//
|
||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// Convert an internal ID into an external ID.
|
// Convert an internal ID into an external ID.
|
||||||
// Spaces are converted to periods. Any other
|
// Spaces are converted to periods. Any other
|
||||||
// non-identifier character is HTML escaped.
|
// non-identifier character is HTML escaped.
|
||||||
@@ -153,10 +163,40 @@ struct WingTokenizer
|
|||||||
// that's OK.
|
// that's OK.
|
||||||
static FString SimplifyID(const FString &ID);
|
static FString SimplifyID(const FString &ID);
|
||||||
|
|
||||||
// Print all tokens into a string builder for debugging.
|
|
||||||
void PrintEverything(FStringBuilderBase &Out) const;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// The actual tokenizer, state.
|
||||||
|
//
|
||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
struct Token
|
||||||
|
{
|
||||||
|
FName Name; // Only if it's an identifier token.
|
||||||
|
FStringView Rest; // Only if it's a rest-of-line token.
|
||||||
|
TCHAR Type = 0; // A punctuation mark, or Identifier, or RestOfLine
|
||||||
|
};
|
||||||
|
|
||||||
|
// The string that we tokenized.
|
||||||
|
FString Input;
|
||||||
|
|
||||||
|
// If the tokenization failed, an error message.
|
||||||
|
FString Error;
|
||||||
|
|
||||||
|
// The result, an array of tokens. Two empty sentinels at the end.
|
||||||
|
TArray<Token, TInlineAllocator<50>> Tokens;
|
||||||
|
|
||||||
|
// The cursor which advances along the tokens. Never moves past sentinels.
|
||||||
|
Token *Next;
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Internal Implementation Functions.
|
||||||
|
//
|
||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
using Cat = WingCharacterClasses::Cat;
|
||||||
|
|
||||||
// Add a token to the token array.
|
// Add a token to the token array.
|
||||||
void Add(TCHAR Type, FName InternalID);
|
void Add(TCHAR Type, FName InternalID);
|
||||||
void Add(TCHAR Type, FStringView Rest);
|
void Add(TCHAR Type, FStringView Rest);
|
||||||
|
|||||||
@@ -41,7 +41,6 @@ public:
|
|||||||
// Returns the set of flags that are supported by this variable category.
|
// Returns the set of flags that are supported by this variable category.
|
||||||
static const TSet<FName> &GetRelevantFlagSet(Cat C);
|
static const TSet<FName> &GetRelevantFlagSet(Cat C);
|
||||||
|
|
||||||
|
|
||||||
// Check if the variable list is empty.
|
// Check if the variable list is empty.
|
||||||
bool IsEmpty() const { return Variables.IsEmpty(); }
|
bool IsEmpty() const { return Variables.IsEmpty(); }
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ class UWidgetTree;
|
|||||||
struct FAssetData;
|
struct FAssetData;
|
||||||
|
|
||||||
|
|
||||||
// Utility functions for widget blueprint manipulation.
|
|
||||||
class WingWidgets
|
class WingWidgets
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|||||||
Reference in New Issue
Block a user