xo-interpreter2 stack: work on variable references [WIP]

This commit is contained in:
Roland Conybeare 2026-02-05 10:44:11 -05:00
commit 370e52a149
21 changed files with 542 additions and 22 deletions

View file

@ -24,6 +24,9 @@ namespace xo {
static Binding global() { return Binding(s_link_global, 0); } static Binding global() { return Binding(s_link_global, 0); }
static Binding local(int32_t j_slot) { return Binding(0, j_slot); } static Binding local(int32_t j_slot) { return Binding(0, j_slot); }
bool is_null() const {
return (i_link_ == s_link_sentinel) && (j_slot_ == -1);
}
bool is_global() const { return i_link_ == s_link_global; } bool is_global() const { return i_link_ == s_link_global; }
bool is_local() const { return (i_link_ == 0) && (j_slot_ >= 0); } bool is_local() const { return (i_link_ == 0) && (j_slot_ >= 0); }

View file

@ -0,0 +1,13 @@
/** @file Variable.hpp
*
* @author Roland Conybeare, Feb 2026
**/
#pragma once
#include "DVariable.hpp"
#include "detail/IExpression_DVariable.hpp"
#include "detail/IGCObject_DVariable.hpp"
#include "detail/IPrintable_DVariable.hpp"
/* end Variable.hpp */

View file

@ -77,6 +77,20 @@ xo_add_genfacetimpl(
# ---------------------------------------------------------------- # ----------------------------------------------------------------
# note: manual target; generated code committed to git
xo_add_genfacetimpl(
TARGET xo-interpreter2-facetimpl-procedure-closure
FACET_PKG xo_procedure2
FACET Printable
REPR DClosure
INPUT idl/IProcedure_DClosure.json5
OUTPUT_HPP_DIR include/xo/interpreter2
OUTPUT_IMPL_SUBDIR detail
OUTPUT_CPP_DIR src/interpreter2
)
# ----------------------------------------------------------------
xo_add_genfacet_all(xo-interpreter2-genfacet-all) xo_add_genfacet_all(xo-interpreter2-genfacet-all)
# ---------------------------------------------------------------- # ----------------------------------------------------------------

View file

@ -0,0 +1,17 @@
{
mode: "implementation",
includes: [
"<xo/procedure2/RuntimeContext.hpp>",
"<xo/procedure2/detail/IRuntimeContext_Xfer.hpp>",
"<xo/procedure2/Procedure.hpp>",
"<xo/procedure2/detail/IProcedure_Xfer.hpp>",
],
local_types: [ ],
namespace1: "xo",
namespace2: "scm",
facet_idl: "idl/Procedure.json5",
brief: "provide AProcedure interface for DClosure",
using_doxygen: true,
repr: "DClosure",
doc: [ "implement AProcedure for DClosure" ],
}

View file

@ -0,0 +1,11 @@
/** @file Closure.hpp
*
* @author Roland Conybeare, Feb 2026
**/
#pragma once
#include "DClosure.hpp"
#include "detail/IProcedure_DClosure.hpp"
/* end Closure.hpp */

View file

@ -3,8 +3,11 @@
* @author Roland Conybeare, Feb 2026 * @author Roland Conybeare, Feb 2026
**/ **/
#pragma once
#include "LocalEnv.hpp" #include "LocalEnv.hpp"
#include <xo/expression2/LambdaExpr.hpp> #include <xo/expression2/LambdaExpr.hpp>
#include <xo/procedure2/RuntimeContext.hpp>
namespace xo { namespace xo {
namespace scm { namespace scm {
@ -15,7 +18,10 @@ namespace xo {
**/ **/
class DClosure { class DClosure {
public: public:
using ARuntimeContext = xo::scm::ARuntimeContext;
using AAllocator = xo::mm::AAllocator; using AAllocator = xo::mm::AAllocator;
using AGCObject = xo::mm::AGCObject;
using ppindentinfo = xo::print::ppindentinfo;
using size_type = std::int32_t; using size_type = std::int32_t;
public: public:
@ -29,11 +35,35 @@ namespace xo {
const DLambdaExpr * lm, const DLambdaExpr * lm,
const DLocalEnv * env); const DLocalEnv * env);
/** @defgroup scm-closure-general-methods **/
///@{
const DLambdaExpr * lambda() const noexcept { return lambda_; }
const DLocalEnv * env() const noexcept { return env_; }
///@}
/** @defgroup scm-closure-procedure-facet **/
///@{
/** for now, support just fixed-arity procedures **/ /** for now, support just fixed-arity procedures **/
bool is_nary() const noexcept { return false; } bool is_nary() const noexcept { return false; }
/** number of arguments expected by this procedure (-1 if nary) **/ /** number of arguments expected by this procedure (-1 if nary) **/
size_type n_args() const noexcept { return lambda_->n_args(); } size_type n_args() const noexcept { return lambda_->n_args(); }
obj<AGCObject> apply_nocheck(obj<ARuntimeContext> rcx, const DArray * args);
///@}
/** @defgroup scm-closure-gcobject-facet **/
///@{
///@}
/** @defgroup scm-closure-printable-facet **/
///@{
bool pretty(const ppindentinfo & ppii) const;
///@}
private: private:
/** lambda expression **/ /** lambda expression **/
const DLambdaExpr * lambda_ = nullptr; const DLambdaExpr * lambda_ = nullptr;

View file

@ -0,0 +1,67 @@
/** @file IProcedure_DClosure.hpp
*
* Generated automagically from ingredients:
* 1. code generator:
* [xo-facet/codegen/genfacet]
* arguments:
* --input [idl/IProcedure_DClosure.json5]
* 2. jinja2 template for abstract facet .hpp file:
* [iface_facet_repr.hpp.j2]
* 3. idl for facet methods
* [idl/IProcedure_DClosure.json5]
**/
#pragma once
#include "Procedure.hpp"
#include <xo/procedure2/RuntimeContext.hpp>
#include <xo/procedure2/detail/IRuntimeContext_Xfer.hpp>
#include <xo/procedure2/Procedure.hpp>
#include <xo/procedure2/detail/IProcedure_Xfer.hpp>
#include "DClosure.hpp"
namespace xo { namespace scm { class IProcedure_DClosure; } }
namespace xo {
namespace facet {
template <>
struct FacetImplementation<xo::scm::AProcedure,
xo::scm::DClosure>
{
using ImplType = xo::scm::IProcedure_Xfer
<xo::scm::DClosure,
xo::scm::IProcedure_DClosure>;
};
}
}
namespace xo {
namespace scm {
/** @class IProcedure_DClosure
**/
class IProcedure_DClosure {
public:
/** @defgroup scm-procedure-dclosure-type-traits **/
///@{
using AGCObject = xo::scm::AProcedure::AGCObject;
using Copaque = xo::scm::AProcedure::Copaque;
using Opaque = xo::scm::AProcedure::Opaque;
///@}
/** @defgroup scm-procedure-dclosure-methods **/
///@{
// const methods
/** true iff procedure takes n arguments **/
static bool is_nary(const DClosure & self) noexcept;
/** number of arguments. -1 for n-ary **/
static std::int32_t n_args(const DClosure & self) noexcept;
// non-const methods
/** invoke procedure; assume arguments satisfy type system **/
static obj<AGCObject> apply_nocheck(DClosure & self, obj<ARuntimeContext> rcx, const DArray * args);
///@}
};
} /*namespace scm*/
} /*namespace xo*/
/* end */

View file

@ -16,6 +16,8 @@ set(SELF_SRCS
IGCObject_DVsmApplyFrame.cpp IGCObject_DVsmApplyFrame.cpp
IPrintable_DVsmApplyFrame.cpp IPrintable_DVsmApplyFrame.cpp
IProcedure_DClosure.cpp
VsmInstr.cpp VsmInstr.cpp
DClosure.cpp DClosure.cpp

View file

@ -6,6 +6,8 @@
#include "DClosure.hpp" #include "DClosure.hpp"
namespace xo { namespace xo {
using xo::mm::AGCObject;
namespace scm { namespace scm {
DClosure::DClosure(const DLambdaExpr * lm, DClosure::DClosure(const DLambdaExpr * lm,
@ -23,6 +25,16 @@ namespace xo {
return new (mem) DClosure(lm, env); return new (mem) DClosure(lm, env);
} }
obj<AGCObject>
DClosure::apply_nocheck(obj<ARuntimeContext> rcx,
const DArray * args)
{
(void)rcx;
(void)args;
assert(false);
}
} /*namespace scm*/ } /*namespace scm*/
} /*namespace xo*/ } /*namespace xo*/

View file

@ -0,0 +1,39 @@
/** @file IProcedure_DClosure.cpp
*
* Generated automagically from ingredients:
* 1. code generator:
* [xo-facet/codegen/genfacet]
* arguments:
* --input [idl/IProcedure_DClosure.json5]
* 2. jinja2 template for abstract facet .hpp file:
* [iface_facet_any.hpp.j2]
* 3. idl for facet methods
* [idl/IProcedure_DClosure.json5]
**/
#include "detail/IProcedure_DClosure.hpp"
namespace xo {
namespace scm {
auto
IProcedure_DClosure::is_nary(const DClosure & self) noexcept -> bool
{
return self.is_nary();
}
auto
IProcedure_DClosure::n_args(const DClosure & self) noexcept -> std::int32_t
{
return self.n_args();
}
auto
IProcedure_DClosure::apply_nocheck(DClosure & self, obj<ARuntimeContext> rcx, const DArray * args) -> obj<AGCObject>
{
return self.apply_nocheck(rcx, args);
}
} /*namespace scm*/
} /*namespace xo*/
/* end IProcedure_DClosure.cpp */

View file

@ -8,6 +8,8 @@
#include "VsmApplyFrame.hpp" #include "VsmApplyFrame.hpp"
#include "VsmEvalArgsFrame.hpp" #include "VsmEvalArgsFrame.hpp"
#include "Closure.hpp"
#include <xo/printable2/detail/APrintable.hpp> #include <xo/printable2/detail/APrintable.hpp>
#include <xo/facet/FacetRegistry.hpp> #include <xo/facet/FacetRegistry.hpp>
#include <xo/reflectutil/typeseq.hpp> #include <xo/reflectutil/typeseq.hpp>
@ -36,8 +38,15 @@ namespace xo {
FacetRegistry::register_impl<AGCObject, DVsmEvalArgsFrame>(); FacetRegistry::register_impl<AGCObject, DVsmEvalArgsFrame>();
FacetRegistry::register_impl<APrintable, DVsmEvalArgsFrame>(); FacetRegistry::register_impl<APrintable, DVsmEvalArgsFrame>();
// Procedure
// +- Primitive_gco_2_gco_gco
// \- Closure
FacetRegistry::register_impl<AProcedure, DClosure>();
log && log(xtag("DVsmApplyFrame.tseq", typeseq::id<DVsmApplyFrame>())); log && log(xtag("DVsmApplyFrame.tseq", typeseq::id<DVsmApplyFrame>()));
log && log(xtag("DVsmEvalArgsFrame.tseq", typeseq::id<DVsmEvalArgsFrame>())); log && log(xtag("DVsmEvalArgsFrame.tseq", typeseq::id<DVsmEvalArgsFrame>()));
log && log(xtag("DClosure.tseq", typeseq::id<DClosure>()));
return true; return true;
} }

View file

@ -186,6 +186,43 @@ namespace xo {
vsm.visit_pools(visitor); vsm.visit_pools(visitor);
} }
TEST_CASE("VirtualSchematikaMachine-lambda1", "[interpreter2][VSM]")
{
scope log(XO_DEBUG(true));
VsmConfig cfg;
VirtualSchematikaMachine vsm(cfg);
bool eof_flag = false;
vsm.begin_interactive_session();
VsmResultExt res = vsm.read_eval_print(span_type::from_cstr("lambda (x : i64) -> i64 { x * x; };"), eof_flag);
REQUIRE(res.is_value());
REQUIRE(res.value());
log && log(xtag("res.tseq", res.value()->_typeseq()));
auto x = obj<AGCObject,DFloat>::from(*res.value());
REQUIRE(x);
REQUIRE(x.data()->value() == 1.570796325);
REQUIRE(res.remaining_.size() == 1);
REQUIRE(*res.remaining_.lo() == '\n');
auto visitor = [&log](const MemorySizeInfo & info) {
log && log(xtag("resource", info.resource_name_),
xtag("used", info.used_),
xtag("alloc", info.allocated_),
xtag("commit", info.committed_),
xtag("resv", info.reserved_));
};
FacetRegistry::instance().visit_pools(visitor);
vsm.visit_pools(visitor);
}
} /*namespace ut*/ } /*namespace ut*/
} /*namespace xo*/ } /*namespace xo*/

View file

@ -0,0 +1,12 @@
/** @file Boolean.hpp
*
* @author Roland Conybeare, Feb 2026
**/
#pragma once
#include "DBoolean.hpp"
#include "boolean/IGCObject_DBoolean.hpp"
#include "boolean/IPrintable_DBoolean.hpp"
/* end Boolean.hpp */

View file

@ -1,6 +1,6 @@
/** @file String.hpp /** @file String.hpp
* *
* @author Roland Conybeare, Feb 22026 * @author Roland Conybeare, Feb 2026
**/ **/
#pragma once #pragma once

View file

@ -65,4 +65,5 @@
] ]
} }
], ],
router_facet_explicit_content: [ ],
} }

View file

@ -0,0 +1,12 @@
/** @file ExpectExprSsm.hpp
*
* @author Roland Conybeare, Feb 2026
**/
#pragma once
#include "DExpectExprSsm.hpp"
#include "ssm/ISyntaxStateMachine_DExpectExprSsm.hpp"
#include "ssm/IPrintable_DExpectExprSsm.hpp"
/* end ExpectExprSsm.hpp */

View file

@ -89,6 +89,9 @@ namespace xo {
/** get unique (within stringtable) string, beginning with @p prefix **/ /** get unique (within stringtable) string, beginning with @p prefix **/
const DUniqueString * gensym(std::string_view prefix); const DUniqueString * gensym(std::string_view prefix);
/** get variable defn for @p symbolname, or else nullptr **/
Binding lookup_binding(std::string_view symbolname);
/** push nested local symtab while parsing the body of a lambda expression; /** push nested local symtab while parsing the body of a lambda expression;
* restore previous symtab at the end of lambda-expression definition. * restore previous symtab at the end of lambda-expression definition.
* See @ref pop_local_symtab * See @ref pop_local_symtab
@ -229,6 +232,11 @@ namespace xo {
obj<AExpression>, obj<AExpression>,
std::string_view expect_str); std::string_view expect_str);
/** report error - no binding for variable @p sym
**/
void error_unbound_variable(std::string_view ssm_name,
std::string_view sym);
///@} ///@}
private: private:

View file

@ -3,23 +3,18 @@
* @author Roland Conybeare, Jan 2026 * @author Roland Conybeare, Jan 2026
**/ **/
#include "DExpectExprSsm.hpp" #include "ExpectExprSsm.hpp"
#include "ParserStateMachine.hpp" #include "ParserStateMachine.hpp"
#include "SyntaxStateMachine.hpp" #include "SyntaxStateMachine.hpp"
#include "ssm/ISyntaxStateMachine_DExpectExprSsm.hpp"
#include "ssm/ISyntaxStateMachine_DProgressSsm.hpp" #include "ssm/ISyntaxStateMachine_DProgressSsm.hpp"
#include "DSequenceSsm.hpp" #include "DSequenceSsm.hpp"
#include "syntaxstatetype.hpp" #include "syntaxstatetype.hpp"
#include <xo/expression2/DConstant.hpp> #include <xo/expression2/Variable.hpp>
#include <xo/expression2/detail/IExpression_DConstant.hpp> #include <xo/expression2/Constant.hpp>
#include <xo/object2/DBoolean.hpp> #include <xo/object2/Boolean.hpp>
#include <xo/object2/boolean/IGCObject_DBoolean.hpp> #include <xo/object2/Integer.hpp>
#include <xo/object2/DInteger.hpp> #include <xo/object2/Float.hpp>
#include <xo/object2/number/IGCObject_DInteger.hpp> #include <xo/object2/String.hpp>
#include <xo/object2/DFloat.hpp>
#include <xo/object2/number/IGCObject_DFloat.hpp>
#include <xo/object2/DString.hpp>
#include <xo/object2/string/IGCObject_DString.hpp>
#include <xo/gc/GCObject.hpp> #include <xo/gc/GCObject.hpp>
#include <xo/facet/facet_implementation.hpp> #include <xo/facet/facet_implementation.hpp>
@ -196,7 +191,27 @@ namespace xo {
DExpectExprSsm::on_symbol_token(const Token & tk, DExpectExprSsm::on_symbol_token(const Token & tk,
ParserStateMachine * p_psm) ParserStateMachine * p_psm)
{ {
Super::on_token(tk, p_psm); scope log(XO_DEBUG(p_psm->debug_flag()));
log && log(xtag("tk", tk));
const DVariable * var = p_psm->lookup_variable(tk.text());
if (!var) {
p_psm->error_unbound_variable(ssm_classname(),
tk.text());
}
// examples of possible continuations from symbol foo
// foo ; // (1) foo is entire rvalue expression
// foo + ... // (2) foo begin operator expression
// foo(..); // (3) foo begin apply function
//
//
DProgressSsm::start(p_psm->parser_alloc(),
obj<AExpression,DVariable>(const_cast<DVariable *>(var)),
p_psm);
} }
#ifdef NOT_YET #ifdef NOT_YET

View file

@ -68,8 +68,7 @@ namespace xo {
obj<AAllocator> expr_mm, obj<AAllocator> expr_mm,
ParserStateMachine * p_psm) ParserStateMachine * p_psm)
{ {
constexpr bool c_debug_flag = true; scope log(XO_DEBUG(p_psm->debug_flag()));
scope log(XO_DEBUG(c_debug_flag));
DIfElseExpr * if_expr = DIfElseExpr::_make_empty(expr_mm); DIfElseExpr * if_expr = DIfElseExpr::_make_empty(expr_mm);
DIfElseSsm * if_ssm = DIfElseSsm::_make(parser_mm, if_expr); DIfElseSsm * if_ssm = DIfElseSsm::_make(parser_mm, if_expr);

View file

@ -107,6 +107,48 @@ namespace xo {
return stringtable_.gensym(str); return stringtable_.gensym(str);
} }
Binding
ParserStateMachine::lookup_binding(std::string_view symbolname)
{
scope log(XO_DEBUG(debug_flag_));
if (!local_symtab_)
return Binding::null();
const DUniqueString * ustr = stringtable_.lookup(symbolname);
if (!ustr) {
// if not in string table, then can't be a variable either
return Binding::null();
}
DLocalSymtab * symtab = local_symtab_;
// count #of nested scopes to cross, to reach symbol
//
int32_t link_count = 0;
while (symtab) {
Binding b = symtab->lookup_binding(ustr);
if (b.is_local()) {
assert(b.i_link() == 0);
return Binding(link_count, b.j_slot());
}
++link_count;
symtab = symtab->parent();
}
// TODO: check global symtab also
log.retroactively_enable();
log("STUB: check global symtab");
return Binding::null();
}
void void
ParserStateMachine::push_local_symtab(DLocalSymtab * symtab) ParserStateMachine::push_local_symtab(DLocalSymtab * symtab)
{ {
@ -400,6 +442,21 @@ namespace xo {
this->capture_error(ssm_name, errmsg); this->capture_error(ssm_name, errmsg);
} }
void
ParserStateMachine::error_unbound_variable(std::string_view ssm_name,
std::string_view sym)
{
auto errmsg_string = tostr("No binding for symbol",
xtag("symbol", sym),
xtag("ssm", ssm_name));
auto errmsg = DString::from_view(expr_alloc_,
std::string_view(errmsg_string));
this->capture_error(ssm_name, errmsg);
}
} /*namespace scm*/ } /*namespace scm*/
} /*namespace xo*/ } /*namespace xo*/

View file

@ -220,7 +220,7 @@ namespace xo {
{ {
const auto & testname = Catch::getResultCapture().getCurrentTestName(); const auto & testname = Catch::getResultCapture().getCurrentTestName();
constexpr bool c_debug_flag = true; constexpr bool c_debug_flag = false;
scope log(XO_DEBUG(c_debug_flag), xtag("test", testname)); scope log(XO_DEBUG(c_debug_flag), xtag("test", testname));
ArenaConfig config; ArenaConfig config;
@ -285,7 +285,7 @@ namespace xo {
{ {
const auto & testname = Catch::getResultCapture().getCurrentTestName(); const auto & testname = Catch::getResultCapture().getCurrentTestName();
constexpr bool c_debug_flag = true; constexpr bool c_debug_flag = false;
scope log(XO_DEBUG(c_debug_flag), xtag("test", testname)); scope log(XO_DEBUG(c_debug_flag), xtag("test", testname));
ArenaConfig config; ArenaConfig config;
@ -350,7 +350,7 @@ namespace xo {
{ {
const auto & testname = Catch::getResultCapture().getCurrentTestName(); const auto & testname = Catch::getResultCapture().getCurrentTestName();
constexpr bool c_debug_flag = true; constexpr bool c_debug_flag = false;
scope log(XO_DEBUG(c_debug_flag), xtag("test", testname)); scope log(XO_DEBUG(c_debug_flag), xtag("test", testname));
ArenaConfig config; ArenaConfig config;
@ -415,7 +415,7 @@ namespace xo {
{ {
const auto & testname = Catch::getResultCapture().getCurrentTestName(); const auto & testname = Catch::getResultCapture().getCurrentTestName();
constexpr bool c_debug_flag = true; constexpr bool c_debug_flag = false;
scope log(XO_DEBUG(c_debug_flag), xtag("test", testname)); scope log(XO_DEBUG(c_debug_flag), xtag("test", testname));
ArenaConfig config; ArenaConfig config;
@ -517,7 +517,7 @@ namespace xo {
TEST_CASE("SchematikaParser-interactive-lambda", "[reader2][SchematikaParser]") TEST_CASE("SchematikaParser-interactive-lambda", "[reader2][SchematikaParser]")
{ {
constexpr bool c_debug_flag = true; constexpr bool c_debug_flag = false;
scope log(XO_DEBUG(c_debug_flag)); scope log(XO_DEBUG(c_debug_flag));
ArenaConfig config; ArenaConfig config;
@ -725,7 +725,7 @@ namespace xo {
TEST_CASE("SchematikaParser-interactive-if", "[reader2][SchematikaParser]") TEST_CASE("SchematikaParser-interactive-if", "[reader2][SchematikaParser]")
{ {
constexpr bool c_debug_flag = true; constexpr bool c_debug_flag = false;
scope log(XO_DEBUG(c_debug_flag)); scope log(XO_DEBUG(c_debug_flag));
ArenaConfig config; ArenaConfig config;
@ -834,6 +834,168 @@ namespace xo {
//REQUIRE(result.error_description()); //REQUIRE(result.error_description());
} }
TEST_CASE("SchematikaParser-interactive-lambda2", "[reader2][SchematikaParser]")
{
constexpr bool c_debug_flag = true;
scope log(XO_DEBUG(c_debug_flag));
ArenaConfig config;
config.name_ = "test-arena";
config.size_ = 16 * 1024;
DArena expr_arena = DArena::map(config);
obj<AAllocator> expr_alloc = with_facet<AAllocator>::mkobj(&expr_arena);
SchematikaParser parser(config, 4096, expr_alloc, false /*debug_flag*/);
parser.begin_interactive_session();
/** Walkthrough parsing input equivalent to:
*
* lambda (x : i64) -> i64 { x * x };
*
**/
{
auto & result = parser.on_token(Token::lambda_token());
log && log("after lambda 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::leftparen_token());
log && log("after lparen 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::symbol_token("x"));
log && log("after symbol(n) 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::colon_token());
log && log("after colon 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::symbol_token("i64"));
log && log("after symbol(i64) 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::rightparen_token());
log && log("after rightparen 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::yields_token());
log && log("after yields 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::symbol_token("i64"));
log && log("after symbol(i64) 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::leftbrace_token());
log && log("after leftbrace 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::symbol_token("x"));
log && log("after symbol(x) 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());
}
#ifdef NOPE
{
auto & result = parser.on_token(Token::rightbrace_token());
log && log("after rightbrace 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());
}
//REQUIRE(result.is_error());
//// illegal input on token
//REQUIRE(result.error_description());
#endif
REQUIRE(false);
}
} /*namespace ut*/ } /*namespace ut*/
} /*namespace xo*/ } /*namespace xo*/