Add string chains to menu string properties

This commit is contained in:
Jan 2021-12-02 22:39:12 +01:00
parent 6f15fe6010
commit 616c6414ff
2 changed files with 25 additions and 1 deletions

View File

@ -1,5 +1,7 @@
#include "MenuMatcherFactory.h" #include "MenuMatcherFactory.h"
#include <sstream>
#include "MenuExpressionMatchers.h" #include "MenuExpressionMatchers.h"
using namespace menu; using namespace menu;
@ -9,9 +11,30 @@ MenuMatcherFactory::MenuMatcherFactory(const IMatcherForLabelSupplier<SimplePars
{ {
} }
MatcherFactoryWrapper<SimpleParserValue> MenuMatcherFactory::StringChain() const
{
return Or({
And({
String(),
Loop(String())
}).Transform([](const token_list_t& tokens) -> SimpleParserValue
{
std::ostringstream ss;
for (const auto& token : tokens)
{
ss << token.get().StringValue();
}
return SimpleParserValue::String(tokens[0].get().GetPos(), new std::string(ss.str()));
}),
String()
});
}
MatcherFactoryWrapper<SimpleParserValue> MenuMatcherFactory::Text() const MatcherFactoryWrapper<SimpleParserValue> MenuMatcherFactory::Text() const
{ {
return MatcherFactoryWrapper(Or({String(), Identifier()})); return MatcherFactoryWrapper(Or({StringChain(), Identifier()}));
} }
MatcherFactoryWrapper<SimpleParserValue> MenuMatcherFactory::Numeric() const MatcherFactoryWrapper<SimpleParserValue> MenuMatcherFactory::Numeric() const

View File

@ -18,6 +18,7 @@ namespace menu
public: public:
explicit MenuMatcherFactory(const IMatcherForLabelSupplier<SimpleParserValue>* labelSupplier); explicit MenuMatcherFactory(const IMatcherForLabelSupplier<SimpleParserValue>* labelSupplier);
_NODISCARD MatcherFactoryWrapper<SimpleParserValue> StringChain() const;
_NODISCARD MatcherFactoryWrapper<SimpleParserValue> Text() const; _NODISCARD MatcherFactoryWrapper<SimpleParserValue> Text() const;
_NODISCARD MatcherFactoryWrapper<SimpleParserValue> Numeric() const; _NODISCARD MatcherFactoryWrapper<SimpleParserValue> Numeric() const;