xo-reader2: accept parsed expression at top level..

This commit is contained in:
Roland Conybeare 2026-01-22 17:41:40 -05:00
commit 15e1e50659
5 changed files with 33 additions and 8 deletions

View file

@ -41,6 +41,12 @@ namespace xo {
std::string_view error_src_fn, std::string_view error_src_fn,
const DString * error_description); const DString * error_description);
/** create ParserResult for parsing success;
* parsing yields expression @p expr
**/
static ParserResult expression(std::string_view ssm,
obj<AExpression> expr);
/** create ParserResult for a parsing error. /** create ParserResult for a parsing error.
* Reporting detailed message @p errmsg * Reporting detailed message @p errmsg
* from syntax state machine @p ssm * from syntax state machine @p ssm

View file

@ -148,6 +148,10 @@ namespace xo {
/** @defgroup scm-parserstatemachine-error-entrypoints error entry points **/ /** @defgroup scm-parserstatemachine-error-entrypoints error entry points **/
///@{ ///@{
/** capture result expression @p expr **/
void capture_result(std::string_view ssm_anme,
obj<AExpression> expr);
/** capture error message @p errmsg from @p ssm_name, /** capture error message @p errmsg from @p ssm_name,
* as current state machine output. * as current state machine output.
* *

View file

@ -218,18 +218,16 @@ namespace xo {
DExprSeqState::on_parsed_expression(obj<AExpression> expr, DExprSeqState::on_parsed_expression(obj<AExpression> expr,
ParserStateMachine * p_psm) ParserStateMachine * p_psm)
{ {
p_psm->illegal_parsed_expression("DExprSeqState::on_parsed_expression", // toplevel expr sequence accepts an arbitrary number of expressions.
expr,
this->get_expect_str()); p_psm->capture_result("DExprSeqState::on_parsed_expression", expr);
} }
void void
DExprSeqState::on_parsed_expression_with_semicolon(obj<AExpression> expr, DExprSeqState::on_parsed_expression_with_semicolon(obj<AExpression> expr,
ParserStateMachine * p_psm) ParserStateMachine * p_psm)
{ {
p_psm->illegal_parsed_expression("DExprSeqState::on_parsed_expression_with_semicolon", p_psm->capture_result("DExprSeqState::on_parsed_expression_with_semicolon", expr);
expr,
this->get_expect_str());
} }
bool bool

View file

@ -36,6 +36,16 @@ namespace xo {
error_description_{error_description} error_description_{error_description}
{} {}
ParserResult
ParserResult::expression(std::string_view ssm_name,
obj<AExpression> expr)
{
return ParserResult(parser_result_type::expression,
expr,
ssm_name,
nullptr);
}
ParserResult ParserResult
ParserResult::error(std::string_view ssm_name, ParserResult::error(std::string_view ssm_name,
const DString * errmsg) const DString * errmsg)

View file

@ -288,6 +288,13 @@ namespace xo {
stack_->top().on_semicolon_token(tk, this); stack_->top().on_semicolon_token(tk, this);
} }
void
ParserStateMachine::capture_result(std::string_view ssm_name,
obj<AExpression> expr)
{
this->result_ = ParserResult::expression(ssm_name, expr);
}
void void
ParserStateMachine::capture_error(std::string_view ssm_name, ParserStateMachine::capture_error(std::string_view ssm_name,
const DString * errmsg) const DString * errmsg)
@ -321,7 +328,7 @@ namespace xo {
void void
ParserStateMachine::illegal_input_on_symbol(std::string_view ssm_name, ParserStateMachine::illegal_input_on_symbol(std::string_view ssm_name,
std::string_view sym, std::string_view sym,
std::string_view expect_str) std::string_view expect_str)
{ {
// TODO: // TODO:
// - want to write error message using DArena // - want to write error message using DArena