WsParser_VS/libSyntax/syntax_templets.h

64 lines
2.2 KiB
C
Raw Permalink 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>
2025-02-12 04:37:49 +00:00
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-14 01:26:42 +00:00
class Any : public lib_syntax::__anyone_impl, public __types_list<TYPES...> {
2025-02-11 14:32:10 +00:00
public:
2025-02-14 01:26:42 +00:00
Any() : __anyone_impl(__types_list<TYPES...>::getRules()) { }
2025-02-11 14:32:10 +00:00
};
template<typename... TYPES>
2025-02-14 01:26:42 +00:00
class Seqs : public lib_syntax::__sequence_impl, public __types_list<TYPES...> {
2025-02-11 14:32:10 +00:00
public:
2025-02-14 01:26:42 +00:00
Seqs() : __sequence_impl(__types_list<TYPES...>::getRules()) { }
2025-02-11 14:32:10 +00:00
};
2025-02-12 02:26:39 +00:00
template<typename TYPE, int min, int max> requires std::derived_from<TYPE, lib_syntax::IBasicRule>
2025-02-14 01:26:42 +00:00
class Rept : public lib_syntax::__repeat_impl {
2025-02-11 14:32:10 +00:00
public:
2025-02-14 01:26:42 +00:00
Rept() : __repeat_impl(std::make_shared<TYPE>(), min, max) { }
2025-02-11 14:32:10 +00:00
};
2025-02-14 01:26:42 +00:00
template<typename TYPE> class OptMulti : public Rept<TYPE, 0, INT_MAX> { };
template<typename TYPE> class Multi : public Rept<TYPE, 1, INT_MAX> { };
template<typename TYPE> class Opt : public Rept<TYPE, 0, 1> { };
2025-02-11 14:32:10 +00:00
2025-02-12 02:26:39 +00:00
template<typename E, typename T, lib_token::TokenProc<E> p = nullptr>
2025-02-12 04:37:49 +00:00
requires std::derived_from<E, ast_basic::IExprInstance>&& std::derived_from<T, lib_token::ITokenProcess>
2025-02-14 01:26:42 +00:00
class Action : public lib_syntax::__token_match_impl<E, p> {
2025-02-12 04:37:49 +00:00
public:
2025-02-14 01:26:42 +00:00
Action() : __token_match_impl<E, p>(std::make_shared<T>()) { }
2025-02-11 14:32:10 +00:00
};
2025-02-12 04:37:49 +00:00
template<typename ExprT> requires std::derived_from<ExprT, ast_basic::IExprInstance>
void apntk(std::shared_ptr<ExprT> expr, std::shared_ptr<const lib_token::IToken> t) {
expr->addToken(t);
}
2025-02-12 06:41:24 +00:00
template<typename T>
requires std::derived_from<T, lib_token::ITokenProcess>
2025-02-14 01:26:42 +00:00
class Match : public Action<ast_basic::IExprInstance, T, apntk<ast_basic::IExprInstance>> { };
2025-02-11 14:32:10 +00:00
}