xo-reader2: refactor: crtp to share code across SSM impls
This commit is contained in:
parent
d44bb78900
commit
b5b6a51ce4
4 changed files with 116 additions and 40 deletions
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "SyntaxStateMachine.hpp"
|
||||
#include "DSyntaxStateMachine.hpp"
|
||||
#include <xo/expression2/DLambdaExpr.hpp>
|
||||
#include <xo/expression2/SymbolTable.hpp>
|
||||
//#include <xo/expression2/DLocalSymtab.hpp>
|
||||
|
|
@ -55,9 +55,9 @@ namespace xo {
|
|||
/** @class DLambdaSsm
|
||||
* @brief parsing state-machine for a lambda-expression
|
||||
**/
|
||||
class DLambdaSsm {
|
||||
class DLambdaSsm : public DSyntaxStateMachine<DLambdaSsm> {
|
||||
public:
|
||||
//using DSymbolTable = xo::scm::DSymbolTable;
|
||||
using Super = DSyntaxStateMachine<DLambdaSsm>;
|
||||
using DLocalSymtab = xo::scm::DLocalSymtab;
|
||||
using AAllocator = xo::mm::AAllocator;
|
||||
using DArena = xo::mm::DArena;
|
||||
|
|
@ -80,6 +80,8 @@ namespace xo {
|
|||
/** @defgroup scm-lambdassm-methods **/
|
||||
///@{
|
||||
|
||||
const char * ssm_classname() const noexcept { return "DLambdaSsm"; }
|
||||
|
||||
static void start(ParserStateMachine * p_psm);
|
||||
|
||||
/** update ssm on lambda keyword token @p tk,
|
||||
|
|
@ -110,11 +112,13 @@ namespace xo {
|
|||
void on_token(const Token & tk,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
#ifdef OBSOLETE
|
||||
/** update this ssm when nested parser
|
||||
* emits @p td.
|
||||
**/
|
||||
void on_parsed_symbol(std::string_view sym,
|
||||
ParserStateMachine * p_psm);
|
||||
#endif
|
||||
|
||||
/** update this ssm when nested parser
|
||||
* emits @p td.
|
||||
|
|
@ -122,12 +126,14 @@ namespace xo {
|
|||
void on_parsed_typedescr(TypeDescr td,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
#ifdef OBSOLETE
|
||||
/** update this ssm to consume parsed formal (name,value)
|
||||
* from nested (and now expired) ssm
|
||||
**/
|
||||
void on_parsed_formal(const DUniqueString * sym,
|
||||
TypeDescr td,
|
||||
ParserStateMachine * p_psm);
|
||||
#endif
|
||||
|
||||
/** consume formal params @p arglist from completed nested ssm,
|
||||
* with overall parser state in @p p_psm.
|
||||
|
|
|
|||
|
|
@ -5,16 +5,16 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "SyntaxStateMachine.hpp"
|
||||
#include <xo/object2/DArray.hpp>
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
|
||||
/** @class DSyntaxStateMachine
|
||||
* @brief static interface for implementing ASyntaxStateMachine
|
||||
* @brief static helper interface for ASyntaxStateMachine implementations
|
||||
*
|
||||
* Using CRTP to collect methods common to ASyntaxStateMachine
|
||||
* implementations.
|
||||
* Using CRTP.
|
||||
*
|
||||
* Deliberately unusable through base class pointer.
|
||||
* For runtime polymorphism use something like:
|
||||
|
|
@ -27,11 +27,91 @@ namespace xo {
|
|||
**/
|
||||
template<typename Derived>
|
||||
class DSyntaxStateMachine {
|
||||
friend Derived;
|
||||
public:
|
||||
using TypeDescr = xo::reflect::TypeDescr;
|
||||
|
||||
/** arglist is DArray of obj<AGCObejct,DVariable> **/
|
||||
void on_parsed_formal_arglist(this auto&& self, DArray * arglist, ParserStateMachine * p_psm) {
|
||||
p_psm->illegal_parsed_formal_arglist(
|
||||
/** Default implementation for required SyntaxStateMachine facet method
|
||||
**/
|
||||
void on_token(this auto&& self,
|
||||
const Token & tk,
|
||||
ParserStateMachine * p_psm)
|
||||
{
|
||||
p_psm->illegal_input_on_token(self.ssm_classname(),
|
||||
tk,
|
||||
self.get_expect_str());
|
||||
}
|
||||
|
||||
void on_parsed_symbol(this auto&& self,
|
||||
std::string_view sym,
|
||||
ParserStateMachine * p_psm)
|
||||
{
|
||||
p_psm->illegal_input_on_symbol(self.ssm_classname(),
|
||||
sym,
|
||||
self.get_expect_str());
|
||||
}
|
||||
|
||||
/** Default implementation for required SyntaxStateMachine facet method
|
||||
**/
|
||||
void on_parsed_typedescr(this auto&& self,
|
||||
TypeDescr td,
|
||||
ParserStateMachine * p_psm)
|
||||
{
|
||||
p_psm->illegal_input_on_typedescr(self.ssm_classname(),
|
||||
td,
|
||||
self.get_expect_str());
|
||||
}
|
||||
|
||||
/** Default implementation for required SyntaxStateMachine facet method
|
||||
**/
|
||||
void on_parsed_formal(this auto&& self,
|
||||
const DUniqueString * param_name,
|
||||
TypeDescr param_type,
|
||||
ParserStateMachine * p_psm)
|
||||
{
|
||||
p_psm->illegal_parsed_formal(self.ssm_classname(),
|
||||
param_name,
|
||||
param_type,
|
||||
self.get_expect_str());
|
||||
}
|
||||
|
||||
/** Default implementation for required SyntaxStateMachine facet method
|
||||
*
|
||||
* arglist is DArray of obj<AGCObejct,DVariable>
|
||||
**/
|
||||
void on_parsed_formal_arglist(this auto&& self,
|
||||
DArray * arglist,
|
||||
ParserStateMachine * p_psm)
|
||||
{
|
||||
p_psm->illegal_parsed_formal_arglist(self.ssm_classname(),
|
||||
arglist,
|
||||
self.get_expect_str());
|
||||
}
|
||||
|
||||
/** Default implementation for required SyntaxStateMachine facet method
|
||||
**/
|
||||
void on_parsed_expression(this auto&& self,
|
||||
obj<AExpression> expr,
|
||||
ParserStateMachine * p_psm)
|
||||
{
|
||||
p_psm->illegal_parsed_expression(self.ssm_classname(),
|
||||
expr,
|
||||
self.get_expect_str());
|
||||
|
||||
}
|
||||
|
||||
/** Default implementation for required SyntaxStateMachine facet method
|
||||
**/
|
||||
void on_parsed_expression_with_semicolon(this auto&& self,
|
||||
obj<AExpression> expr,
|
||||
ParserStateMachine * p_psm)
|
||||
{
|
||||
// We don't need a separate entry point,
|
||||
// since the semicolon isn't relevant to problem with syntax
|
||||
//
|
||||
|
||||
p_psm->illegal_parsed_expression(self.ssm_classname(),
|
||||
expr,
|
||||
self.get_expect_str());
|
||||
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue