mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-18 18:57:57 -05:00
Add expression parsing for menu parser
This commit is contained in:
@ -8,6 +8,7 @@
|
||||
#include "GenericStringPropertySequence.h"
|
||||
#include "Parsing/Menu/Matcher/MenuMatcherFactory.h"
|
||||
#include "Parsing/Menu/Domain/CommonMenuTypes.h"
|
||||
#include "Parsing/Menu/Matcher/MenuCommonMatchers.h"
|
||||
|
||||
using namespace menu;
|
||||
|
||||
@ -63,6 +64,52 @@ namespace menu::menu_properties
|
||||
state->m_current_menu->m_rect = rect;
|
||||
}
|
||||
};
|
||||
|
||||
class SequenceBooleanExpression final : public MenuFileParser::sequence_t
|
||||
{
|
||||
static constexpr auto CAPTURE_EXPRESSION = 1;
|
||||
|
||||
public:
|
||||
explicit SequenceBooleanExpression(std::string keyword)
|
||||
{
|
||||
const MenuMatcherFactory create(this);
|
||||
|
||||
AddLabeledMatchers(MenuCommonMatchers::Expression(this), MenuCommonMatchers::LABEL_EXPRESSION);
|
||||
|
||||
AddMatchers({
|
||||
create.KeywordIgnoreCase(std::move(keyword)),
|
||||
create.Or({
|
||||
create.And({
|
||||
create.KeywordIgnoreCase("when"),
|
||||
create.Char('('),
|
||||
create.Label(MenuCommonMatchers::LABEL_EXPRESSION).Capture(CAPTURE_EXPRESSION),
|
||||
create.Char(')')
|
||||
}),
|
||||
create.Label(MenuCommonMatchers::LABEL_EXPRESSION)
|
||||
}),
|
||||
create.Char(';')
|
||||
});
|
||||
}
|
||||
|
||||
protected:
|
||||
void ProcessMatch(MenuFileParserState* state, SequenceResult<SimpleParserValue>& result) const override
|
||||
{
|
||||
assert(state->m_current_menu);
|
||||
|
||||
const auto expression = MenuCommonMatchers::ProcessExpression(state, result);
|
||||
|
||||
std::cout << "Evaluated expression!\n";
|
||||
std::cout << " IsStatic: " << expression->IsStatic() << "\n";
|
||||
|
||||
const auto value = expression->Evaluate();
|
||||
if(value.m_type == CommonExpressionValue::Type::DOUBLE)
|
||||
std::cout << " Value: " << value.m_double_value << "\n";
|
||||
else if(value.m_type == CommonExpressionValue::Type::INT)
|
||||
std::cout << " Value: " << value.m_int_value << "\n";
|
||||
else if (value.m_type == CommonExpressionValue::Type::STRING)
|
||||
std::cout << " Value: \"" << *value.m_string_value << "\"\n";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
using namespace menu_properties;
|
||||
@ -187,4 +234,6 @@ void MenuPropertySequences::AddSequences(FeatureLevel featureLevel)
|
||||
{
|
||||
state->m_current_menu->m_text_only_focus = true;
|
||||
}));
|
||||
|
||||
AddSequence(std::make_unique<SequenceBooleanExpression>("visible"));
|
||||
}
|
||||
|
Reference in New Issue
Block a user