xo-reader2: DefineSsm handles colon token after lhs var

example:  def foo : f64 = 3.14;
This commit is contained in:
Roland Conybeare 2026-01-20 22:22:45 -05:00
commit 3cca1b8255
5 changed files with 35 additions and 3 deletions

View file

@ -105,6 +105,9 @@ namespace xo {
/** operate state machine for incoming if-token @p tk **/
void on_if_token(const Token & tk);
/** operate state machine for incoming colon-token @p tk **/
void on_colon_token(const Token & tk);
///@}
/** @defgroup scm-parserstatemachine-error-entrypoints error entry points **/

View file

@ -477,7 +477,7 @@ namespace xo {
DDefineSsm::on_def_token(const Token & tk,
ParserStateMachine * p_psm)
{
if (this->defstate_ == defexprstatetype::def_0) {
if (defstate_ == defexprstatetype::def_0) {
this->defstate_ = defexprstatetype::def_1;
DExpectSymbolSsm::start(p_psm->parser_alloc(), p_psm);
@ -502,6 +502,13 @@ namespace xo {
DDefineSsm::on_colon_token(const Token & tk,
ParserStateMachine * p_psm)
{
if (defstate_ == defexprstatetype::def_2) {
this->defstate_ = defexprstatetype::def_3;
// expect_type_xs::start(p_psm);
return;
}
p_psm->illegal_input_on_token("DDefineSsm::on_colon_token",
tk,
this->get_expect_str());

View file

@ -139,6 +139,10 @@ namespace xo {
this->on_if_token(tk);
break;
case tokentype::tk_colon:
this->on_colon_token(tk);
break;
// all the not-yet handled cases
case tokentype::tk_invalid:
case tokentype::tk_bool:
@ -157,7 +161,6 @@ namespace xo {
case tokentype::tk_greatequal:
case tokentype::tk_dot:
case tokentype::tk_comma:
case tokentype::tk_colon:
case tokentype::tk_doublecolon:
case tokentype::tk_semicolon:
case tokentype::tk_singleassign:
@ -208,6 +211,14 @@ namespace xo {
stack_->top().on_if_token(tk, this);
}
void
ParserStateMachine::on_colon_token(const Token & tk)
{
scope log(XO_DEBUG(debug_flag_), xtag("tk", tk));
stack_->top().on_colon_token(tk, this);
}
void
ParserStateMachine::capture_error(std::string_view ssm_name,
const DString * errmsg)

View file

@ -112,6 +112,17 @@ namespace xo {
log && log(xtag("result", result));
}
{
auto & result = parser.on_token(Token::colon_token());
REQUIRE(parser.has_incomplete_expr() == true);
REQUIRE(result.is_incomplete());
log && log("after colon token:");
log && log(xtag("parser", &parser));
log && log(xtag("result", result));
}
// define-expressions not properly implemented
//REQUIRE(result.error_description());

View file

@ -108,7 +108,7 @@ namespace xo {
/** token representing comma @c "," **/
static Token comma() { return Token(tokentype::tk_comma); }
/** token representing colon @c ":" **/
static Token colon() { return Token(tokentype::tk_colon); }
static Token colon_token() { return Token(tokentype::tk_colon); }
/** token representing double-colo @c "::" **/
static Token doublecolon() { return Token(tokentype::tk_doublecolon); }
/** token representing semicolon @c ";" **/