mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-25 14:17:54 -05:00
Move Menu Expression to Simple Namespace to have generic configurable expressions
This commit is contained in:
@ -3,7 +3,52 @@
|
||||
#include <sstream>
|
||||
#include <utility>
|
||||
|
||||
#include "AbstractParser.h"
|
||||
#include "ParserSingleInputStream.h"
|
||||
#include "Parsing/ParsingException.h"
|
||||
#include "Parsing/Simple/SimpleLexer.h"
|
||||
#include "Parsing/Simple/Expression/ISimpleExpression.h"
|
||||
|
||||
class DefinesIfDirectiveParsingState
|
||||
{
|
||||
public:
|
||||
std::unique_ptr<ISimpleExpression> m_expression;
|
||||
};
|
||||
|
||||
class DefinesIfDirectiveParser final : public AbstractParser<SimpleParserValue, DefinesIfDirectiveParsingState>
|
||||
{
|
||||
protected:
|
||||
explicit DefinesIfDirectiveParser(ILexer<SimpleParserValue>* lexer)
|
||||
: AbstractParser<SimpleParserValue, DefinesIfDirectiveParsingState>(lexer, std::make_unique<DefinesIfDirectiveParsingState>())
|
||||
{
|
||||
}
|
||||
|
||||
const std::vector<sequence_t*>& GetTestsForState() override
|
||||
{
|
||||
static std::vector<sequence_t*> sequences
|
||||
{
|
||||
};
|
||||
return sequences;
|
||||
}
|
||||
|
||||
public:
|
||||
static bool EvaluateIfDirective(std::map<std::string, DefinesStreamProxy::Define>& defines, const std::string& value)
|
||||
{
|
||||
std::istringstream ss(value);
|
||||
ParserSingleInputStream inputStream(ss, "");
|
||||
SimpleLexer::Config config{};
|
||||
config.m_emit_new_line_tokens = false;
|
||||
config.m_read_numbers = true;
|
||||
config.m_read_strings = false;
|
||||
SimpleLexer lexer(&inputStream, std::move(config));
|
||||
DefinesIfDirectiveParser parser(&lexer);
|
||||
if (!parser.Parse())
|
||||
return false;
|
||||
|
||||
const auto& expression = parser.m_state->m_expression;
|
||||
return expression->IsStatic() && expression->Evaluate().IsTruthy();
|
||||
}
|
||||
};
|
||||
|
||||
DefinesStreamProxy::DefineParameterPosition::DefineParameterPosition()
|
||||
: m_parameter_index(0u),
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <unordered_map>
|
||||
#include <map>
|
||||
#include <stack>
|
||||
#include <sstream>
|
||||
|
||||
@ -44,7 +44,7 @@ public:
|
||||
|
||||
private:
|
||||
IParserLineStream* const m_stream;
|
||||
std::unordered_map<std::string, Define> m_defines;
|
||||
std::map<std::string, Define> m_defines;
|
||||
std::stack<bool> m_modes;
|
||||
unsigned m_ignore_depth;
|
||||
|
||||
|
Reference in New Issue
Block a user