xo-reader2: simplify DExpectTypeSsm w/ DSyntaxStateMachine
This commit is contained in:
parent
3b1b4f03b5
commit
feb94b13cb
2 changed files with 13 additions and 274 deletions
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "SyntaxStateMachine.hpp"
|
#include "DSyntaxStateMachine.hpp"
|
||||||
#include <xo/indentlog/print/ppindentinfo.hpp>
|
#include <xo/indentlog/print/ppindentinfo.hpp>
|
||||||
|
|
||||||
namespace xo {
|
namespace xo {
|
||||||
|
|
@ -21,8 +21,9 @@ namespace xo {
|
||||||
*
|
*
|
||||||
* @endpre
|
* @endpre
|
||||||
**/
|
**/
|
||||||
class DExpectTypeSsm {
|
class DExpectTypeSsm : public DSyntaxStateMachine<DExpectTypeSsm> {
|
||||||
public:
|
public:
|
||||||
|
using Super = DSyntaxStateMachine<DExpectTypeSsm>;
|
||||||
using TypeDescr = xo::reflect::TypeDescr;
|
using TypeDescr = xo::reflect::TypeDescr;
|
||||||
using DArena = xo::mm::DArena;
|
using DArena = xo::mm::DArena;
|
||||||
using ppindentinfo = xo::print::ppindentinfo;
|
using ppindentinfo = xo::print::ppindentinfo;
|
||||||
|
|
@ -34,6 +35,8 @@ namespace xo {
|
||||||
|
|
||||||
static void start(ParserStateMachine * p_psm);
|
static void start(ParserStateMachine * p_psm);
|
||||||
|
|
||||||
|
const char * ssm_classname() const noexcept { return "DExpectTypeSsm"; }
|
||||||
|
|
||||||
/** @defgroup scm-expecttype-ssm-facet syntaxstatemachine facet methods **/
|
/** @defgroup scm-expecttype-ssm-facet syntaxstatemachine facet methods **/
|
||||||
///@{
|
///@{
|
||||||
|
|
||||||
|
|
@ -57,105 +60,6 @@ namespace xo {
|
||||||
void on_symbol_token(const Token & tk,
|
void on_symbol_token(const Token & tk,
|
||||||
ParserStateMachine * p_psm);
|
ParserStateMachine * p_psm);
|
||||||
|
|
||||||
/** operate state machine for this syntax on incoming define-token @p tk
|
|
||||||
* with overall parser state in @p p_psm
|
|
||||||
**/
|
|
||||||
void on_def_token(const Token & tk,
|
|
||||||
ParserStateMachine * p_psm);
|
|
||||||
|
|
||||||
/** operate state machine for this syntax on incoming if-token @p tk
|
|
||||||
* with overall parser state in @p p_psm
|
|
||||||
**/
|
|
||||||
void on_if_token(const Token & tk,
|
|
||||||
ParserStateMachine * p_psm);
|
|
||||||
|
|
||||||
/** operate state machine for this syntax on incoming colon-token @p tk
|
|
||||||
* with overall parser state in @p p_psm
|
|
||||||
**/
|
|
||||||
void on_colon_token(const Token & tk,
|
|
||||||
ParserStateMachine * p_psm);
|
|
||||||
|
|
||||||
/** operate state machine for this syntax on incoming singleassign-token @p tk
|
|
||||||
* with overall parser state in @p p_psm
|
|
||||||
**/
|
|
||||||
void on_singleassign_token(const Token & tk,
|
|
||||||
ParserStateMachine * p_psm);
|
|
||||||
|
|
||||||
/** update state for this syntax on incoming string token @p tk,
|
|
||||||
* overall parser state in @p p_psm
|
|
||||||
**/
|
|
||||||
void on_string_token(const Token & tk,
|
|
||||||
ParserStateMachine * p_psm);
|
|
||||||
|
|
||||||
/** update state for this syntax on incoming f64 token @p tk,
|
|
||||||
* overall parser state in @p p_psm
|
|
||||||
**/
|
|
||||||
void on_f64_token(const Token & tk,
|
|
||||||
ParserStateMachine * p_psm);
|
|
||||||
|
|
||||||
/** update state for this syntax on incoming i64 token @p tk,
|
|
||||||
* overall parser state in @p p_psm
|
|
||||||
**/
|
|
||||||
void on_i64_token(const Token & tk,
|
|
||||||
ParserStateMachine * p_psm);
|
|
||||||
|
|
||||||
/** update state for this syntax on incoming bool token @p tk,
|
|
||||||
* overall parser state in @p p_psm
|
|
||||||
**/
|
|
||||||
void on_bool_token(const Token & tk,
|
|
||||||
ParserStateMachine * p_psm);
|
|
||||||
|
|
||||||
/** update state for this syntax on incoming semicolon token @p tk,
|
|
||||||
* overall parser state in @p p_psm
|
|
||||||
**/
|
|
||||||
void on_semicolon_token(const Token & tk,
|
|
||||||
ParserStateMachine * p_psm);
|
|
||||||
|
|
||||||
/** (Never called).
|
|
||||||
* Operate state machine for this syntax after symbol
|
|
||||||
* emitted from nested ssm.
|
|
||||||
* Impossible path for DExpectTypeSsm until such time as it relies
|
|
||||||
* on nested ssms. Currently using on_symbol_token
|
|
||||||
* entry point instead.
|
|
||||||
**/
|
|
||||||
void on_parsed_symbol(std::string_view sym,
|
|
||||||
ParserStateMachine * p_psm);
|
|
||||||
|
|
||||||
/** operate state machine for this syntax on receiving type-description
|
|
||||||
* from nested parser.
|
|
||||||
* Currently (jan 2026) impossible path for DExpectTypeSsm.
|
|
||||||
* Active path is via on_symbol_token()
|
|
||||||
**/
|
|
||||||
void on_parsed_typedescr(TypeDescr td,
|
|
||||||
ParserStateMachine * p_psm);
|
|
||||||
|
|
||||||
/** operate state machine to consume formal param (name,value)
|
|
||||||
* emitted by nested ssm
|
|
||||||
**/
|
|
||||||
void on_parsed_formal(const DUniqueString * param_name,
|
|
||||||
TypeDescr param_type,
|
|
||||||
ParserStateMachine * p_psm);
|
|
||||||
|
|
||||||
/** consume formal params @p arglist from completed nested ssm,
|
|
||||||
* with overall parser state in @p p_psm.
|
|
||||||
**/
|
|
||||||
void on_parsed_formal_arglist(DArray * arglist,
|
|
||||||
ParserStateMachine * p_psm);
|
|
||||||
|
|
||||||
/** operate state machine for this syntax on receiving expression
|
|
||||||
* from nested parser.
|
|
||||||
* (provided to satisfy ASyntaxStateMachine api. not reachable)
|
|
||||||
**/
|
|
||||||
void on_parsed_expression(obj<AExpression> expr,
|
|
||||||
ParserStateMachine * p_psm);
|
|
||||||
|
|
||||||
/** operate state machine for this syntax on receiving expression
|
|
||||||
* followed by semicolon from nested parser.
|
|
||||||
* (provided to satisfy ASyntaxStateMachine api. not reachable)
|
|
||||||
**/
|
|
||||||
void on_parsed_expression_with_semicolon(obj<AExpression> expr,
|
|
||||||
ParserStateMachine * p_psm);
|
|
||||||
|
|
||||||
///@}
|
///@}
|
||||||
/** @defgroup scm-expecttype-printable-facet printable facet methods **/
|
/** @defgroup scm-expecttype-printable-facet printable facet methods **/
|
||||||
///@{
|
///@{
|
||||||
|
|
|
||||||
|
|
@ -66,44 +66,14 @@ namespace xo {
|
||||||
this->on_symbol_token(tk, p_psm);
|
this->on_symbol_token(tk, p_psm);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case tokentype::tk_def:
|
|
||||||
this->on_def_token(tk, p_psm);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case tokentype::tk_if:
|
|
||||||
this->on_if_token(tk, p_psm);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case tokentype::tk_colon:
|
|
||||||
this->on_colon_token(tk, p_psm);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case tokentype::tk_singleassign:
|
|
||||||
this->on_singleassign_token(tk, p_psm);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case tokentype::tk_string:
|
|
||||||
this->on_string_token(tk, p_psm);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case tokentype::tk_f64:
|
|
||||||
this->on_f64_token(tk, p_psm);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case tokentype::tk_i64:
|
|
||||||
this->on_i64_token(tk, p_psm);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case tokentype::tk_bool:
|
|
||||||
this->on_bool_token(tk, p_psm);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case tokentype::tk_semicolon:
|
|
||||||
this->on_semicolon_token(tk, p_psm);
|
|
||||||
break;
|
|
||||||
|
|
||||||
// all the not-yet handled cases
|
// all the not-yet handled cases
|
||||||
case tokentype::tk_invalid:
|
case tokentype::tk_invalid:
|
||||||
|
case tokentype::tk_def:
|
||||||
|
case tokentype::tk_if:
|
||||||
|
case tokentype::tk_f64:
|
||||||
|
case tokentype::tk_i64:
|
||||||
|
case tokentype::tk_bool:
|
||||||
|
case tokentype::tk_string:
|
||||||
case tokentype::tk_leftparen:
|
case tokentype::tk_leftparen:
|
||||||
case tokentype::tk_rightparen:
|
case tokentype::tk_rightparen:
|
||||||
case tokentype::tk_leftbracket:
|
case tokentype::tk_leftbracket:
|
||||||
|
|
@ -116,8 +86,11 @@ namespace xo {
|
||||||
case tokentype::tk_greatequal:
|
case tokentype::tk_greatequal:
|
||||||
case tokentype::tk_dot:
|
case tokentype::tk_dot:
|
||||||
case tokentype::tk_comma:
|
case tokentype::tk_comma:
|
||||||
|
case tokentype::tk_colon:
|
||||||
|
case tokentype::tk_semicolon:
|
||||||
case tokentype::tk_doublecolon:
|
case tokentype::tk_doublecolon:
|
||||||
case tokentype::tk_assign:
|
case tokentype::tk_assign:
|
||||||
|
case tokentype::tk_singleassign:
|
||||||
case tokentype::tk_yields:
|
case tokentype::tk_yields:
|
||||||
case tokentype::tk_plus:
|
case tokentype::tk_plus:
|
||||||
case tokentype::tk_minus:
|
case tokentype::tk_minus:
|
||||||
|
|
@ -140,87 +113,6 @@ namespace xo {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
DExpectTypeSsm::on_def_token(const Token & tk,
|
|
||||||
ParserStateMachine * p_psm)
|
|
||||||
{
|
|
||||||
p_psm->illegal_input_on_token("DExpectTypeSsm",
|
|
||||||
tk,
|
|
||||||
this->get_expect_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
DExpectTypeSsm::on_if_token(const Token & tk,
|
|
||||||
ParserStateMachine * p_psm)
|
|
||||||
{
|
|
||||||
p_psm->illegal_input_on_token("DxpectTypeSsm",
|
|
||||||
tk,
|
|
||||||
this->get_expect_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
DExpectTypeSsm::on_colon_token(const Token & tk,
|
|
||||||
ParserStateMachine * p_psm)
|
|
||||||
{
|
|
||||||
p_psm->illegal_input_on_token("DxpectTypeSsm",
|
|
||||||
tk,
|
|
||||||
this->get_expect_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
DExpectTypeSsm::on_singleassign_token(const Token & tk,
|
|
||||||
ParserStateMachine * p_psm)
|
|
||||||
{
|
|
||||||
p_psm->illegal_input_on_token("DExpectTypeSsm::on_singleassign_token",
|
|
||||||
tk,
|
|
||||||
this->get_expect_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
DExpectTypeSsm::on_string_token(const Token & tk,
|
|
||||||
ParserStateMachine * p_psm)
|
|
||||||
{
|
|
||||||
p_psm->illegal_input_on_token("DExpectTypeSsm",
|
|
||||||
tk,
|
|
||||||
this->get_expect_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
DExpectTypeSsm::on_f64_token(const Token & tk,
|
|
||||||
ParserStateMachine * p_psm)
|
|
||||||
{
|
|
||||||
p_psm->illegal_input_on_token("DExpectTypeSsm",
|
|
||||||
tk,
|
|
||||||
this->get_expect_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
DExpectTypeSsm::on_i64_token(const Token & tk,
|
|
||||||
ParserStateMachine * p_psm)
|
|
||||||
{
|
|
||||||
p_psm->illegal_input_on_token("DExpectTypeSsm::on_i64_token",
|
|
||||||
tk,
|
|
||||||
this->get_expect_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
DExpectTypeSsm::on_bool_token(const Token & tk,
|
|
||||||
ParserStateMachine * p_psm)
|
|
||||||
{
|
|
||||||
p_psm->illegal_input_on_token("DExpectTypeSsm::on_bool_token",
|
|
||||||
tk,
|
|
||||||
this->get_expect_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
DExpectTypeSsm::on_semicolon_token(const Token & tk,
|
|
||||||
ParserStateMachine * p_psm)
|
|
||||||
{
|
|
||||||
p_psm->illegal_input_on_token("DExpectTypeSsm::on_semicolon_token",
|
|
||||||
tk,
|
|
||||||
this->get_expect_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
DExpectTypeSsm::on_symbol_token(const Token & tk,
|
DExpectTypeSsm::on_symbol_token(const Token & tk,
|
||||||
ParserStateMachine * p_psm)
|
ParserStateMachine * p_psm)
|
||||||
|
|
@ -247,71 +139,14 @@ namespace xo {
|
||||||
td = Reflect::require<std::int64_t>();
|
td = Reflect::require<std::int64_t>();
|
||||||
|
|
||||||
if (!td) {
|
if (!td) {
|
||||||
p_psm->illegal_input_on_token("DExpectTypeSsm::on_symbol_token",
|
Super::on_token(tk, p_psm);
|
||||||
tk,
|
return;
|
||||||
this->get_expect_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
p_psm->pop_ssm();
|
p_psm->pop_ssm();
|
||||||
p_psm->on_parsed_typedescr(td);
|
p_psm->on_parsed_typedescr(td);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
DExpectTypeSsm::on_parsed_symbol(std::string_view sym,
|
|
||||||
ParserStateMachine * p_psm)
|
|
||||||
{
|
|
||||||
p_psm->illegal_input_on_symbol("ExpectTypeSsm::on_parsed_symbol",
|
|
||||||
sym,
|
|
||||||
this->get_expect_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
DExpectTypeSsm::on_parsed_typedescr(TypeDescr td,
|
|
||||||
ParserStateMachine * p_psm)
|
|
||||||
{
|
|
||||||
p_psm->illegal_input_on_typedescr("ExpectTypeSsm::on_parsed_typedescr",
|
|
||||||
td,
|
|
||||||
this->get_expect_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
DExpectTypeSsm::on_parsed_formal(const DUniqueString * param_name,
|
|
||||||
TypeDescr param_type,
|
|
||||||
ParserStateMachine * p_psm)
|
|
||||||
{
|
|
||||||
p_psm->illegal_parsed_formal("DExpectTypeSsm::on_parsed_formal",
|
|
||||||
param_name,
|
|
||||||
param_type,
|
|
||||||
this->get_expect_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
DExpectTypeSsm::on_parsed_formal_arglist(DArray * arglist,
|
|
||||||
ParserStateMachine * p_psm)
|
|
||||||
{
|
|
||||||
p_psm->illegal_parsed_formal_arglist("DExpectTypeSsm::on_parsed_formal_arglist",
|
|
||||||
arglist,
|
|
||||||
this->get_expect_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
DExpectTypeSsm::on_parsed_expression(obj<AExpression> expr,
|
|
||||||
ParserStateMachine * p_psm)
|
|
||||||
{
|
|
||||||
p_psm->illegal_parsed_expression("DExpectTypeSsm::on_parsed_expression",
|
|
||||||
expr,
|
|
||||||
this->get_expect_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
DExpectTypeSsm::on_parsed_expression_with_semicolon(obj<AExpression> expr,
|
|
||||||
ParserStateMachine * p_psm)
|
|
||||||
{
|
|
||||||
p_psm->illegal_parsed_expression("DExpectTypeSsm::on_parsed_expression_with_semicolon",
|
|
||||||
expr,
|
|
||||||
this->get_expect_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
DExpectTypeSsm::pretty(const ppindentinfo & ppii) const
|
DExpectTypeSsm::pretty(const ppindentinfo & ppii) const
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue