xo-reader2: + ExpectSymbolSsm + SyntaxStateMachine.on_parsed_symbol
This commit is contained in:
parent
e252a9f4e7
commit
83ef04c250
28 changed files with 537 additions and 52 deletions
91
xo-reader2/include/xo/reader2/DExpectSymbolSsm.hpp
Normal file
91
xo-reader2/include/xo/reader2/DExpectSymbolSsm.hpp
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
/* file DExpectSymbolSsm.hpp
|
||||
*
|
||||
* author: Roland Conybeare, Aug 2024
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ParserStateMachine.hpp"
|
||||
//#include "SyntaxStateMachine.hpp"
|
||||
#include "syntaxstatetype.hpp"
|
||||
#include <xo/facet/obj.hpp>
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
/** @class DExpectSymbolSsm
|
||||
* @brief state machine to expect + capture a symbol
|
||||
*
|
||||
* For example:
|
||||
* - lhs in a define-expression
|
||||
**/
|
||||
class DExpectSymbolSsm {
|
||||
public:
|
||||
using DArena = xo::mm::DArena;
|
||||
|
||||
public:
|
||||
DExpectSymbolSsm();
|
||||
|
||||
/** create instance using memory from @p parser_mm **/
|
||||
static DExpectSymbolSsm * make(DArena & parser_mm);
|
||||
|
||||
/** start nested parser expecting a symbol,
|
||||
* on top of parser state machine @p p_psm.
|
||||
* On success will deliver symbol by invoking
|
||||
* .on_symbol(sym, p_psm)
|
||||
* to the state machine on top of the stack
|
||||
* as of when this start() method invoked
|
||||
**/
|
||||
static void start(DArena & parser_mm,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
/** update state for this syntax on incoming token @p tk,
|
||||
* with overall parser state in @p p_psm
|
||||
**/
|
||||
static void on_symbol_token(const Token & tk,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
/** @defgroup scm-expectsymbol-ssm-facet syntaxstatemachine facet methods **/
|
||||
///@{
|
||||
|
||||
/** identifies the ssm implemented here **/
|
||||
syntaxstatetype ssm_type() const noexcept;
|
||||
|
||||
/** text describing expected/allowed input to this ssm in current state.
|
||||
* Intended to drive error mesages
|
||||
**/
|
||||
std::string_view get_expect_str() const noexcept;
|
||||
|
||||
/** update state for this syntax on incoming token @p tk,
|
||||
* overall parser state in @p p_psm
|
||||
**/
|
||||
void on_def_token(const Token & tk,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
/** update state for this syntax on incoming token @p tk,
|
||||
* overall parser state in @p p_psm
|
||||
**/
|
||||
void on_if_token(const Token & tk,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
/** update state for this syntax after parsing a symbol @p sym;
|
||||
* overall parser state in @p p_psm.
|
||||
*
|
||||
* NOTE:
|
||||
* might not be obvious that this is unreachable.
|
||||
* DExpectSymbolSsm converts a symbol token,
|
||||
* and delivers it to parent ssm using this entry point.
|
||||
* This method would only be called if consecutive
|
||||
* DExpectSymbolSsm instances on parser stack;
|
||||
* which scenario never occurs in Schematika syntax
|
||||
**/
|
||||
void on_parsed_symbol(std::string_view sym,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
|
||||
///@}
|
||||
|
||||
};
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end DExpectSymbolSsm.hpp */
|
||||
Loading…
Add table
Add a link
Reference in a new issue