mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-09 22:38:06 -05:00
Add ZoneDefinition Lexer
This commit is contained in:
@ -0,0 +1,58 @@
|
||||
#include "ZoneDefinitionCommonMatchers.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "Parsing/Simple/Matcher/SimpleMatcherFactory.h"
|
||||
|
||||
std::unique_ptr<ZoneDefinitionCommonMatchers::matcher_t> ZoneDefinitionCommonMatchers::AssetName(const supplier_t* labelSupplier)
|
||||
{
|
||||
const SimpleMatcherFactory create(labelSupplier);
|
||||
|
||||
return create.And({
|
||||
create.Loop(create.Or({
|
||||
create.Identifier(),
|
||||
create.AnyCharBesides({',', '<', '>', '"', '\\', '*', '?', '|', ':'})
|
||||
})),
|
||||
create.Type(SimpleParserValueType::NEW_LINE).NoConsume()
|
||||
}).Transform([](SimpleMatcherFactory::token_list_t& tokens)
|
||||
{
|
||||
std::ostringstream str;
|
||||
auto previousType = SimpleParserValueType::INVALID;
|
||||
auto previousCharacterWasSlash = false;
|
||||
|
||||
for (const auto& token : tokens)
|
||||
{
|
||||
switch (token.get().m_type)
|
||||
{
|
||||
case SimpleParserValueType::IDENTIFIER:
|
||||
if (previousType == SimpleParserValueType::IDENTIFIER)
|
||||
str << " ";
|
||||
str << token.get().IdentifierValue();
|
||||
break;
|
||||
|
||||
case SimpleParserValueType::CHARACTER:
|
||||
if (token.get().CharacterValue() == '/')
|
||||
{
|
||||
if (previousType == SimpleParserValueType::CHARACTER && !previousCharacterWasSlash)
|
||||
{
|
||||
str << "/";
|
||||
previousCharacterWasSlash = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
str << token.get().CharacterValue();
|
||||
previousCharacterWasSlash = false;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
previousType = token.get().m_type;
|
||||
}
|
||||
|
||||
return SimpleParserValue::Identifier(tokens.front().get().GetPos(), new std::string(str.str()));
|
||||
});
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
|
||||
#include "Parsing/Simple/SimpleParserValue.h"
|
||||
#include "Parsing/Matcher/AbstractMatcher.h"
|
||||
#include "Parsing/Matcher/MatcherLabel.h"
|
||||
|
||||
class ZoneDefinitionCommonMatchers
|
||||
{
|
||||
public:
|
||||
typedef AbstractMatcher<SimpleParserValue> matcher_t;
|
||||
typedef IMatcherForLabelSupplier<SimpleParserValue> supplier_t;
|
||||
|
||||
static constexpr int LABEL_ASSET_NAME = std::numeric_limits<int>::max() - 1;
|
||||
|
||||
static std::unique_ptr<matcher_t> AssetName(const supplier_t* labelSupplier);
|
||||
};
|
Reference in New Issue
Block a user