Accept static expressions for menu floating point and int

This commit is contained in:
Jan 2021-11-26 21:50:07 +01:00
parent 9279123ef9
commit c3a44f60d3
4 changed files with 8 additions and 6 deletions

View File

@ -2,6 +2,7 @@
#include <utility> #include <utility>
#include "Parsing/Menu/Matcher/MenuExpressionMatchers.h"
#include "Parsing/Menu/Matcher/MenuMatcherFactory.h" #include "Parsing/Menu/Matcher/MenuMatcherFactory.h"
using namespace menu; using namespace menu;
@ -11,9 +12,10 @@ GenericFloatingPointPropertySequence::GenericFloatingPointPropertySequence(std::
{ {
const MenuMatcherFactory create(this); const MenuMatcherFactory create(this);
AddLabeledMatchers(MenuExpressionMatchers().Expression(this), MenuExpressionMatchers::LABEL_EXPRESSION);
AddMatchers({ AddMatchers({
create.KeywordIgnoreCase(std::move(keywordName)).Capture(CAPTURE_FIRST_TOKEN), create.KeywordIgnoreCase(std::move(keywordName)).Capture(CAPTURE_FIRST_TOKEN),
create.Numeric().Capture(CAPTURE_VALUE) create.NumericExpression()
}); });
} }
@ -21,7 +23,7 @@ void GenericFloatingPointPropertySequence::ProcessMatch(MenuFileParserState* sta
{ {
if (m_set_callback) if (m_set_callback)
{ {
const auto value = MenuMatcherFactory::TokenNumericFloatingPointValue(result.NextCapture(CAPTURE_VALUE)); const auto value = MenuMatcherFactory::TokenNumericExpressionValue(result);
m_set_callback(state, result.NextCapture(CAPTURE_FIRST_TOKEN).GetPos(), value); m_set_callback(state, result.NextCapture(CAPTURE_FIRST_TOKEN).GetPos(), value);
} }
} }

View File

@ -14,7 +14,6 @@ namespace menu
private: private:
static constexpr auto CAPTURE_FIRST_TOKEN = 1; static constexpr auto CAPTURE_FIRST_TOKEN = 1;
static constexpr auto CAPTURE_VALUE = 2;
const callback_t m_set_callback; const callback_t m_set_callback;

View File

@ -2,6 +2,7 @@
#include <utility> #include <utility>
#include "Parsing/Menu/Matcher/MenuExpressionMatchers.h"
#include "Parsing/Menu/Matcher/MenuMatcherFactory.h" #include "Parsing/Menu/Matcher/MenuMatcherFactory.h"
using namespace menu; using namespace menu;
@ -11,9 +12,10 @@ GenericIntPropertySequence::GenericIntPropertySequence(std::string keywordName,
{ {
const MenuMatcherFactory create(this); const MenuMatcherFactory create(this);
AddLabeledMatchers(MenuExpressionMatchers().Expression(this), MenuExpressionMatchers::LABEL_EXPRESSION);
AddMatchers({ AddMatchers({
create.KeywordIgnoreCase(std::move(keywordName)).Capture(CAPTURE_FIRST_TOKEN), create.KeywordIgnoreCase(std::move(keywordName)).Capture(CAPTURE_FIRST_TOKEN),
create.Integer().Capture(CAPTURE_VALUE) create.IntExpression(), // value
}); });
} }
@ -21,7 +23,7 @@ void GenericIntPropertySequence::ProcessMatch(MenuFileParserState* state, Sequen
{ {
if (m_set_callback) if (m_set_callback)
{ {
const auto value = result.NextCapture(CAPTURE_VALUE).IntegerValue(); const auto value = MenuMatcherFactory::TokenIntExpressionValue(result);
m_set_callback(state, result.NextCapture(CAPTURE_FIRST_TOKEN).GetPos(), value); m_set_callback(state, result.NextCapture(CAPTURE_FIRST_TOKEN).GetPos(), value);
} }
} }

View File

@ -14,7 +14,6 @@ namespace menu
private: private:
static constexpr auto CAPTURE_FIRST_TOKEN = 1; static constexpr auto CAPTURE_FIRST_TOKEN = 1;
static constexpr auto CAPTURE_VALUE = 2;
const callback_t m_set_callback; const callback_t m_set_callback;