Parse menu function values

This commit is contained in:
Jan 2021-12-27 11:28:11 +01:00
parent 7ea53808b7
commit d4154d0cc2
2 changed files with 42 additions and 34 deletions

View File

@ -2,11 +2,14 @@
#include <string>
#include "Parsing/Simple/Expression/ISimpleExpression.h"
namespace menu
{
class CommonFunctionDef
{
public:
std::string m_name;
std::unique_ptr<ISimpleExpression> m_value;
};
}

View File

@ -2,6 +2,7 @@
#include <sstream>
#include "Generic/GenericExpressionPropertySequence.h"
#include "Generic/GenericStringPropertySequence.h"
#include "Parsing/Menu/Matcher/MenuMatcherFactory.h"
@ -19,7 +20,7 @@ namespace menu::function_scope_sequences
const MenuMatcherFactory create(this);
AddMatchers({
create.Char('}')
create.Char('}').Capture(CAPTURE_TOKEN)
});
}
@ -35,7 +36,7 @@ namespace menu::function_scope_sequences
else
{
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());
}
}
@ -56,4 +57,8 @@ void FunctionScopeSequences::AddSequences(FeatureLevel featureLevel, bool permis
{
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);
}));
}