xo-interpreter2: + nil + cons

This commit is contained in:
Roland Conybeare 2026-03-11 16:19:40 -05:00
commit cc42c98928
22 changed files with 148 additions and 5 deletions

View file

@ -84,12 +84,18 @@ namespace xo {
void on_quote_token(const Token & tk,
ParserStateMachine * p_psm);
/** step state machine for this syntax on incoming boolean literal token @p tkk
/** step state machine for this syntax on incoming boolean literal token @p tk
* with overall parser state in @p p_psm
**/
void on_bool_token(const Token & tk,
ParserStateMachine * p_psm);
/** step state machine for this syntax on incoming nil literal token @p tk
* with overall parser state in @p p_psm.
**/
void on_nil_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
**/

View file

@ -119,6 +119,11 @@ namespace xo {
**/
void on_bool_token(const Token & tk, ParserStateMachine * p_psm);
/** update state for this syntax on incoming nil token @p tk,
* overall parser state in @p p_psm
**/
void on_nil_token(const Token & tk, ParserStateMachine * p_psm);
/** update state for this syntax on incoming leftparen token @p tk,
* overall parser state in @p p_psm
**/

View file

@ -171,6 +171,7 @@ namespace xo {
case tokentype::tk_slash:
case tokentype::tk_cmpeq:
case tokentype::tk_cmpne:
case tokentype::tk_nil:
case tokentype::tk_type:
case tokentype::tk_lambda:
case tokentype::tk_let:

View file

@ -546,6 +546,7 @@ namespace xo {
case tokentype::tk_slash:
case tokentype::tk_cmpeq:
case tokentype::tk_cmpne:
case tokentype::tk_nil:
case tokentype::tk_type:
case tokentype::tk_lambda:
case tokentype::tk_then:

View file

@ -150,6 +150,7 @@ namespace xo {
case tokentype::tk_slash:
case tokentype::tk_cmpeq:
case tokentype::tk_cmpne:
case tokentype::tk_nil:
case tokentype::tk_type:
case tokentype::tk_lambda:
case tokentype::tk_then:

View file

@ -18,6 +18,7 @@
#include <xo/object2/Boolean.hpp>
#include <xo/object2/Integer.hpp>
#include <xo/object2/Float.hpp>
#include <xo/object2/List.hpp>
#include <xo/stringtable2/String.hpp>
#include <xo/alloc2/GCObject.hpp>
#include <xo/facet/facet_implementation.hpp>
@ -155,6 +156,10 @@ namespace xo {
this->on_bool_token(tk, p_psm);
return;
case tokentype::tk_nil:
this->on_nil_token(tk, p_psm);
return;
case tokentype::tk_if:
this->on_if_token(tk, p_psm);
return;
@ -372,6 +377,23 @@ namespace xo {
p_psm);
}
void
DExpectExprSsm::on_nil_token(const Token & tk,
ParserStateMachine * p_psm)
{
(void)tk;
auto nil = DList::nil();
auto expr = DConstant::make(p_psm->expr_alloc(), nil);
// DProgressSsm responsible for resolving cases like
// nil ++ nil;
DProgressSsm::start(p_psm->parser_alloc(),
expr,
p_psm);
}
void
DExpectExprSsm::on_f64_token(const Token & tk,
ParserStateMachine * p_psm)

View file

@ -135,6 +135,7 @@ namespace xo {
case tokentype::tk_slash:
case tokentype::tk_cmpeq:
case tokentype::tk_cmpne:
case tokentype::tk_nil:
case tokentype::tk_type:
case tokentype::tk_then:
case tokentype::tk_else:

View file

@ -165,6 +165,7 @@ namespace xo {
case tokentype::tk_slash:
case tokentype::tk_cmpeq:
case tokentype::tk_cmpne:
case tokentype::tk_nil:
case tokentype::tk_type:
case tokentype::tk_then:
case tokentype::tk_else:

View file

@ -127,6 +127,7 @@ namespace xo {
case tokentype::tk_slash:
case tokentype::tk_cmpeq:
case tokentype::tk_cmpne:
case tokentype::tk_nil:
case tokentype::tk_type:
case tokentype::tk_lambda:
case tokentype::tk_then:

View file

@ -122,6 +122,7 @@ namespace xo {
case tokentype::tk_slash:
case tokentype::tk_cmpeq:
case tokentype::tk_cmpne:
case tokentype::tk_nil:
case tokentype::tk_type:
case tokentype::tk_then:
case tokentype::tk_else:

View file

@ -122,6 +122,7 @@ namespace xo {
case tokentype::tk_slash:
case tokentype::tk_cmpeq:
case tokentype::tk_cmpne:
case tokentype::tk_nil:
case tokentype::tk_type:
case tokentype::tk_then:
case tokentype::tk_else:

View file

@ -140,6 +140,7 @@ namespace xo {
case tokentype::tk_slash:
case tokentype::tk_cmpeq:
case tokentype::tk_cmpne:
case tokentype::tk_nil:
case tokentype::tk_type:
case tokentype::tk_then:
case tokentype::tk_else:

View file

@ -101,6 +101,7 @@ namespace xo {
case tokentype::tk_slash:
case tokentype::tk_cmpeq:
case tokentype::tk_cmpne:
case tokentype::tk_nil:
case tokentype::tk_type:
case tokentype::tk_lambda:
case tokentype::tk_then:

View file

@ -107,6 +107,7 @@ namespace xo {
case tokentype::tk_slash:
case tokentype::tk_cmpeq:
case tokentype::tk_cmpne:
case tokentype::tk_nil:
case tokentype::tk_type:
case tokentype::tk_lambda:
case tokentype::tk_then:

View file

@ -186,6 +186,7 @@ namespace xo {
case tokentype::tk_slash:
case tokentype::tk_cmpeq:
case tokentype::tk_cmpne:
case tokentype::tk_nil:
case tokentype::tk_type:
case tokentype::tk_lambda:
case tokentype::tk_let:

View file

@ -163,6 +163,7 @@ namespace xo {
case tokentype::tk_slash:
case tokentype::tk_cmpeq:
case tokentype::tk_cmpne:
case tokentype::tk_nil:
case tokentype::tk_type:
case tokentype::tk_then:
case tokentype::tk_else:

View file

@ -132,6 +132,7 @@ namespace xo {
case tokentype::tk_slash:
case tokentype::tk_cmpeq:
case tokentype::tk_cmpne:
case tokentype::tk_nil:
case tokentype::tk_type:
case tokentype::tk_lambda:
case tokentype::tk_then:

View file

@ -309,6 +309,7 @@ namespace xo {
this->on_operator_token(tk, p_psm);
return;
case tokentype::tk_nil:
case tokentype::tk_type:
case tokentype::tk_lambda:
break;

View file

@ -133,6 +133,7 @@ namespace xo {
case tokentype::tk_slash:
case tokentype::tk_cmpeq:
case tokentype::tk_cmpne:
case tokentype::tk_nil:
case tokentype::tk_type:
case tokentype::tk_lambda:
case tokentype::tk_then:

View file

@ -114,6 +114,7 @@ namespace xo {
case tokentype::tk_slash:
case tokentype::tk_cmpeq:
case tokentype::tk_cmpne:
case tokentype::tk_nil:
case tokentype::tk_type:
case tokentype::tk_lambda:
case tokentype::tk_let:

View file

@ -17,6 +17,7 @@
#include <xo/expression2/Constant.hpp>
#include <xo/stringtable2/String.hpp>
#include <xo/object2/List.hpp>
#include <xo/object2/Float.hpp>
#include <xo/object2/Integer.hpp>
#include <xo/object2/Boolean.hpp>
@ -152,6 +153,10 @@ namespace xo {
this->on_bool_token(tk, p_psm);
return;
case tokentype::tk_nil:
this->on_nil_token(tk, p_psm);
return;
case tokentype::tk_leftparen:
this->on_leftparen_token(tk, p_psm);
return;
@ -378,7 +383,7 @@ namespace xo {
break;
}
Super::on_token(tk, p_psm);
Super::illegal_token(tk, p_psm);
}
void
@ -404,7 +409,32 @@ namespace xo {
break;
}
Super::on_token(tk, p_psm);
Super::illegal_token(tk, p_psm);
}
void
DToplevelSeqSsm::on_nil_token(const Token & tk,
ParserStateMachine * p_psm)
{
switch (seqtype_) {
case exprseqtype::toplevel_interactive:
{
auto dvalue = DList::nil();
auto expr = DConstant::make(p_psm->expr_alloc(), dvalue);
DProgressSsm::start(p_psm->parser_alloc(),
expr,
p_psm);
return;
}
case exprseqtype::toplevel_batch:
break;
case exprseqtype::N:
assert(false);
break;
}
Super::illegal_token(tk, p_psm);
}
void
@ -431,7 +461,7 @@ namespace xo {
break;
}
Super::on_token(tk, p_psm);
Super::illegal_token(tk, p_psm);
}
void
@ -454,7 +484,7 @@ namespace xo {
break;
}
Super::on_token(tk, p_psm);
Super::illegal_token(tk, p_psm);
}
void

View file

@ -15,6 +15,7 @@
#include <xo/expression2/VarRef.hpp>
#include <xo/expression2/Constant.hpp>
#include <xo/procedure2/Primitive_gco_2_gco_gco.hpp>
#include <xo/object2/List.hpp>
#include <xo/object2/Float.hpp>
#include <xo/object2/Integer.hpp>
#include <xo/stringtable2/String.hpp>
@ -41,6 +42,7 @@ namespace xo {
using xo::scm::Token;
using xo::mm::AGCObject;
using xo::scm::DPrimitive_gco_2_gco_gco;
using xo::scm::DList;
using xo::scm::DString;
using xo::scm::DFloat;
using xo::scm::DInteger;
@ -603,6 +605,67 @@ namespace xo {
log && fixture.log_memory_layout(&log);
}
TEST_CASE("SchematikaParser-interactive-nil", "[reader2][SchematikaParser]")
{
const auto & testname = Catch::getResultCapture().getCurrentTestName();
constexpr bool c_debug_flag = false;
scope log(XO_DEBUG(c_debug_flag), xtag("test", testname));
ParserFixture fixture(testname, c_debug_flag);
auto & parser = *(fixture.parser_);
parser.begin_interactive_session();
/** Walkthrough parsing input equivalent to:
*
* nil ;
*
**/
{
auto & result = parser.on_token(Token::nil_token());
log && log("after nil token:");
log && log(xtag("parser", &parser));
log && log(xtag("result", result));
REQUIRE(parser.has_incomplete_expr() == true);
REQUIRE(!result.is_error());
REQUIRE(result.is_incomplete());
}
{
auto & result = parser.on_token(Token::semicolon_token());
log && log("after semicolon token:");
log && log(xtag("parser", &parser));
log && log(xtag("result", result));
REQUIRE(parser.has_incomplete_expr() == false);
REQUIRE(!result.is_error());
REQUIRE(result.is_expression());
REQUIRE(result.result_expr());
auto expr = obj<AExpression,DConstant>::from(result.result_expr());
REQUIRE(expr);
REQUIRE(expr->value());
auto value_list = obj<AGCObject,DList>::from(expr->value());
REQUIRE(value_list);
REQUIRE(value_list->is_empty());
}
//REQUIRE(result.is_error());
//// illegal input on token
//REQUIRE(result.error_description());
log && fixture.log_memory_layout(&log);
}
TEST_CASE("SchematikaParser-interactive-arith", "[reader2][SchematikaParser]")
{
const auto & testname = Catch::getResultCapture().getCurrentTestName();