xo-reader2: DefineSsm: respond to = token
This commit is contained in:
parent
a3f5b12955
commit
c60aeda12a
8 changed files with 105 additions and 4 deletions
|
|
@ -98,6 +98,13 @@ namespace xo {
|
||||||
obj<AAllocator> expr_mm,
|
obj<AAllocator> expr_mm,
|
||||||
ParserStateMachine * p_psm);
|
ParserStateMachine * p_psm);
|
||||||
|
|
||||||
|
///@}
|
||||||
|
/** @defgroup scm-definessm-access-methods **/
|
||||||
|
///@{
|
||||||
|
|
||||||
|
/** identify define-expression state **/
|
||||||
|
defexprstatetype defstate() const noexcept { return defstate_; }
|
||||||
|
|
||||||
///@}
|
///@}
|
||||||
/** @defgroup scm-define-ssm-facet syntaxstatemachine facet methods **/
|
/** @defgroup scm-define-ssm-facet syntaxstatemachine facet methods **/
|
||||||
///@{
|
///@{
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,9 @@ namespace xo {
|
||||||
/** true iff state machine currently has incomplete expression **/
|
/** true iff state machine currently has incomplete expression **/
|
||||||
bool has_incomplete_expr() const noexcept;
|
bool has_incomplete_expr() const noexcept;
|
||||||
|
|
||||||
|
/** top of parser stack **/
|
||||||
|
obj<ASyntaxStateMachine> top_ssm() const;
|
||||||
|
|
||||||
///@}
|
///@}
|
||||||
|
|
||||||
/** @defgroup scm-parserstatemachine-bookkeeping bookkeeping methods **/
|
/** @defgroup scm-parserstatemachine-bookkeeping bookkeeping methods **/
|
||||||
|
|
|
||||||
|
|
@ -172,6 +172,9 @@ namespace xo {
|
||||||
obj<AAllocator> expr_alloc,
|
obj<AAllocator> expr_alloc,
|
||||||
bool debug_flag);
|
bool debug_flag);
|
||||||
|
|
||||||
|
/** scm-schematikaparser-access-methods **/
|
||||||
|
///@{
|
||||||
|
|
||||||
bool debug_flag() const { return debug_flag_; }
|
bool debug_flag() const { return debug_flag_; }
|
||||||
|
|
||||||
/** true if parser is at top-level,
|
/** true if parser is at top-level,
|
||||||
|
|
@ -185,6 +188,13 @@ namespace xo {
|
||||||
**/
|
**/
|
||||||
bool has_incomplete_expr() const;
|
bool has_incomplete_expr() const;
|
||||||
|
|
||||||
|
/** top of parser stack **/
|
||||||
|
obj<ASyntaxStateMachine> top_ssm() const;
|
||||||
|
|
||||||
|
///@}
|
||||||
|
/** scm-schematikaparser-general-methods **/
|
||||||
|
///@{
|
||||||
|
|
||||||
/** put parser into state for beginning an interactive session.
|
/** put parser into state for beginning an interactive session.
|
||||||
**/
|
**/
|
||||||
void begin_interactive_session();
|
void begin_interactive_session();
|
||||||
|
|
@ -215,11 +225,17 @@ namespace xo {
|
||||||
**/
|
**/
|
||||||
void reset_to_idle_toplevel();
|
void reset_to_idle_toplevel();
|
||||||
|
|
||||||
|
///@}
|
||||||
|
/** scm-schematikaparser-pretty-methods **/
|
||||||
|
///@{
|
||||||
|
|
||||||
/** print human-readable representation on stream @p os **/
|
/** print human-readable representation on stream @p os **/
|
||||||
void print(std::ostream & os) const;
|
void print(std::ostream & os) const;
|
||||||
/** pretty-printer support **/
|
/** pretty-printer support **/
|
||||||
bool pretty(const ppindentinfo & ppii) const;
|
bool pretty(const ppindentinfo & ppii) const;
|
||||||
|
|
||||||
|
///@}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/** state machine **/
|
/** state machine **/
|
||||||
ParserStateMachine psm_;
|
ParserStateMachine psm_;
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ set(SELF_SRCS
|
||||||
ParserStack.cpp
|
ParserStack.cpp
|
||||||
ParserResult.cpp
|
ParserResult.cpp
|
||||||
|
|
||||||
|
syntaxstatetype.cpp
|
||||||
ISyntaxStateMachine_Any.cpp
|
ISyntaxStateMachine_Any.cpp
|
||||||
|
|
||||||
DExprSeqState.cpp
|
DExprSeqState.cpp
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,12 @@ namespace xo {
|
||||||
return !(this->is_at_toplevel());
|
return !(this->is_at_toplevel());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
obj<ASyntaxStateMachine>
|
||||||
|
ParserStateMachine::top_ssm() const
|
||||||
|
{
|
||||||
|
return this->stack_->top();
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParserStateMachine::establish_toplevel_ssm(obj<ASyntaxStateMachine> ssm)
|
ParserStateMachine::establish_toplevel_ssm(obj<ASyntaxStateMachine> ssm)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -28,23 +28,33 @@ namespace xo {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
SchematikaParser::is_at_toplevel() const {
|
SchematikaParser::is_at_toplevel() const
|
||||||
|
{
|
||||||
return psm_.is_at_toplevel();
|
return psm_.is_at_toplevel();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
SchematikaParser::has_incomplete_expr() const {
|
SchematikaParser::has_incomplete_expr() const
|
||||||
|
{
|
||||||
return !(this->is_at_toplevel());
|
return !(this->is_at_toplevel());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
obj<ASyntaxStateMachine>
|
||||||
|
SchematikaParser::top_ssm() const
|
||||||
|
{
|
||||||
|
return psm_.top_ssm();
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
SchematikaParser::begin_interactive_session() {
|
SchematikaParser::begin_interactive_session()
|
||||||
|
{
|
||||||
DExprSeqState::establish_interactive(psm_.expr_alloc(), &psm_);
|
DExprSeqState::establish_interactive(psm_.expr_alloc(), &psm_);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
SchematikaParser::begin_batch_session() {
|
SchematikaParser::begin_batch_session()
|
||||||
|
{
|
||||||
DExprSeqState::establish_batch(psm_.expr_alloc(), &psm_);
|
DExprSeqState::establish_batch(psm_.expr_alloc(), &psm_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
34
src/reader2/syntaxstatetype.cpp
Normal file
34
src/reader2/syntaxstatetype.cpp
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
/** @file syntaxstatetype.cpp
|
||||||
|
*
|
||||||
|
* @author Roland Conybeare, Jan 2026
|
||||||
|
**/
|
||||||
|
|
||||||
|
#include "syntaxstatetype.hpp"
|
||||||
|
|
||||||
|
namespace xo {
|
||||||
|
namespace scm {
|
||||||
|
|
||||||
|
const char *
|
||||||
|
syntaxstatetype_descr(syntaxstatetype x) {
|
||||||
|
switch (x) {
|
||||||
|
case syntaxstatetype::invalid:
|
||||||
|
break;
|
||||||
|
case syntaxstatetype::expect_toplevel_expression_sequence:
|
||||||
|
return "expect-toplevel-expression-sequence";
|
||||||
|
case syntaxstatetype::expect_symbol:
|
||||||
|
return "expect-symbol";
|
||||||
|
case syntaxstatetype::expect_type:
|
||||||
|
return "expect-type";
|
||||||
|
case syntaxstatetype::defexpr:
|
||||||
|
return "defexpr";
|
||||||
|
case syntaxstatetype::N:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return "syntaxstatetype?";
|
||||||
|
}
|
||||||
|
|
||||||
|
} /*namespace scm*/
|
||||||
|
} /*namespace xo*/
|
||||||
|
|
||||||
|
/* end syntaxstatetype.cpp */
|
||||||
|
|
@ -4,12 +4,18 @@
|
||||||
**/
|
**/
|
||||||
|
|
||||||
#include <xo/reader2/SchematikaParser.hpp>
|
#include <xo/reader2/SchematikaParser.hpp>
|
||||||
|
#include <xo/reader2/DDefineSsm.hpp>
|
||||||
|
#include <xo/reader2/ssm/ISyntaxStateMachine_DDefineSsm.hpp>
|
||||||
#include <xo/reader2/init_reader2.hpp>
|
#include <xo/reader2/init_reader2.hpp>
|
||||||
#include <xo/alloc2/arena/IAllocator_DArena.hpp>
|
#include <xo/alloc2/arena/IAllocator_DArena.hpp>
|
||||||
#include <catch2/catch.hpp>
|
#include <catch2/catch.hpp>
|
||||||
|
|
||||||
namespace xo {
|
namespace xo {
|
||||||
using xo::scm::SchematikaParser;
|
using xo::scm::SchematikaParser;
|
||||||
|
using xo::scm::ASyntaxStateMachine;
|
||||||
|
using xo::scm::syntaxstatetype;
|
||||||
|
using xo::scm::DDefineSsm;
|
||||||
|
using xo::scm::defexprstatetype;
|
||||||
using xo::scm::ParserResult;
|
using xo::scm::ParserResult;
|
||||||
using xo::scm::parser_result_type;
|
using xo::scm::parser_result_type;
|
||||||
using xo::scm::Token;
|
using xo::scm::Token;
|
||||||
|
|
@ -134,6 +140,24 @@ namespace xo {
|
||||||
log && log(xtag("result", result));
|
log && log(xtag("result", result));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
auto & result = parser.on_token(Token::singleassign_token());
|
||||||
|
|
||||||
|
REQUIRE(parser.has_incomplete_expr() == true);
|
||||||
|
REQUIRE(result.is_incomplete());
|
||||||
|
|
||||||
|
log && log("after typename symbol token:");
|
||||||
|
log && log(xtag("parser", &parser));
|
||||||
|
log && log(xtag("result", result));
|
||||||
|
|
||||||
|
auto def_ssm
|
||||||
|
= obj<ASyntaxStateMachine,DDefineSsm>::from(parser.top_ssm());
|
||||||
|
|
||||||
|
REQUIRE(def_ssm);
|
||||||
|
REQUIRE(def_ssm.data()->ssm_type() == syntaxstatetype::defexpr);
|
||||||
|
REQUIRE(def_ssm.data()->defstate() == defexprstatetype::def_5);
|
||||||
|
}
|
||||||
|
|
||||||
// define-expressions not properly implemented
|
// define-expressions not properly implemented
|
||||||
|
|
||||||
//REQUIRE(result.error_description());
|
//REQUIRE(result.error_description());
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue