WsParser_VS/libSyntax/syntax_templets.h

52 lines
1.5 KiB
C
Raw Normal View History

2025-02-11 14:32:10 +00:00
#pragma once
#include "libsyntax.h"
#include <concepts>
namespace lib_composit {
2025-02-12 02:13:35 +00:00
template<typename... TYPES> class __types_list;
2025-02-11 14:32:10 +00:00
2025-02-12 02:13:35 +00:00
template<> class __types_list<> {
2025-02-11 14:32:10 +00:00
public:
static QList<std::shared_ptr<const lib_syntax::IBasicRule>> getRules() {
return QList<std::shared_ptr<const lib_syntax::IBasicRule>>();
}
};
template<typename T, typename... Rets>
requires std::derived_from<T, lib_syntax::IBasicRule>
2025-02-12 02:13:35 +00:00
class __types_list<T, Rets...> : public __types_list<Rets...> {
2025-02-11 14:32:10 +00:00
public:
static QList<std::shared_ptr<const lib_syntax::IBasicRule>> getRules() {
2025-02-12 02:13:35 +00:00
auto list = __types_list<Rets...>::getRules();
2025-02-11 14:32:10 +00:00
list.prepend(std::make_shared<const T>());
return list;
}
};
template<typename... TYPES>
2025-02-12 02:13:35 +00:00
class AnyR : public lib_syntax::Any, public __types_list<TYPES...> {
2025-02-11 14:32:10 +00:00
public:
2025-02-12 02:13:35 +00:00
AnyR() : Any(__types_list<TYPES...>::getRules()){ }
2025-02-11 14:32:10 +00:00
};
template<typename... TYPES>
2025-02-12 02:13:35 +00:00
class SeqsR : public lib_syntax::Seqs, public __types_list<TYPES...> {
2025-02-11 14:32:10 +00:00
public:
2025-02-12 02:13:35 +00:00
SeqsR() : Seqs(__types_list<TYPES...>::getRules()){ }
2025-02-11 14:32:10 +00:00
};
template<typename TYPE, int min, int max>
class ReptR : public lib_syntax::Rept {
public:
ReptR() : Rept(std::make_shared<TYPE>(), min, max){ }
};
2025-02-12 02:13:35 +00:00
template<typename E, typename T, lib_token::TokenProc<E> xproc = nullptr>
2025-02-11 14:32:10 +00:00
requires std::derived_from<E, ast_basic::IExprInstance> && std::derived_from<T, lib_token::ITokenProcess>
class TokenR : public lib_syntax::TokenMatch<E, xproc> {
public:
TokenR() : TokenMatch<E, xproc>(std::make_shared<T>()){ }
};
}