xo-interpreter2 stack: parse literal lists (w/ implicit types)

This commit is contained in:
Roland Conybeare 2026-03-02 23:21:10 +11:00
commit f2a9aa3f52
19 changed files with 1052 additions and 99 deletions

View file

@ -4,6 +4,7 @@
*/
#include "ExpectQLiteralSsm.hpp"
#include "ExpectQListSsm.hpp"
#include <xo/object2/Float.hpp>
//#include "DExpectFormalArgSsm.hpp"
//#include "ssm/ISyntaxStateMachine_DExpectFormalArgSsm.hpp"
@ -24,31 +25,13 @@ namespace xo {
// using xo::reflect::typeseq;
namespace scm {
#ifdef NOT_USING
const char *
formalarglstatetype_descr(formalarglstatetype x) {
switch (x) {
case formalarglstatetype::invalid:
return "invalid";
case formalarglstatetype::argl_0:
return "argl_0";
case formalarglstatetype::argl_1a:
return "argl_1a";
case formalarglstatetype::argl_1b:
return "argl_1b";
case formalarglstatetype::n_formalarglstatetype:
break;
}
return "?formalarglstatetype";
}
#endif
DExpectQLiteralSsm::DExpectQLiteralSsm()
DExpectQLiteralSsm::DExpectQLiteralSsm(bool cxl_on_rightparen)
: cxl_on_rightparen_{cxl_on_rightparen}
{}
DExpectQLiteralSsm *
DExpectQLiteralSsm::_make(DArena & arena)
DExpectQLiteralSsm::_make(DArena & arena,
bool cxl_on_rightparen)
{
/* out-of-order so argl follows ssm in arena,
* consistent with any subsequent arglist realloc.
@ -57,23 +40,26 @@ namespace xo {
void * mem = arena.alloc_for<DExpectQLiteralSsm>();
return new (mem) DExpectQLiteralSsm();
return new (mem) DExpectQLiteralSsm(cxl_on_rightparen);
}
obj<ASyntaxStateMachine,DExpectQLiteralSsm>
DExpectQLiteralSsm::make(DArena & arena)
DExpectQLiteralSsm::make(DArena & arena,
bool cxl_on_rightparen)
{
obj<ASyntaxStateMachine,DExpectQLiteralSsm> retval(_make(arena));
obj<ASyntaxStateMachine,DExpectQLiteralSsm> retval(_make(arena,
cxl_on_rightparen));
return retval;
}
void
DExpectQLiteralSsm::start(ParserStateMachine * p_psm)
DExpectQLiteralSsm::start(ParserStateMachine * p_psm,
bool cxl_on_rightparen)
{
DArena::Checkpoint ckp = p_psm->parser_alloc().checkpoint();
p_psm->push_ssm(ckp, DExpectQLiteralSsm::make(p_psm->parser_alloc()));
p_psm->push_ssm(ckp, DExpectQLiteralSsm::make(p_psm->parser_alloc(),
cxl_on_rightparen));
}
syntaxstatetype
@ -97,8 +83,14 @@ namespace xo {
return;
case tokentype::tk_leftparen:
case tokentype::tk_comma:
this->on_leftparen_token(tk, p_psm);
return;
case tokentype::tk_rightparen:
this->on_rightparen_token(tk, p_psm);
return;
case tokentype::tk_comma:
case tokentype::tk_lambda:
case tokentype::tk_def:
case tokentype::tk_if:
@ -197,21 +189,18 @@ namespace xo {
}
#endif
#ifdef NOT_YET
void
DExpectQLiteralSsm::on_leftparen_token(const Token & tk,
ParserStateMachine * p_psm)
ParserStateMachine * p_psm)
{
if (fastate_ == formalarglstatetype::argl_0) {
this->fastate_ = formalarglstatetype::argl_1a;
// replace self with specialized version for parsing a literal list
DExpectFormalArgSsm::start(p_psm);
return;
}
Super::on_token(tk, p_psm);
p_psm->pop_ssm();
DExpectQListSsm::start(p_psm);
p_psm->on_token(tk);
}
#ifdef NOT_YET
void
DExpectQLiteralSsm::on_comma_token(const Token & tk,
ParserStateMachine * p_psm)
@ -225,22 +214,20 @@ namespace xo {
Super::on_token(tk, p_psm);
}
#endif
void
DExpectQLiteralSsm::on_rightparen_token(const Token & tk,
ParserStateMachine * p_psm)
ParserStateMachine * p_psm)
{
if (fastate_ == formalarglstatetype::argl_1b) {
DArray * args = argl_;
if (cxl_on_rightparen_) {
p_psm->pop_ssm();
p_psm->on_parsed_formal_arglist(args);
p_psm->on_token(tk);
return;
}
Super::on_token(tk, p_psm);
}
#endif
bool
DExpectQLiteralSsm::pretty(const ppindentinfo & ppii) const