You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
+Created a custom syntax tokenizer for Hlsl Highlighter. The vanilla tokenizer does a greedy match, which can lead to cases like "FloatA" to be tokenized as "Float" and "A". The new tokenizer is more specific about when to check for a match +Added ISyntaxTokenizer to be used as a based class for all syntax tokenizers #jira UE-144112 #rb Halfdan.Ingvarsson #fyi Jamie.Dale #preflight skip [CL 19380707 by jack cai in ue5-main branch]
80 lines
1.8 KiB
C++
80 lines
1.8 KiB
C++
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
#pragma once
|
|
|
|
#include "CoreMinimal.h"
|
|
|
|
class SLATE_API ISyntaxTokenizer
|
|
{
|
|
public:
|
|
/** Denotes the type of token */
|
|
enum class ETokenType : uint8
|
|
{
|
|
/** Syntax token matching the tokenizing rules provided */
|
|
Syntax,
|
|
/** String token containing some literal text */
|
|
Literal,
|
|
};
|
|
|
|
/** A token referencing a range in the original text */
|
|
struct FToken
|
|
{
|
|
FToken(const ETokenType InType, const FTextRange& InRange)
|
|
: Type(InType)
|
|
, Range(InRange)
|
|
{
|
|
}
|
|
|
|
ETokenType Type;
|
|
FTextRange Range;
|
|
};
|
|
|
|
/** A line containing a series of tokens */
|
|
struct FTokenizedLine
|
|
{
|
|
FTextRange Range;
|
|
TArray<FToken> Tokens;
|
|
};
|
|
|
|
virtual ~ISyntaxTokenizer() {};
|
|
|
|
virtual void Process(TArray<FTokenizedLine>& OutTokenizedLines, const FString& Input) = 0;
|
|
};
|
|
|
|
/**
|
|
* Tokenize the text based upon the given rule set
|
|
*/
|
|
class SLATE_API FSyntaxTokenizer : public ISyntaxTokenizer
|
|
{
|
|
public:
|
|
/** Rule used to match syntax token types */
|
|
struct FRule
|
|
{
|
|
FRule(FString InMatchText)
|
|
: MatchText(MoveTemp(InMatchText))
|
|
{
|
|
}
|
|
|
|
FString MatchText;
|
|
};
|
|
|
|
/**
|
|
* Create a new tokenizer which will use the given rules to match syntax tokens
|
|
* @param InRules Rules to control the tokenizer, processed in-order so the most greedy matches must come first
|
|
*/
|
|
static TSharedRef< FSyntaxTokenizer > Create(TArray<FRule> InRules);
|
|
|
|
virtual ~FSyntaxTokenizer();
|
|
|
|
virtual void Process(TArray<FTokenizedLine>& OutTokenizedLines, const FString& Input) override;
|
|
|
|
private:
|
|
|
|
FSyntaxTokenizer(TArray<FRule> InRules);
|
|
|
|
void TokenizeLineRanges(const FString& Input, const TArray<FTextRange>& LineRanges, TArray<FTokenizedLine>& OutTokenizedLines);
|
|
|
|
/** Rules to control the tokenizer, processed in-order so the most greedy matches must come first */
|
|
TArray<FRule> Rules;
|
|
|
|
};
|