mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-20 08:05:45 +00:00
Add MenuMatcherFactory with extensions for Numeric and Text token types
This commit is contained in:
parent
ff823b4722
commit
5df6fce48a
48
src/ObjLoading/Parsing/Menu/MenuMatcherFactory.cpp
Normal file
48
src/ObjLoading/Parsing/Menu/MenuMatcherFactory.cpp
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
#include "MenuMatcherFactory.h"
|
||||||
|
|
||||||
|
using namespace menu;
|
||||||
|
|
||||||
|
MenuMatcherFactory::MenuMatcherFactory(const IMatcherForLabelSupplier<SimpleParserValue>* labelSupplier)
|
||||||
|
: SimpleMatcherFactory(labelSupplier)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
MatcherFactoryWrapper<SimpleParserValue> MenuMatcherFactory::Text() const
|
||||||
|
{
|
||||||
|
return MatcherFactoryWrapper<SimpleParserValue>(Or({String(), Identifier()}));
|
||||||
|
}
|
||||||
|
|
||||||
|
MatcherFactoryWrapper<SimpleParserValue> MenuMatcherFactory::Numeric() const
|
||||||
|
{
|
||||||
|
return MatcherFactoryWrapper<SimpleParserValue>(Or({FloatingPoint(), Integer()}));
|
||||||
|
}
|
||||||
|
|
||||||
|
int MenuMatcherFactory::TokenNumericIntValue(const SimpleParserValue& value)
|
||||||
|
{
|
||||||
|
if(value.m_type == SimpleParserValueType::FLOATING_POINT)
|
||||||
|
{
|
||||||
|
return static_cast<int>(value.FloatingPointValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
return value.IntegerValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
double MenuMatcherFactory::TokenNumericFloatingPointValue(const SimpleParserValue& value)
|
||||||
|
{
|
||||||
|
if (value.m_type == SimpleParserValueType::INTEGER)
|
||||||
|
{
|
||||||
|
return static_cast<double>(value.IntegerValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
return value.FloatingPointValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string& MenuMatcherFactory::TokenTextValue(const SimpleParserValue& value)
|
||||||
|
{
|
||||||
|
if(value.m_type == SimpleParserValueType::IDENTIFIER)
|
||||||
|
{
|
||||||
|
return value.IdentifierValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
return value.StringValue();
|
||||||
|
}
|
19
src/ObjLoading/Parsing/Menu/MenuMatcherFactory.h
Normal file
19
src/ObjLoading/Parsing/Menu/MenuMatcherFactory.h
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Parsing/Simple/Matcher/SimpleMatcherFactory.h"
|
||||||
|
|
||||||
|
namespace menu
|
||||||
|
{
|
||||||
|
class MenuMatcherFactory : public SimpleMatcherFactory
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit MenuMatcherFactory(const IMatcherForLabelSupplier<SimpleParserValue>* labelSupplier);
|
||||||
|
|
||||||
|
_NODISCARD MatcherFactoryWrapper<SimpleParserValue> Text() const;
|
||||||
|
_NODISCARD MatcherFactoryWrapper<SimpleParserValue> Numeric() const;
|
||||||
|
|
||||||
|
_NODISCARD static int TokenNumericIntValue(const SimpleParserValue& value);
|
||||||
|
_NODISCARD static double TokenNumericFloatingPointValue(const SimpleParserValue& value);
|
||||||
|
_NODISCARD static std::string& TokenTextValue(const SimpleParserValue& value);
|
||||||
|
};
|
||||||
|
}
|
@ -1,16 +1,16 @@
|
|||||||
#include "SequenceName.h"
|
#include "SequenceName.h"
|
||||||
|
|
||||||
#include "Parsing/Simple/Matcher/SimpleMatcherFactory.h"
|
#include "Parsing/Menu/MenuMatcherFactory.h"
|
||||||
|
|
||||||
using namespace menu;
|
using namespace menu;
|
||||||
|
|
||||||
SequenceName::SequenceName()
|
SequenceName::SequenceName()
|
||||||
{
|
{
|
||||||
const SimpleMatcherFactory create(this);
|
const MenuMatcherFactory create(this);
|
||||||
|
|
||||||
AddMatchers({
|
AddMatchers({
|
||||||
create.KeywordIgnoreCase("name"),
|
create.KeywordIgnoreCase("name"),
|
||||||
create.Or({create.String(), create.Identifier()}).Capture(CAPTURE_NAME)
|
create.Text().Capture(CAPTURE_NAME)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -18,8 +18,7 @@ void SequenceName::ProcessMatch(MenuFileParserState* state, SequenceResult<Simpl
|
|||||||
{
|
{
|
||||||
assert(state->m_current_item || state->m_current_menu || state->m_current_function);
|
assert(state->m_current_item || state->m_current_menu || state->m_current_function);
|
||||||
|
|
||||||
const auto& nameToken = result.NextCapture(CAPTURE_NAME);
|
const auto nameValue = MenuMatcherFactory::TokenTextValue(result.NextCapture(CAPTURE_NAME));
|
||||||
const auto nameValue = nameToken.m_type == SimpleParserValueType::IDENTIFIER ? nameToken.IdentifierValue() : nameToken.StringValue();
|
|
||||||
|
|
||||||
if (state->m_current_item)
|
if (state->m_current_item)
|
||||||
state->m_current_item->m_name = nameValue;
|
state->m_current_item->m_name = nameValue;
|
||||||
|
@ -2,13 +2,13 @@
|
|||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
#include "Parsing/Simple/Matcher/SimpleMatcherFactory.h"
|
#include "Parsing/Menu/MenuMatcherFactory.h"
|
||||||
|
|
||||||
using namespace menu;
|
using namespace menu;
|
||||||
|
|
||||||
SequenceCloseBlock::SequenceCloseBlock()
|
SequenceCloseBlock::SequenceCloseBlock()
|
||||||
{
|
{
|
||||||
const SimpleMatcherFactory create(this);
|
const MenuMatcherFactory create(this);
|
||||||
|
|
||||||
AddMatchers({
|
AddMatchers({
|
||||||
create.Char('}').Capture(CAPTURE_TOKEN)
|
create.Char('}').Capture(CAPTURE_TOKEN)
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
#include "SequenceFunctionDef.h"
|
#include "SequenceFunctionDef.h"
|
||||||
|
|
||||||
#include "Parsing/Simple/Matcher/SimpleMatcherFactory.h"
|
#include "Parsing/Menu/MenuMatcherFactory.h"
|
||||||
|
|
||||||
using namespace menu;
|
using namespace menu;
|
||||||
|
|
||||||
SequenceFunctionDef::SequenceFunctionDef()
|
SequenceFunctionDef::SequenceFunctionDef()
|
||||||
{
|
{
|
||||||
const SimpleMatcherFactory create(this);
|
const MenuMatcherFactory create(this);
|
||||||
|
|
||||||
AddMatchers({
|
AddMatchers({
|
||||||
create.Keyword("functionDef"),
|
create.Keyword("functionDef"),
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
#include "SequenceItemDef.h"
|
#include "SequenceItemDef.h"
|
||||||
|
|
||||||
#include "Parsing/Simple/Matcher/SimpleMatcherFactory.h"
|
#include "Parsing/Menu/MenuMatcherFactory.h"
|
||||||
|
|
||||||
using namespace menu;
|
using namespace menu;
|
||||||
|
|
||||||
SequenceItemDef::SequenceItemDef()
|
SequenceItemDef::SequenceItemDef()
|
||||||
{
|
{
|
||||||
const SimpleMatcherFactory create(this);
|
const MenuMatcherFactory create(this);
|
||||||
|
|
||||||
AddMatchers({
|
AddMatchers({
|
||||||
create.Keyword("itemDef"),
|
create.Keyword("itemDef"),
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
#include "SequenceLoadMenu.h"
|
#include "SequenceLoadMenu.h"
|
||||||
|
|
||||||
#include "Parsing/Simple/Matcher/SimpleMatcherFactory.h"
|
#include "Parsing/Menu/MenuMatcherFactory.h"
|
||||||
|
|
||||||
using namespace menu;
|
using namespace menu;
|
||||||
|
|
||||||
SequenceLoadMenu::SequenceLoadMenu()
|
SequenceLoadMenu::SequenceLoadMenu()
|
||||||
{
|
{
|
||||||
const SimpleMatcherFactory create(this);
|
const MenuMatcherFactory create(this);
|
||||||
|
|
||||||
AddMatchers({
|
AddMatchers({
|
||||||
create.Keyword("loadMenu"),
|
create.Keyword("loadMenu"),
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
#include "SequenceMenuDef.h"
|
#include "SequenceMenuDef.h"
|
||||||
|
|
||||||
#include "Parsing/Simple/Matcher/SimpleMatcherFactory.h"
|
#include "Parsing/Menu/MenuMatcherFactory.h"
|
||||||
|
|
||||||
using namespace menu;
|
using namespace menu;
|
||||||
|
|
||||||
SequenceMenuDef::SequenceMenuDef()
|
SequenceMenuDef::SequenceMenuDef()
|
||||||
{
|
{
|
||||||
const SimpleMatcherFactory create(this);
|
const MenuMatcherFactory create(this);
|
||||||
|
|
||||||
AddMatchers({
|
AddMatchers({
|
||||||
create.Keyword("menuDef"),
|
create.Keyword("menuDef"),
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
#include "SequenceOpenGlobalScopeBlock.h"
|
#include "SequenceOpenGlobalScopeBlock.h"
|
||||||
|
|
||||||
#include "Parsing/Simple/Matcher/SimpleMatcherFactory.h"
|
#include "Parsing/Menu/MenuMatcherFactory.h"
|
||||||
|
|
||||||
using namespace menu;
|
using namespace menu;
|
||||||
|
|
||||||
SequenceOpenGlobalScopeBlock::SequenceOpenGlobalScopeBlock()
|
SequenceOpenGlobalScopeBlock::SequenceOpenGlobalScopeBlock()
|
||||||
{
|
{
|
||||||
const SimpleMatcherFactory create(this);
|
const MenuMatcherFactory create(this);
|
||||||
|
|
||||||
AddMatchers({
|
AddMatchers({
|
||||||
create.Char('{')
|
create.Char('{')
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
#include "Parsing/Simple/SimpleParserValue.h"
|
#include "Parsing/Simple/SimpleParserValue.h"
|
||||||
#include "Parsing/Matcher/AbstractMatcherFactory.h"
|
#include "Parsing/Matcher/AbstractMatcherFactory.h"
|
||||||
|
|
||||||
class SimpleMatcherFactory final : public AbstractMatcherFactory<SimpleParserValue>
|
class SimpleMatcherFactory : public AbstractMatcherFactory<SimpleParserValue>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit SimpleMatcherFactory(const IMatcherForLabelSupplier<SimpleParserValue>* labelSupplier);
|
explicit SimpleMatcherFactory(const IMatcherForLabelSupplier<SimpleParserValue>* labelSupplier);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user