mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-20 16:15:43 +00:00
Parse menu function values
This commit is contained in:
parent
7ea53808b7
commit
d4154d0cc2
@ -2,11 +2,14 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "Parsing/Simple/Expression/ISimpleExpression.h"
|
||||||
|
|
||||||
namespace menu
|
namespace menu
|
||||||
{
|
{
|
||||||
class CommonFunctionDef
|
class CommonFunctionDef
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
std::string m_name;
|
std::string m_name;
|
||||||
|
std::unique_ptr<ISimpleExpression> m_value;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
#include "Generic/GenericExpressionPropertySequence.h"
|
||||||
#include "Generic/GenericStringPropertySequence.h"
|
#include "Generic/GenericStringPropertySequence.h"
|
||||||
#include "Parsing/Menu/Matcher/MenuMatcherFactory.h"
|
#include "Parsing/Menu/Matcher/MenuMatcherFactory.h"
|
||||||
|
|
||||||
@ -9,51 +10,55 @@ using namespace menu;
|
|||||||
|
|
||||||
namespace menu::function_scope_sequences
|
namespace menu::function_scope_sequences
|
||||||
{
|
{
|
||||||
class SequenceCloseBlock final : public MenuFileParser::sequence_t
|
class SequenceCloseBlock final : public MenuFileParser::sequence_t
|
||||||
{
|
{
|
||||||
static constexpr auto CAPTURE_TOKEN = 1;
|
static constexpr auto CAPTURE_TOKEN = 1;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SequenceCloseBlock()
|
SequenceCloseBlock()
|
||||||
{
|
{
|
||||||
const MenuMatcherFactory create(this);
|
const MenuMatcherFactory create(this);
|
||||||
|
|
||||||
AddMatchers({
|
AddMatchers({
|
||||||
create.Char('}')
|
create.Char('}').Capture(CAPTURE_TOKEN)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void ProcessMatch(MenuFileParserState* state, SequenceResult<SimpleParserValue>& result) const override
|
void ProcessMatch(MenuFileParserState* state, SequenceResult<SimpleParserValue>& result) const override
|
||||||
{
|
{
|
||||||
const auto existingFunction = state->m_functions_by_name.find(state->m_current_function->m_name);
|
const auto existingFunction = state->m_functions_by_name.find(state->m_current_function->m_name);
|
||||||
if (existingFunction == state->m_functions_by_name.end())
|
if (existingFunction == state->m_functions_by_name.end())
|
||||||
{
|
{
|
||||||
state->m_functions_by_name.emplace(std::make_pair(state->m_current_function->m_name, state->m_current_function));
|
state->m_functions_by_name.emplace(std::make_pair(state->m_current_function->m_name, state->m_current_function));
|
||||||
state->m_current_function = nullptr;
|
state->m_current_function = nullptr;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::ostringstream ss;
|
std::ostringstream ss;
|
||||||
ss << "Function with name \"" << state->m_current_menu->m_name << "\" already exists";
|
ss << "Function with name \"" << state->m_current_function->m_name << "\" already exists";
|
||||||
throw ParsingException(result.NextCapture(CAPTURE_TOKEN).GetPos(), ss.str());
|
throw ParsingException(result.NextCapture(CAPTURE_TOKEN).GetPos(), ss.str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
using namespace function_scope_sequences;
|
using namespace function_scope_sequences;
|
||||||
|
|
||||||
FunctionScopeSequences::FunctionScopeSequences(std::vector<std::unique_ptr<MenuFileParser::sequence_t>>& allSequences, std::vector<MenuFileParser::sequence_t*>& scopeSequences)
|
FunctionScopeSequences::FunctionScopeSequences(std::vector<std::unique_ptr<MenuFileParser::sequence_t>>& allSequences, std::vector<MenuFileParser::sequence_t*>& scopeSequences)
|
||||||
: AbstractScopeSequenceHolder(allSequences, scopeSequences)
|
: AbstractScopeSequenceHolder(allSequences, scopeSequences)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void FunctionScopeSequences::AddSequences(FeatureLevel featureLevel, bool permissive)
|
void FunctionScopeSequences::AddSequences(FeatureLevel featureLevel, bool permissive)
|
||||||
{
|
{
|
||||||
AddSequence(std::make_unique<SequenceCloseBlock>());
|
AddSequence(std::make_unique<SequenceCloseBlock>());
|
||||||
AddSequence(std::make_unique<GenericStringPropertySequence>("name", [](const MenuFileParserState* state, const TokenPos&, const std::string& value)
|
AddSequence(std::make_unique<GenericStringPropertySequence>("name", [](const MenuFileParserState* state, const TokenPos&, const std::string& value)
|
||||||
{
|
{
|
||||||
state->m_current_function->m_name = value;
|
state->m_current_function->m_name = value;
|
||||||
}));
|
}));
|
||||||
|
AddSequence(GenericExpressionPropertySequence::WithKeyword("value", [](const MenuFileParserState* state, const TokenPos&, std::unique_ptr<ISimpleExpression> value)
|
||||||
|
{
|
||||||
|
state->m_current_function->m_value = std::move(value);
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user