xo-reader2: support 0-argument apply-expressions
This commit is contained in:
parent
c221a31efe
commit
6795c1bc15
7 changed files with 138 additions and 77 deletions
|
|
@ -30,12 +30,13 @@ namespace xo {
|
|||
* apply_0 --on_expr()--> apply_1
|
||||
* apply_1 --on_leftparen()--> apply_2
|
||||
* apply_2 --on_expr()--> apply_3
|
||||
* --on_rightparen()--> (done)
|
||||
* apply_3 --on_comma()--> apply_2
|
||||
* --on_rightparen()-> (done)
|
||||
* --on_rightparen()--> (done)
|
||||
*
|
||||
* apply_0: start
|
||||
* apply_1: leftparen following expr allows parser to recognize apply
|
||||
* apply_2: expect next argument
|
||||
* apply_2: expect next argument, or rightparent to continue
|
||||
* apply_3: got argument, expect comma or rightparen to continue
|
||||
* (done): apply complete, pop exprstate from stack
|
||||
*
|
||||
|
|
@ -129,6 +130,15 @@ namespace xo {
|
|||
void on_leftparen_token(const Token & tk,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
/** handle rightparen token @p tk for this ssm,
|
||||
* with overall parser state in @p p_psm.
|
||||
*
|
||||
* Rightparen will complete apply-expression,
|
||||
* terminating this syntax.
|
||||
**/
|
||||
void on_rightparen_token(const Token & tk,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
///@}
|
||||
/** @defgroup ssm-applyssm-facet syntaxstatemachine facet methods **/
|
||||
///@{
|
||||
|
|
@ -177,9 +187,14 @@ namespace xo {
|
|||
///@}
|
||||
|
||||
private:
|
||||
/** @defgroup ssm-applyssm-mpl-methods **/
|
||||
/** @defgroup ssm-applyssm-impl-methods **/
|
||||
///@{
|
||||
|
||||
/** create final apply-expression for this syntax,
|
||||
* using @p mm for memory
|
||||
**/
|
||||
obj<AExpression> assemble_expr(obj<AAllocator> mm);
|
||||
|
||||
///@}
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -22,21 +22,24 @@ namespace xo {
|
|||
using ppindentinfo = xo::print::ppindentinfo;
|
||||
|
||||
public:
|
||||
explicit DExpectExprSsm(bool allow_defs,
|
||||
bool cxl_on_rightparen);
|
||||
DExpectExprSsm(bool allow_defs,
|
||||
bool cxl_on_rightbrace,
|
||||
bool cxl_on_rightparen);
|
||||
|
||||
static DExpectExprSsm * _make(DArena & parser_mm,
|
||||
bool allow_defs,
|
||||
bool cxl_on_rightbrace);
|
||||
bool cxl_on_rightbrace,
|
||||
bool cxl_on_rightparen);
|
||||
|
||||
/** create fop referring to new DExpectExprSsm **/
|
||||
static obj<ASyntaxStateMachine,DExpectExprSsm> make(DArena & parser_mm,
|
||||
bool allow_defs,
|
||||
bool cxl_on_rightbrace);
|
||||
bool cxl_on_rightbrace,
|
||||
bool cxl_on_rightparen);
|
||||
|
||||
static void start(DArena & parser_mm,
|
||||
bool allow_defs,
|
||||
static void start(bool allow_defs,
|
||||
bool cxl_on_rightbrace,
|
||||
bool cxl_on_rightparen,
|
||||
ParserStateMachine * p_psm);
|
||||
static void start(ParserStateMachine * p_psm);
|
||||
|
||||
|
|
@ -46,6 +49,7 @@ namespace xo {
|
|||
static const char * ssm_classname() { return "DExpectExprSsm"; }
|
||||
bool allow_defs() const noexcept { return allow_defs_; }
|
||||
bool cxl_on_rightbrace() const noexcept { return cxl_on_rightbrace_; }
|
||||
bool cxl_on_rightparen() const noexcept { return cxl_on_rightparen_; }
|
||||
|
||||
///@}
|
||||
/** @defgroup scm-expectexpr-methods general methods **/
|
||||
|
|
@ -57,6 +61,15 @@ namespace xo {
|
|||
void on_leftparen_token(const Token & tk,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
/** update state for this syntax on incoming rightparen token @p tk,
|
||||
* with overall parser state in @p p_psm.
|
||||
*
|
||||
* Generally treats as illegal, but cancels gracefully when
|
||||
* @ref cxl_on_rightparen_ set.
|
||||
**/
|
||||
void on_rightparen_token(const Token & tk,
|
||||
ParserStateMachine * p_psm);
|
||||
|
||||
/** update state for this syntax on incoming leftbrace token @p tk,
|
||||
* with overall parser state in @p p_psm
|
||||
**/
|
||||
|
|
@ -165,8 +178,11 @@ namespace xo {
|
|||
* 2a. expression
|
||||
**/
|
||||
bool cxl_on_rightbrace_ = false;
|
||||
|
||||
|
||||
/** if true: expecting either:
|
||||
* 1a. expression
|
||||
* 1b. right paren ')', in which case no expression
|
||||
**/
|
||||
bool cxl_on_rightparen_ = false;
|
||||
};
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue