Add ZoneDefinition Lexer

This commit is contained in:
Jan
2021-03-10 14:58:02 +01:00
parent c47ea48b6b
commit 8798779b39
21 changed files with 232 additions and 14 deletions

View File

@ -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()));
});
}

View File

@ -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);
};