xo-reader2 stack: expand symbol table to store typedefs
+ typedef utest + misc qol policy choices
This commit is contained in:
parent
07b7a7c978
commit
76af3ff3b5
42 changed files with 1050 additions and 110 deletions
|
|
@ -25,6 +25,10 @@ set(SELF_SRCS
|
|||
ISyntaxStateMachine_DDefineSsm.cpp
|
||||
IPrintable_DDefineSsm.cpp
|
||||
|
||||
DDeftypeSsm.cpp
|
||||
ISyntaxStateMachine_DDeftypeSsm.cpp
|
||||
IPrintable_DDeftypeSsm.cpp
|
||||
|
||||
DIfElseSsm.cpp
|
||||
ISyntaxStateMachine_DIfElseSsm.cpp
|
||||
IPrintable_DIfElseSsm.cpp
|
||||
|
|
|
|||
|
|
@ -139,6 +139,7 @@ namespace xo {
|
|||
return;
|
||||
case tokentype::tk_symbol:
|
||||
case tokentype::tk_def:
|
||||
case tokentype::tk_deftype:
|
||||
case tokentype::tk_if:
|
||||
case tokentype::tk_then:
|
||||
case tokentype::tk_else:
|
||||
|
|
|
|||
|
|
@ -13,14 +13,6 @@
|
|||
#include <xo/printable2/Printable.hpp>
|
||||
#include <xo/facet/FacetRegistry.hpp>
|
||||
|
||||
#ifdef NOT_YET
|
||||
#include "parserstatemachine.hpp"
|
||||
#include "expect_symbol_xs.hpp"
|
||||
#include "expect_expr_xs.hpp"
|
||||
#include "expect_type_xs.hpp"
|
||||
#include "pretty_expression.hpp"
|
||||
#endif
|
||||
|
||||
namespace xo {
|
||||
using xo::print::APrintable;
|
||||
using xo::facet::FacetRegistry;
|
||||
|
|
@ -526,6 +518,7 @@ namespace xo {
|
|||
|
||||
// all the not-yet handled cases
|
||||
case tokentype::tk_invalid:
|
||||
case tokentype::tk_deftype:
|
||||
case tokentype::tk_string:
|
||||
case tokentype::tk_f64:
|
||||
case tokentype::tk_i64:
|
||||
|
|
@ -600,7 +593,7 @@ namespace xo {
|
|||
if (defstate_ == defexprstatetype::def_2) {
|
||||
this->defstate_ = defexprstatetype::def_3;
|
||||
|
||||
DExpectTypeSsm::start(p_psm);
|
||||
DExpectTypeSsm::start(false /*!corrected*/, p_psm);
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
@ -688,7 +681,6 @@ namespace xo {
|
|||
= FacetRegistry::instance().variant<APrintable,
|
||||
AExpression>(def_expr_);
|
||||
assert(expr.data());
|
||||
(void)expr;
|
||||
|
||||
return ppii.pps()->pretty_struct(ppii,
|
||||
"DDefineSsm",
|
||||
|
|
|
|||
275
src/reader2/DDeftypeSsm.cpp
Normal file
275
src/reader2/DDeftypeSsm.cpp
Normal file
|
|
@ -0,0 +1,275 @@
|
|||
/** @file DDeftypeSsm.cpp
|
||||
*
|
||||
* @author Roland Conybeare, Mar 2026
|
||||
**/
|
||||
|
||||
#include "DeftypeSsm.hpp"
|
||||
#include "syntaxstatetype.hpp"
|
||||
#include "ExpectSymbolSsm.hpp"
|
||||
#include "ExpectTypeSsm.hpp"
|
||||
#include "Constant.hpp"
|
||||
#include <xo/object2/Boolean.hpp>
|
||||
#include <string_view>
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
|
||||
extern const char *
|
||||
DeftypeXst::_descr(enum DeftypeXst::code x)
|
||||
{
|
||||
switch (x) {
|
||||
case code::invalid: return "invalid";
|
||||
case code::def_0: return "def_0";
|
||||
case code::def_1: return "def_1";
|
||||
case code::def_2: return "def_2";
|
||||
case code::def_3: return "def_3";
|
||||
case code::def_4: return "def_4";
|
||||
case code::N: break;
|
||||
}
|
||||
|
||||
return "?DeftypeXst";
|
||||
}
|
||||
|
||||
std::ostream &
|
||||
operator<<(std::ostream & os, DeftypeXst x)
|
||||
{
|
||||
os << DeftypeXst::_descr(x.code());
|
||||
return os;
|
||||
}
|
||||
|
||||
DDeftypeSsm::DDeftypeSsm()
|
||||
: deftype_xst_{DeftypeXst::code::def_0}
|
||||
{}
|
||||
|
||||
DDeftypeSsm *
|
||||
DDeftypeSsm::_make(DArena & parser_mm)
|
||||
{
|
||||
void * mem = parser_mm.alloc_for<DDeftypeSsm>();
|
||||
|
||||
return new (mem) DDeftypeSsm();
|
||||
}
|
||||
|
||||
obj<ASyntaxStateMachine,DDeftypeSsm>
|
||||
DDeftypeSsm::make(DArena & parser_mm)
|
||||
{
|
||||
return obj<ASyntaxStateMachine,DDeftypeSsm>(_make(parser_mm));
|
||||
}
|
||||
|
||||
void
|
||||
DDeftypeSsm::start(DArena & mm,
|
||||
ParserStateMachine * p_psm)
|
||||
{
|
||||
assert(p_psm->stack());
|
||||
|
||||
DArena::Checkpoint ckp = p_psm->parser_alloc().checkpoint();
|
||||
|
||||
auto deftype_ssm = DDeftypeSsm::make(mm);
|
||||
|
||||
p_psm->push_ssm(ckp, deftype_ssm);
|
||||
}
|
||||
|
||||
syntaxstatetype
|
||||
DDeftypeSsm::ssm_type() const noexcept
|
||||
{
|
||||
return syntaxstatetype::deftypeexpr;
|
||||
}
|
||||
|
||||
std::string_view
|
||||
DDeftypeSsm::get_expect_str() const noexcept
|
||||
{
|
||||
switch (this->deftype_xst_.code()) {
|
||||
case DeftypeXst::code::invalid:
|
||||
break;
|
||||
case DeftypeXst::code::def_0:
|
||||
return "deftype";
|
||||
case DeftypeXst::code::def_1:
|
||||
return "symbol";
|
||||
case DeftypeXst::code::def_2:
|
||||
return "doublecolon";
|
||||
case DeftypeXst::code::def_3:
|
||||
return "type";
|
||||
case DeftypeXst::code::def_4:
|
||||
return "semicolon";
|
||||
case DeftypeXst::code::N:
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return "?expect";
|
||||
}
|
||||
|
||||
void
|
||||
DDeftypeSsm::on_token(const Token & tk,
|
||||
ParserStateMachine * p_psm)
|
||||
{
|
||||
scope log(XO_DEBUG(p_psm->debug_flag()), xtag("tk", tk));
|
||||
|
||||
switch (tk.tk_type()) {
|
||||
|
||||
case tokentype::tk_deftype:
|
||||
this->on_deftype_token(tk, p_psm);
|
||||
return;
|
||||
|
||||
case tokentype::tk_doublecolon:
|
||||
this->on_doublecolon_token(tk, p_psm);
|
||||
return;
|
||||
|
||||
case tokentype::tk_semicolon:
|
||||
this->on_semicolon_token(tk, p_psm);
|
||||
return;
|
||||
|
||||
// all the not-yet handled cases
|
||||
case tokentype::tk_symbol:
|
||||
case tokentype::tk_def:
|
||||
case tokentype::tk_colon:
|
||||
case tokentype::tk_singleassign:
|
||||
case tokentype::tk_invalid:
|
||||
case tokentype::tk_string:
|
||||
case tokentype::tk_f64:
|
||||
case tokentype::tk_i64:
|
||||
case tokentype::tk_bool:
|
||||
case tokentype::tk_if:
|
||||
case tokentype::tk_quote:
|
||||
case tokentype::tk_leftparen:
|
||||
case tokentype::tk_rightparen:
|
||||
case tokentype::tk_leftbracket:
|
||||
case tokentype::tk_rightbracket:
|
||||
case tokentype::tk_leftbrace:
|
||||
case tokentype::tk_rightbrace:
|
||||
case tokentype::tk_leftangle:
|
||||
case tokentype::tk_rightangle:
|
||||
case tokentype::tk_lessequal:
|
||||
case tokentype::tk_greatequal:
|
||||
case tokentype::tk_dot:
|
||||
case tokentype::tk_comma:
|
||||
case tokentype::tk_assign:
|
||||
case tokentype::tk_yields:
|
||||
case tokentype::tk_plus:
|
||||
case tokentype::tk_minus:
|
||||
case tokentype::tk_star:
|
||||
case tokentype::tk_slash:
|
||||
case tokentype::tk_cmpeq:
|
||||
case tokentype::tk_cmpne:
|
||||
case tokentype::tk_type:
|
||||
case tokentype::tk_lambda:
|
||||
case tokentype::tk_then:
|
||||
case tokentype::tk_else:
|
||||
case tokentype::tk_let:
|
||||
case tokentype::tk_in:
|
||||
case tokentype::tk_end:
|
||||
case tokentype::N:
|
||||
break;
|
||||
}
|
||||
|
||||
Super::illegal_token(tk, p_psm);
|
||||
}
|
||||
|
||||
void
|
||||
DDeftypeSsm::on_deftype_token(const Token & tk,
|
||||
ParserStateMachine * p_psm)
|
||||
{
|
||||
if (deftype_xst_.code() == DeftypeXst::code::def_0) {
|
||||
this->deftype_xst_ = DeftypeXst(DeftypeXst::code::def_1);
|
||||
|
||||
DExpectSymbolSsm::start(p_psm);
|
||||
|
||||
/* continue in .on_parsed_symbol() */
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Super::illegal_token(tk, p_psm);
|
||||
}
|
||||
|
||||
void
|
||||
DDeftypeSsm::on_parsed_symbol(std::string_view sym_name,
|
||||
ParserStateMachine * p_psm)
|
||||
{
|
||||
if (deftype_xst_.code() == DeftypeXst::code::def_1) {
|
||||
this->deftype_xst_ = DeftypeXst(DeftypeXst::code::def_2);
|
||||
this->lhs_symbol_ = p_psm->intern_string(sym_name);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Super::illegal_parsed_symbol(sym_name, p_psm);
|
||||
}
|
||||
|
||||
void
|
||||
DDeftypeSsm::on_doublecolon_token(const Token & tk,
|
||||
ParserStateMachine * p_psm)
|
||||
{
|
||||
if (deftype_xst_.code() == DeftypeXst::code::def_2) {
|
||||
this->deftype_xst_ = DeftypeXst(DeftypeXst::code::def_3);
|
||||
|
||||
DExpectTypeSsm::start(true /*corrected*/, p_psm);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Super::illegal_token(tk, p_psm);
|
||||
}
|
||||
|
||||
void
|
||||
DDeftypeSsm::on_parsed_type(obj<AType> type,
|
||||
ParserStateMachine * p_psm)
|
||||
{
|
||||
if (deftype_xst_.code() == DeftypeXst::code::def_3) {
|
||||
this->deftype_xst_ = DeftypeXst(DeftypeXst::code::def_4);
|
||||
|
||||
DLocalSymtab * local = p_psm->local_symtab();
|
||||
|
||||
if (local) {
|
||||
local->append_type(p_psm->expr_alloc(),
|
||||
lhs_symbol_,
|
||||
type);
|
||||
} else {
|
||||
DGlobalSymtab * global = p_psm->global_symtab();
|
||||
|
||||
DTypename * tname = DTypename::_make(p_psm->expr_alloc(),
|
||||
lhs_symbol_,
|
||||
type);
|
||||
|
||||
global->upsert_typename(p_psm->expr_alloc(), tname);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Super::illegal_type(type, p_psm);
|
||||
}
|
||||
|
||||
void
|
||||
DDeftypeSsm::on_semicolon_token(const Token & tk,
|
||||
ParserStateMachine * p_psm)
|
||||
{
|
||||
if (deftype_xst_.code() == DeftypeXst::code::def_4) {
|
||||
p_psm->pop_ssm();
|
||||
|
||||
// Reporting a placeholder expression to preserve policy
|
||||
// that 'every toplevel statement produces an expression'
|
||||
//
|
||||
auto result_expr
|
||||
= DConstant::make(p_psm->expr_alloc(),
|
||||
DBoolean::box<AGCObject>(p_psm->expr_alloc(),
|
||||
true));
|
||||
p_psm->on_parsed_expression(result_expr);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Super::illegal_token(tk, p_psm);
|
||||
}
|
||||
|
||||
bool
|
||||
DDeftypeSsm::pretty(const ppindentinfo & ppii) const
|
||||
{
|
||||
return ppii.pps()->pretty_struct(ppii,
|
||||
"DDeftypeSsm",
|
||||
refrtag("deftypestate", deftype_xst_),
|
||||
refrtag("expect", this->get_expect_str()));
|
||||
}
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end DDeftypeSsm.cpp */
|
||||
|
|
@ -165,6 +165,7 @@ namespace xo {
|
|||
|
||||
// all the not-yet handled cases
|
||||
case tokentype::tk_invalid:
|
||||
case tokentype::tk_deftype:
|
||||
case tokentype::tk_singleassign:
|
||||
case tokentype::tk_colon:
|
||||
case tokentype::tk_semicolon:
|
||||
|
|
|
|||
|
|
@ -105,6 +105,7 @@ namespace xo {
|
|||
case tokentype::tk_leftparen:
|
||||
case tokentype::tk_lambda:
|
||||
case tokentype::tk_def:
|
||||
case tokentype::tk_deftype:
|
||||
case tokentype::tk_if:
|
||||
case tokentype::tk_symbol:
|
||||
case tokentype::tk_singleassign:
|
||||
|
|
@ -154,7 +155,7 @@ namespace xo {
|
|||
if (fstate_ == formalstatetype::formal_1) {
|
||||
this->fstate_ = formalstatetype::formal_2;
|
||||
|
||||
DExpectTypeSsm::start(p_psm);
|
||||
DExpectTypeSsm::start(false /*!corrected*/, p_psm);
|
||||
|
||||
/* control reenters via DExpectFormalArgSsm::on_parsed_typedescr() */
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -135,6 +135,7 @@ namespace xo {
|
|||
// all the not-yet-handled cases
|
||||
case tokentype::tk_lambda:
|
||||
case tokentype::tk_def:
|
||||
case tokentype::tk_deftype:
|
||||
case tokentype::tk_if:
|
||||
case tokentype::tk_symbol:
|
||||
case tokentype::tk_colon:
|
||||
|
|
|
|||
|
|
@ -92,6 +92,7 @@ namespace xo {
|
|||
case tokentype::tk_comma:
|
||||
case tokentype::tk_lambda:
|
||||
case tokentype::tk_def:
|
||||
case tokentype::tk_deftype:
|
||||
case tokentype::tk_if:
|
||||
case tokentype::tk_symbol:
|
||||
case tokentype::tk_colon:
|
||||
|
|
|
|||
|
|
@ -92,6 +92,7 @@ namespace xo {
|
|||
case tokentype::tk_comma:
|
||||
case tokentype::tk_lambda:
|
||||
case tokentype::tk_def:
|
||||
case tokentype::tk_deftype:
|
||||
case tokentype::tk_if:
|
||||
case tokentype::tk_symbol:
|
||||
case tokentype::tk_colon:
|
||||
|
|
|
|||
|
|
@ -110,6 +110,7 @@ namespace xo {
|
|||
case tokentype::tk_comma:
|
||||
case tokentype::tk_lambda:
|
||||
case tokentype::tk_def:
|
||||
case tokentype::tk_deftype:
|
||||
case tokentype::tk_if:
|
||||
case tokentype::tk_symbol:
|
||||
case tokentype::tk_colon:
|
||||
|
|
|
|||
|
|
@ -74,6 +74,7 @@ namespace xo {
|
|||
case tokentype::tk_i64:
|
||||
case tokentype::tk_bool:
|
||||
case tokentype::tk_def:
|
||||
case tokentype::tk_deftype:
|
||||
case tokentype::tk_if:
|
||||
case tokentype::tk_singleassign:
|
||||
case tokentype::tk_colon:
|
||||
|
|
|
|||
|
|
@ -3,14 +3,15 @@
|
|||
* @author Roland Conybeare, Aug 2024
|
||||
**/
|
||||
|
||||
#include "DExpectTypeSsm.hpp"
|
||||
#include "ssm/ISyntaxStateMachine_DExpectTypeSsm.hpp"
|
||||
#include "ExpectTypeSsm.hpp"
|
||||
//#include "ssm/ISyntaxStateMachine_DExpectTypeSsm.hpp"
|
||||
#include "SyntaxStateMachine.hpp"
|
||||
#include <string_view>
|
||||
#include <xo/type/AtomicType.hpp>
|
||||
#include <xo/reflect/Reflect.hpp>
|
||||
#include <xo/facet/facet_implementation.hpp>
|
||||
#include <xo/reflectutil/typeseq.hpp>
|
||||
#include <xo/indentlog/print/pretty.hpp>
|
||||
#include <string_view>
|
||||
|
||||
namespace xo {
|
||||
using xo::facet::with_facet;
|
||||
|
|
@ -19,30 +20,32 @@ namespace xo {
|
|||
using xo::reflect::typeseq;
|
||||
|
||||
namespace scm {
|
||||
DExpectTypeSsm::DExpectTypeSsm()
|
||||
DExpectTypeSsm::DExpectTypeSsm(bool corrected)
|
||||
: corrected_{corrected}
|
||||
{}
|
||||
|
||||
DExpectTypeSsm *
|
||||
DExpectTypeSsm::_make(DArena & mm)
|
||||
DExpectTypeSsm::_make(DArena & mm, bool corrected)
|
||||
{
|
||||
void * mem = mm.alloc(typeseq::id<DArena>(),
|
||||
sizeof(DArena));
|
||||
|
||||
return new (mem) DExpectTypeSsm();
|
||||
return new (mem) DExpectTypeSsm(corrected);
|
||||
}
|
||||
|
||||
obj<ASyntaxStateMachine,DExpectTypeSsm>
|
||||
DExpectTypeSsm::make(DArena & mm)
|
||||
DExpectTypeSsm::make(DArena & mm, bool corrected)
|
||||
{
|
||||
return obj<ASyntaxStateMachine,DExpectTypeSsm>(_make(mm));
|
||||
return obj<ASyntaxStateMachine,DExpectTypeSsm>(_make(mm, corrected));
|
||||
}
|
||||
|
||||
void
|
||||
DExpectTypeSsm::start(ParserStateMachine * p_psm)
|
||||
DExpectTypeSsm::start(bool corrected,
|
||||
ParserStateMachine * p_psm)
|
||||
{
|
||||
DArena::Checkpoint ckp = p_psm->parser_alloc().checkpoint();
|
||||
|
||||
auto ssm = DExpectTypeSsm::make(p_psm->parser_alloc());
|
||||
auto ssm = DExpectTypeSsm::make(p_psm->parser_alloc(), corrected);
|
||||
|
||||
p_psm->push_ssm(ckp, ssm);
|
||||
}
|
||||
|
|
@ -73,6 +76,7 @@ namespace xo {
|
|||
// all the not-yet handled cases
|
||||
case tokentype::tk_invalid:
|
||||
case tokentype::tk_def:
|
||||
case tokentype::tk_deftype:
|
||||
case tokentype::tk_if:
|
||||
case tokentype::tk_f64:
|
||||
case tokentype::tk_i64:
|
||||
|
|
@ -124,32 +128,57 @@ namespace xo {
|
|||
{
|
||||
scope log(XO_DEBUG(p_psm->debug_flag()));
|
||||
|
||||
TypeDescr td = nullptr;
|
||||
if (corrected_) {
|
||||
obj<AType> type;
|
||||
obj mm = p_psm->expr_alloc();
|
||||
|
||||
/* TODO: replace with typetable lookup */
|
||||
if (tk.text() == "unit")
|
||||
type = DAtomicType::make(mm, Metatype::t_unit());
|
||||
if (tk.text() == "bool")
|
||||
type = DAtomicType::make(mm, Metatype::t_bool());
|
||||
else if (tk.text() == "str")
|
||||
type = DAtomicType::make(mm, Metatype::t_str());
|
||||
else if (tk.text() == "f64")
|
||||
type = DAtomicType::make(mm, Metatype::t_f64());
|
||||
else if(tk.text() == "f32")
|
||||
type = DAtomicType::make(mm, Metatype::t_f32());
|
||||
else if(tk.text() == "i16")
|
||||
type = DAtomicType::make(mm, Metatype::t_i16());
|
||||
else if(tk.text() == "i32")
|
||||
type = DAtomicType::make(mm, Metatype::t_i32());
|
||||
else if(tk.text() == "i64")
|
||||
type = DAtomicType::make(mm, Metatype::t_i64());
|
||||
|
||||
if (tk.text() == "bool")
|
||||
td = Reflect::require<bool>();
|
||||
else if (tk.text() == "str")
|
||||
td = Reflect::require<std::string>();
|
||||
else if (tk.text() == "f64")
|
||||
td = Reflect::require<double>();
|
||||
else if(tk.text() == "f32")
|
||||
td = Reflect::require<float>();
|
||||
else if(tk.text() == "i16")
|
||||
td = Reflect::require<std::int16_t>();
|
||||
else if(tk.text() == "i32")
|
||||
td = Reflect::require<std::int32_t>();
|
||||
else if(tk.text() == "i64")
|
||||
td = Reflect::require<std::int64_t>();
|
||||
p_psm->pop_ssm();
|
||||
p_psm->on_parsed_type(type);
|
||||
} else {
|
||||
TypeDescr td = nullptr;
|
||||
|
||||
if (!td) {
|
||||
Super::on_token(tk, p_psm);
|
||||
return;
|
||||
/* TODO: replace with typetable lookup */
|
||||
|
||||
if (tk.text() == "bool")
|
||||
td = Reflect::require<bool>();
|
||||
else if (tk.text() == "str")
|
||||
td = Reflect::require<std::string>();
|
||||
else if (tk.text() == "f64")
|
||||
td = Reflect::require<double>();
|
||||
else if(tk.text() == "f32")
|
||||
td = Reflect::require<float>();
|
||||
else if(tk.text() == "i16")
|
||||
td = Reflect::require<std::int16_t>();
|
||||
else if(tk.text() == "i32")
|
||||
td = Reflect::require<std::int32_t>();
|
||||
else if(tk.text() == "i64")
|
||||
td = Reflect::require<std::int64_t>();
|
||||
|
||||
if (!td) {
|
||||
Super::on_token(tk, p_psm);
|
||||
return;
|
||||
}
|
||||
|
||||
p_psm->pop_ssm();
|
||||
p_psm->on_parsed_typedescr(td);
|
||||
}
|
||||
|
||||
p_psm->pop_ssm();
|
||||
p_psm->on_parsed_typedescr(td);
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
|
|||
|
|
@ -147,6 +147,7 @@ namespace xo {
|
|||
switch (tk.tk_type()) {
|
||||
case tokentype::tk_symbol:
|
||||
case tokentype::tk_def:
|
||||
case tokentype::tk_deftype:
|
||||
break;
|
||||
case tokentype::tk_if:
|
||||
this->on_if_token(tk, p_psm);
|
||||
|
|
|
|||
|
|
@ -3,34 +3,22 @@
|
|||
* @author Roland Conybeare, Jan 2026
|
||||
**/
|
||||
|
||||
#include "DLambdaSsm.hpp"
|
||||
#include "ssm/ISyntaxStateMachine_DLambdaSsm.hpp"
|
||||
#include "DExpectFormalArglistSsm.hpp"
|
||||
#include "ssm/ISyntaxStateMachine_DExpectFormalArglistSsm.hpp"
|
||||
#include "LambdaSsm.hpp"
|
||||
//#include "ssm/ISyntaxStateMachine_DLambdaSsm.hpp"
|
||||
#include "ExpectFormalArglistSsm.hpp"
|
||||
//#include "ssm/ISyntaxStateMachine_DExpectFormalArglistSsm.hpp"
|
||||
#include "DExpectTypeSsm.hpp"
|
||||
#include "DExpectExprSsm.hpp"
|
||||
#include "ParserStateMachine.hpp"
|
||||
#include "syntaxstatetype.hpp"
|
||||
#include <xo/expression2/detail/IExpression_DLambdaExpr.hpp>
|
||||
#include <xo/expression2/DVariable.hpp>
|
||||
#include <xo/expression2/detail/IExpression_DVariable.hpp>
|
||||
#include <xo/expression2/Variable.hpp>
|
||||
//#include <xo/expression2/detail/IExpression_DVariable.hpp>
|
||||
//#include <xo/expression2/symtab/ISymbolTable_DLocalSymtab.hpp>
|
||||
#include <xo/printable2/Printable.hpp>
|
||||
#include <xo/facet/FacetRegistry.hpp>
|
||||
#include <xo/arena/DArena.hpp>
|
||||
|
||||
#ifdef NOT_YET
|
||||
#include "define_xs.hpp"
|
||||
#include "parserstatemachine.hpp"
|
||||
#include "exprstatestack.hpp"
|
||||
#include "expect_formal_arglist_xs.hpp"
|
||||
#include "expect_expr_xs.hpp"
|
||||
#include "expect_type_xs.hpp"
|
||||
#include "pretty_expression.hpp"
|
||||
#include "pretty_variable.hpp"
|
||||
#include "xo/expression/Lambda.hpp"
|
||||
#endif
|
||||
|
||||
namespace xo {
|
||||
using xo::print::APrintable;
|
||||
using xo::mm::AAllocator;
|
||||
|
|
@ -144,6 +132,7 @@ namespace xo {
|
|||
|
||||
// all the not-yet-handled cases
|
||||
case tokentype::tk_def:
|
||||
case tokentype::tk_deftype:
|
||||
case tokentype::tk_if:
|
||||
case tokentype::tk_symbol:
|
||||
case tokentype::tk_colon:
|
||||
|
|
@ -209,7 +198,7 @@ namespace xo {
|
|||
if (lmstate_ == lambdastatetype::lm_2) {
|
||||
this->lmstate_ = lambdastatetype::lm_3;
|
||||
|
||||
DExpectTypeSsm::start(p_psm);
|
||||
DExpectTypeSsm::start(false /*!corrected*/, p_psm);
|
||||
|
||||
/* control reenters via .on_parsed_typedescr() */
|
||||
return;
|
||||
|
|
@ -300,7 +289,8 @@ namespace xo {
|
|||
DLocalSymtab * symtab
|
||||
= DLocalSymtab::_make_empty(p_psm->expr_alloc(),
|
||||
p_psm->local_symtab(),
|
||||
arglist->size());
|
||||
arglist->size(),
|
||||
0 /*ntypes*/);
|
||||
assert(symtab);
|
||||
|
||||
for (DArray::size_type i = 0, n = arglist->size(); i < n; ++i) {
|
||||
|
|
|
|||
|
|
@ -102,6 +102,7 @@ namespace xo {
|
|||
// all the not-yet handled cases
|
||||
case tokentype::tk_symbol:
|
||||
case tokentype::tk_def:
|
||||
case tokentype::tk_deftype:
|
||||
case tokentype::tk_colon:
|
||||
case tokentype::tk_singleassign:
|
||||
case tokentype::tk_semicolon:
|
||||
|
|
|
|||
|
|
@ -284,6 +284,7 @@ namespace xo {
|
|||
// all the not-yet handled cases
|
||||
case tokentype::tk_invalid:
|
||||
case tokentype::tk_def:
|
||||
case tokentype::tk_deftype:
|
||||
case tokentype::tk_if:
|
||||
case tokentype::tk_quote:
|
||||
case tokentype::tk_leftbracket:
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ namespace xo {
|
|||
extern const char *
|
||||
QuoteXst::_descr(enum QuoteXst::code x)
|
||||
{
|
||||
switch(x) {
|
||||
switch (x) {
|
||||
case code::invalid: return "invalid";
|
||||
case code::quote_0: return "quote_0";
|
||||
case code::quote_1: return "quote_1";
|
||||
|
|
@ -104,6 +104,7 @@ namespace xo {
|
|||
// all the not-yet handled cases
|
||||
case tokentype::tk_symbol:
|
||||
case tokentype::tk_def:
|
||||
case tokentype::tk_deftype:
|
||||
case tokentype::tk_colon:
|
||||
case tokentype::tk_singleassign:
|
||||
case tokentype::tk_semicolon:
|
||||
|
|
|
|||
|
|
@ -81,6 +81,7 @@ namespace xo {
|
|||
return;
|
||||
case tokentype::tk_symbol:
|
||||
case tokentype::tk_def:
|
||||
case tokentype::tk_deftype:
|
||||
case tokentype::tk_if:
|
||||
case tokentype::tk_then:
|
||||
case tokentype::tk_else:
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
#include "DToplevelSeqSsm.hpp"
|
||||
#include "ssm/ISyntaxStateMachine_DToplevelSeqSsm.hpp"
|
||||
#include "DDefineSsm.hpp"
|
||||
#include "DDeftypeSsm.hpp"
|
||||
#include "DLambdaSsm.hpp"
|
||||
#include "ProgressSsm.hpp"
|
||||
#include "DIfElseSsm.hpp"
|
||||
|
|
@ -15,20 +16,10 @@
|
|||
#include "VarRef.hpp"
|
||||
|
||||
#include <xo/expression2/Constant.hpp>
|
||||
//#include <xo/expression2/detail/IExpression_DConstant.hpp>
|
||||
|
||||
#include <xo/stringtable2/String.hpp>
|
||||
//#include <xo/object2/string/IGCObject_DString.hpp>
|
||||
|
||||
#include <xo/object2/Float.hpp>
|
||||
//#include <xo/object2/number/IGCObject_DFloat.hpp>
|
||||
|
||||
#include <xo/object2/Integer.hpp>
|
||||
//#include <xo/object2/number/IGCObject_DInteger.hpp>
|
||||
|
||||
#include <xo/object2/Boolean.hpp>
|
||||
//#include <xo/object2/boolean/IGCObject_DBoolean.hpp>
|
||||
|
||||
#include <xo/alloc2/GCObject.hpp>
|
||||
|
||||
namespace xo {
|
||||
|
|
@ -133,6 +124,10 @@ namespace xo {
|
|||
this->on_def_token(tk, p_psm);
|
||||
return;
|
||||
|
||||
case tokentype::tk_deftype:
|
||||
this->on_deftype_token(tk, p_psm);
|
||||
return;
|
||||
|
||||
case tokentype::tk_lambda:
|
||||
this->on_lambda_token(tk, p_psm);
|
||||
return;
|
||||
|
|
@ -255,6 +250,17 @@ namespace xo {
|
|||
*/
|
||||
}
|
||||
|
||||
void
|
||||
DToplevelSeqSsm::on_deftype_token(const Token & tk,
|
||||
ParserStateMachine * p_psm)
|
||||
{
|
||||
(void)tk;
|
||||
|
||||
DDeftypeSsm::start(p_psm->parser_alloc(),
|
||||
p_psm);
|
||||
p_psm->on_token(Token::deftype_token());
|
||||
}
|
||||
|
||||
void
|
||||
DToplevelSeqSsm::on_lambda_token(const Token & tk,
|
||||
ParserStateMachine * p_psm)
|
||||
|
|
@ -462,8 +468,8 @@ namespace xo {
|
|||
|
||||
void
|
||||
DToplevelSeqSsm::on_parsed_expression_with_token(obj<AExpression> expr,
|
||||
const Token & tk,
|
||||
ParserStateMachine * p_psm)
|
||||
const Token & tk,
|
||||
ParserStateMachine * p_psm)
|
||||
{
|
||||
if (tk.tk_type() == tokentype::tk_semicolon) {
|
||||
p_psm->capture_result("DToplevelSeqSsm::on_parsed_expression_with_token", expr);
|
||||
|
|
|
|||
28
src/reader2/IPrintable_DDeftypeSsm.cpp
Normal file
28
src/reader2/IPrintable_DDeftypeSsm.cpp
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/** @file IPrintable_DDeftypeSsm.cpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IPrintable_DDeftypeSsm.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_any.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/IPrintable_DDeftypeSsm.json5]
|
||||
**/
|
||||
|
||||
#include "ssm/IPrintable_DDeftypeSsm.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
auto
|
||||
IPrintable_DDeftypeSsm::pretty(const DDeftypeSsm & self, const ppindentinfo & ppii) -> bool
|
||||
{
|
||||
return self.pretty(ppii);
|
||||
}
|
||||
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end IPrintable_DDeftypeSsm.cpp */
|
||||
84
src/reader2/ISyntaxStateMachine_DDeftypeSsm.cpp
Normal file
84
src/reader2/ISyntaxStateMachine_DDeftypeSsm.cpp
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
/** @file ISyntaxStateMachine_DDeftypeSsm.cpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/ISyntaxStateMachine_DDeftypeSsm.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_any.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/ISyntaxStateMachine_DDeftypeSsm.json5]
|
||||
**/
|
||||
|
||||
#include "ssm/ISyntaxStateMachine_DDeftypeSsm.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
auto
|
||||
ISyntaxStateMachine_DDeftypeSsm::ssm_type(const DDeftypeSsm & self) noexcept -> syntaxstatetype
|
||||
{
|
||||
return self.ssm_type();
|
||||
}
|
||||
|
||||
auto
|
||||
ISyntaxStateMachine_DDeftypeSsm::get_expect_str(const DDeftypeSsm & self) noexcept -> std::string_view
|
||||
{
|
||||
return self.get_expect_str();
|
||||
}
|
||||
|
||||
auto
|
||||
ISyntaxStateMachine_DDeftypeSsm::on_token(DDeftypeSsm & self, const Token & tk, ParserStateMachine * p_psm) -> void
|
||||
{
|
||||
self.on_token(tk, p_psm);
|
||||
}
|
||||
auto
|
||||
ISyntaxStateMachine_DDeftypeSsm::on_parsed_symbol(DDeftypeSsm & self, std::string_view sym, ParserStateMachine * p_psm) -> void
|
||||
{
|
||||
self.on_parsed_symbol(sym, p_psm);
|
||||
}
|
||||
auto
|
||||
ISyntaxStateMachine_DDeftypeSsm::on_parsed_typedescr(DDeftypeSsm & self, TypeDescr td, ParserStateMachine * p_psm) -> void
|
||||
{
|
||||
self.on_parsed_typedescr(td, p_psm);
|
||||
}
|
||||
auto
|
||||
ISyntaxStateMachine_DDeftypeSsm::on_parsed_type(DDeftypeSsm & self, obj<AType> type, ParserStateMachine * p_psm) -> void
|
||||
{
|
||||
self.on_parsed_type(type, p_psm);
|
||||
}
|
||||
auto
|
||||
ISyntaxStateMachine_DDeftypeSsm::on_parsed_formal(DDeftypeSsm & self, const DUniqueString * param_name, TypeDescr param_type, ParserStateMachine * p_psm) -> void
|
||||
{
|
||||
self.on_parsed_formal(param_name, param_type, p_psm);
|
||||
}
|
||||
auto
|
||||
ISyntaxStateMachine_DDeftypeSsm::on_parsed_formal_with_token(DDeftypeSsm & self, const DUniqueString * param_name, TypeDescr param_type, const Token & tk, ParserStateMachine * p_psm) -> void
|
||||
{
|
||||
self.on_parsed_formal_with_token(param_name, param_type, tk, p_psm);
|
||||
}
|
||||
auto
|
||||
ISyntaxStateMachine_DDeftypeSsm::on_parsed_formal_arglist(DDeftypeSsm & self, DArray * arglist, ParserStateMachine * p_psm) -> void
|
||||
{
|
||||
self.on_parsed_formal_arglist(arglist, p_psm);
|
||||
}
|
||||
auto
|
||||
ISyntaxStateMachine_DDeftypeSsm::on_parsed_expression(DDeftypeSsm & self, obj<AExpression> expr, ParserStateMachine * p_psm) -> void
|
||||
{
|
||||
self.on_parsed_expression(expr, p_psm);
|
||||
}
|
||||
auto
|
||||
ISyntaxStateMachine_DDeftypeSsm::on_parsed_expression_with_token(DDeftypeSsm & self, obj<AExpression> expr, const Token & tk, ParserStateMachine * p_psm) -> void
|
||||
{
|
||||
self.on_parsed_expression_with_token(expr, tk, p_psm);
|
||||
}
|
||||
auto
|
||||
ISyntaxStateMachine_DDeftypeSsm::on_quoted_literal(DDeftypeSsm & self, obj<AGCObject> lit, ParserStateMachine * p_psm) -> void
|
||||
{
|
||||
self.on_quoted_literal(lit, p_psm);
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end ISyntaxStateMachine_DDeftypeSsm.cpp */
|
||||
|
|
@ -25,7 +25,8 @@ namespace xo {
|
|||
|
||||
namespace scm {
|
||||
ParserStateMachine::ParserStateMachine(const ArenaConfig & config,
|
||||
const ArenaHashMapConfig & symtab_config,
|
||||
const ArenaHashMapConfig & symtab_var_config,
|
||||
const ArenaHashMapConfig & symtab_type_config,
|
||||
size_type max_stringtable_capacity,
|
||||
obj<AAllocator> expr_alloc,
|
||||
obj<AAllocator> aux_alloc)
|
||||
|
|
@ -33,7 +34,9 @@ namespace xo {
|
|||
parser_alloc_{DArena::map(config)},
|
||||
expr_alloc_{expr_alloc},
|
||||
aux_alloc_{aux_alloc},
|
||||
global_symtab_{DGlobalSymtab::make(expr_alloc, aux_alloc, symtab_config)},
|
||||
global_symtab_{DGlobalSymtab::make(expr_alloc, aux_alloc,
|
||||
symtab_var_config,
|
||||
symtab_type_config)},
|
||||
debug_flag_{config.debug_flag_}
|
||||
{
|
||||
}
|
||||
|
|
@ -275,6 +278,16 @@ namespace xo {
|
|||
this->stack_->top().on_parsed_typedescr(td, this);
|
||||
}
|
||||
|
||||
void
|
||||
ParserStateMachine::on_parsed_type(obj<AType> type)
|
||||
{
|
||||
scope log(XO_DEBUG(debug_flag_));
|
||||
|
||||
assert(stack_);
|
||||
|
||||
this->stack_->top().on_parsed_type(type, this);
|
||||
}
|
||||
|
||||
void
|
||||
ParserStateMachine::on_parsed_formal(const DUniqueString * sym,
|
||||
TypeDescr td)
|
||||
|
|
|
|||
|
|
@ -23,11 +23,14 @@ namespace xo {
|
|||
SchematikaParser::SchematikaParser(const ParserConfig & cfg,
|
||||
obj<AAllocator> expr_alloc,
|
||||
obj<AAllocator> aux_alloc)
|
||||
: psm_{cfg.parser_arena_config_,
|
||||
cfg.symtab_config_,
|
||||
cfg.max_stringtable_capacity_,
|
||||
expr_alloc,
|
||||
aux_alloc},
|
||||
: psm_{
|
||||
cfg.parser_arena_config_,
|
||||
cfg.symtab_var_config_,
|
||||
cfg.symtab_types_config_,
|
||||
cfg.max_stringtable_capacity_,
|
||||
expr_alloc,
|
||||
aux_alloc
|
||||
},
|
||||
debug_flag_{cfg.debug_flag_}
|
||||
{
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,8 @@ namespace xo {
|
|||
: tokenizer_{config.tk_buffer_config_,
|
||||
config.tk_debug_flag_},
|
||||
parser_{ParserConfig(config.parser_arena_config_,
|
||||
config.symtab_config_,
|
||||
config.symtab_var_config_,
|
||||
config.symtab_types_config_,
|
||||
config.max_stringtable_cap_,
|
||||
config.parser_debug_flag_),
|
||||
expr_alloc,
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
#include "SchematikaParser.hpp"
|
||||
#include "ToplevelSeqSsm.hpp"
|
||||
#include "DefineSsm.hpp"
|
||||
#include "DeftypeSsm.hpp"
|
||||
#include "LambdaSsm.hpp"
|
||||
#include "IfElseSsm.hpp"
|
||||
#include "ApplySsm.hpp"
|
||||
|
|
@ -47,6 +48,9 @@ namespace xo {
|
|||
FacetRegistry::register_impl<ASyntaxStateMachine, DDefineSsm>();
|
||||
FacetRegistry::register_impl<APrintable, DDefineSsm>();
|
||||
|
||||
FacetRegistry::register_impl<ASyntaxStateMachine, DDeftypeSsm>();
|
||||
FacetRegistry::register_impl<APrintable, DDeftypeSsm>();
|
||||
|
||||
FacetRegistry::register_impl<ASyntaxStateMachine, DLambdaSsm>();
|
||||
FacetRegistry::register_impl<APrintable, DLambdaSsm>();
|
||||
|
||||
|
|
@ -98,6 +102,7 @@ namespace xo {
|
|||
|
||||
log && log(xtag("DToplevelSeqSsm.tseq", typeseq::id<DToplevelSeqSsm>()));
|
||||
log && log(xtag("DDefineSsm.tseq", typeseq::id<DDefineSsm>()));
|
||||
log && log(xtag("DDeftypeSsm.tseq", typeseq::id<DDeftypeSsm>()));
|
||||
log && log(xtag("DLambdaSsm.tseq", typeseq::id<DLambdaSsm>()));
|
||||
log && log(xtag("DIfElseSsm.tseq", typeseq::id<DIfElseSsm>()));
|
||||
log && log(xtag("DExpectFormalArglistSsm.tseq", typeseq::id<DExpectFormalArglistSsm>()));
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@ namespace xo {
|
|||
break;
|
||||
case syntaxstatetype::defexpr:
|
||||
return "defexpr";
|
||||
case syntaxstatetype::deftypeexpr:
|
||||
return "deftypeexpr";
|
||||
case syntaxstatetype::lambdaexpr:
|
||||
return "lambdaexpr";
|
||||
case syntaxstatetype::ifelseexpr:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue