mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-18 10:47:57 -05:00
Move Menu Expression to Simple Namespace to have generic configurable expressions
This commit is contained in:
@ -7,7 +7,7 @@
|
||||
#include "Generic/GenericStringPropertySequence.h"
|
||||
#include "Parsing/Menu/Domain/EventHandler/CommonEventHandlerScript.h"
|
||||
#include "Parsing/Menu/Domain/EventHandler/CommonEventHandlerSetLocalVar.h"
|
||||
#include "Parsing/Menu/Matcher/MenuCommonMatchers.h"
|
||||
#include "Parsing/Menu/Matcher/MenuExpressionMatchers.h"
|
||||
#include "Parsing/Menu/Matcher/MenuMatcherFactory.h"
|
||||
#include "Parsing/Menu/Matcher/MenuMatcherScriptInt.h"
|
||||
#include "Parsing/Menu/Matcher/MenuMatcherScriptNumeric.h"
|
||||
@ -326,8 +326,9 @@ namespace menu::event_handler_set_scope_sequences
|
||||
SequenceSetLocalVar()
|
||||
{
|
||||
const ScriptMatcherFactory create(this);
|
||||
const MenuExpressionMatchers expressionMatchers;
|
||||
|
||||
AddLabeledMatchers(MenuCommonMatchers::Expression(this), MenuCommonMatchers::LABEL_EXPRESSION);
|
||||
AddLabeledMatchers(expressionMatchers.Expression(this), MenuExpressionMatchers::LABEL_EXPRESSION);
|
||||
|
||||
AddMatchers({
|
||||
create.Or({
|
||||
@ -337,7 +338,7 @@ namespace menu::event_handler_set_scope_sequences
|
||||
create.ScriptKeyword("setLocalVarString").Tag(TAG_STRING)
|
||||
}),
|
||||
create.ScriptText().Capture(CAPTURE_VAR_NAME),
|
||||
create.Label(MenuCommonMatchers::LABEL_EXPRESSION),
|
||||
create.Label(MenuExpressionMatchers::LABEL_EXPRESSION),
|
||||
create.Optional(create.Char(';'))
|
||||
});
|
||||
}
|
||||
@ -420,10 +421,12 @@ namespace menu::event_handler_set_scope_sequences
|
||||
protected:
|
||||
void ProcessMatch(MenuFileParserState* state, SequenceResult<SimpleParserValue>& result) const override
|
||||
{
|
||||
const MenuExpressionMatchers expressionMatchers;
|
||||
|
||||
const auto typeTag = static_cast<SetLocalVarType>(result.NextTag());
|
||||
const auto& varNameToken = result.NextCapture(CAPTURE_VAR_NAME);
|
||||
const auto& varName = MenuMatcherFactory::TokenTextValue(varNameToken);
|
||||
auto expression = MenuCommonMatchers::ProcessExpression(state, result);
|
||||
auto expression = expressionMatchers.ProcessExpression(result);
|
||||
|
||||
if (!expression)
|
||||
throw ParsingException(varNameToken.GetPos(), "No expression");
|
||||
@ -443,13 +446,14 @@ namespace menu::event_handler_set_scope_sequences
|
||||
SequenceIf()
|
||||
{
|
||||
const ScriptMatcherFactory create(this);
|
||||
const MenuExpressionMatchers expressionMatchers;
|
||||
|
||||
AddLabeledMatchers(MenuCommonMatchers::Expression(this), MenuCommonMatchers::LABEL_EXPRESSION);
|
||||
AddLabeledMatchers(expressionMatchers.Expression(this), MenuExpressionMatchers::LABEL_EXPRESSION);
|
||||
|
||||
AddMatchers({
|
||||
create.Keyword("if").Capture(CAPTURE_KEYWORD),
|
||||
create.Char('('),
|
||||
create.Label(MenuCommonMatchers::LABEL_EXPRESSION),
|
||||
create.Label(MenuExpressionMatchers::LABEL_EXPRESSION),
|
||||
create.Char(')'),
|
||||
create.Char('{')
|
||||
});
|
||||
@ -458,7 +462,8 @@ namespace menu::event_handler_set_scope_sequences
|
||||
protected:
|
||||
void ProcessMatch(MenuFileParserState* state, SequenceResult<SimpleParserValue>& result) const override
|
||||
{
|
||||
auto expression = MenuCommonMatchers::ProcessExpression(state, result);
|
||||
const MenuExpressionMatchers expressionMatchers;
|
||||
auto expression = expressionMatchers.ProcessExpression(result);
|
||||
|
||||
if (!expression)
|
||||
throw ParsingException(result.NextCapture(CAPTURE_KEYWORD).GetPos(), "Could not parse expression");
|
||||
@ -485,14 +490,15 @@ namespace menu::event_handler_set_scope_sequences
|
||||
SequenceElseIf()
|
||||
{
|
||||
const ScriptMatcherFactory create(this);
|
||||
const MenuExpressionMatchers expressionMatchers;
|
||||
|
||||
AddLabeledMatchers(MenuCommonMatchers::Expression(this), MenuCommonMatchers::LABEL_EXPRESSION);
|
||||
AddLabeledMatchers(expressionMatchers.Expression(this), MenuExpressionMatchers::LABEL_EXPRESSION);
|
||||
|
||||
AddMatchers({
|
||||
create.Char('}'),
|
||||
create.Keyword("elseif").Capture(CAPTURE_KEYWORD),
|
||||
create.Char('('),
|
||||
create.Label(MenuCommonMatchers::LABEL_EXPRESSION),
|
||||
create.Label(MenuExpressionMatchers::LABEL_EXPRESSION),
|
||||
create.Char(')'),
|
||||
create.Char('{')
|
||||
});
|
||||
@ -501,7 +507,8 @@ namespace menu::event_handler_set_scope_sequences
|
||||
protected:
|
||||
void ProcessMatch(MenuFileParserState* state, SequenceResult<SimpleParserValue>& result) const override
|
||||
{
|
||||
auto expression = MenuCommonMatchers::ProcessExpression(state, result);
|
||||
const MenuExpressionMatchers expressionMatchers;
|
||||
auto expression = expressionMatchers.ProcessExpression(result);
|
||||
|
||||
if (!expression)
|
||||
throw ParsingException(result.NextCapture(CAPTURE_KEYWORD).GetPos(), "Could not parse expression");
|
||||
@ -539,8 +546,9 @@ namespace menu::event_handler_set_scope_sequences
|
||||
SequenceElse()
|
||||
{
|
||||
const ScriptMatcherFactory create(this);
|
||||
const MenuExpressionMatchers expressionMatchers;
|
||||
|
||||
AddLabeledMatchers(MenuCommonMatchers::Expression(this), MenuCommonMatchers::LABEL_EXPRESSION);
|
||||
AddLabeledMatchers(expressionMatchers.Expression(this), MenuExpressionMatchers::LABEL_EXPRESSION);
|
||||
|
||||
AddMatchers({
|
||||
create.Char('}'),
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "Parsing/Menu/Matcher/MenuCommonMatchers.h"
|
||||
#include "Parsing/Menu/Matcher/MenuExpressionMatchers.h"
|
||||
#include "Parsing/Menu/Matcher/MenuMatcherFactory.h"
|
||||
|
||||
using namespace menu;
|
||||
@ -10,7 +10,8 @@ using namespace menu;
|
||||
GenericExpressionPropertySequence::GenericExpressionPropertySequence(callback_t setCallback)
|
||||
: m_set_callback(std::move(setCallback))
|
||||
{
|
||||
AddLabeledMatchers(MenuCommonMatchers::Expression(this), MenuCommonMatchers::LABEL_EXPRESSION);
|
||||
const MenuExpressionMatchers expressionMatchers;
|
||||
AddLabeledMatchers(expressionMatchers.Expression(this), MenuExpressionMatchers::LABEL_EXPRESSION);
|
||||
}
|
||||
|
||||
std::unique_ptr<GenericExpressionPropertySequence> GenericExpressionPropertySequence::WithKeyword(std::string keyword, callback_t setCallback)
|
||||
@ -20,7 +21,7 @@ std::unique_ptr<GenericExpressionPropertySequence> GenericExpressionPropertySequ
|
||||
const MenuMatcherFactory create(result.get());
|
||||
result->AddMatchers({
|
||||
create.KeywordIgnoreCase(std::move(keyword)).Capture(CAPTURE_FIRST_TOKEN),
|
||||
create.Label(MenuCommonMatchers::LABEL_EXPRESSION),
|
||||
create.Label(MenuExpressionMatchers::LABEL_EXPRESSION),
|
||||
create.Optional(create.Char(';'))
|
||||
});
|
||||
|
||||
@ -38,7 +39,7 @@ std::unique_ptr<GenericExpressionPropertySequence> GenericExpressionPropertySequ
|
||||
|
||||
result->AddMatchers({
|
||||
create.And(std::move(keywordMatchers)).Capture(CAPTURE_FIRST_TOKEN),
|
||||
create.Label(MenuCommonMatchers::LABEL_EXPRESSION),
|
||||
create.Label(MenuExpressionMatchers::LABEL_EXPRESSION),
|
||||
create.Optional(create.Char(';'))
|
||||
});
|
||||
|
||||
@ -56,10 +57,10 @@ std::unique_ptr<GenericExpressionPropertySequence> GenericExpressionPropertySequ
|
||||
create.And({
|
||||
create.KeywordIgnoreCase("when"),
|
||||
create.Char('('),
|
||||
create.Label(MenuCommonMatchers::LABEL_EXPRESSION),
|
||||
create.Label(MenuExpressionMatchers::LABEL_EXPRESSION),
|
||||
create.Char(')')
|
||||
}),
|
||||
create.Label(MenuCommonMatchers::LABEL_EXPRESSION)
|
||||
create.Label(MenuExpressionMatchers::LABEL_EXPRESSION)
|
||||
}),
|
||||
create.Optional(create.Char(';'))
|
||||
});
|
||||
@ -71,7 +72,8 @@ void GenericExpressionPropertySequence::ProcessMatch(MenuFileParserState* state,
|
||||
{
|
||||
if (m_set_callback)
|
||||
{
|
||||
auto expression = MenuCommonMatchers::ProcessExpression(state, result);
|
||||
const MenuExpressionMatchers expressionMatchers;
|
||||
auto expression = expressionMatchers.ProcessExpression(result);
|
||||
m_set_callback(state, result.NextCapture(CAPTURE_FIRST_TOKEN).GetPos(), std::move(expression));
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@
|
||||
#include "Generic/GenericStringPropertySequence.h"
|
||||
#include "Parsing/Menu/Matcher/MenuMatcherFactory.h"
|
||||
#include "Parsing/Menu/Domain/CommonMenuTypes.h"
|
||||
#include "Parsing/Menu/Matcher/MenuCommonMatchers.h"
|
||||
#include "Parsing/Menu/Matcher/MenuExpressionMatchers.h"
|
||||
|
||||
using namespace menu;
|
||||
|
||||
|
Reference in New Issue
Block a user