xo-reader2 xo-expresion2: work on define-expressions [WIP]
This commit is contained in:
parent
8bae2128a1
commit
516b0932ee
40 changed files with 711 additions and 72 deletions
|
|
@ -32,6 +32,8 @@ xo_add_genfacet(
|
||||||
OUTPUT_CPP_DIR src/expression2
|
OUTPUT_CPP_DIR src/expression2
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# ----------------------------------------------------------------
|
||||||
|
|
||||||
# note: manual target; generated code committed to git
|
# note: manual target; generated code committed to git
|
||||||
xo_add_genfacet(
|
xo_add_genfacet(
|
||||||
TARGET xo-expression2-facet-expression
|
TARGET xo-expression2-facet-expression
|
||||||
|
|
@ -66,6 +68,20 @@ xo_add_genfacetimpl(
|
||||||
OUTPUT_CPP_DIR src/expression2
|
OUTPUT_CPP_DIR src/expression2
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# note: manual target; generated code committed to git
|
||||||
|
xo_add_genfacetimpl(
|
||||||
|
TARGET xo-expression2-facetimpl-expression-defineexpr
|
||||||
|
FACET_PKG xo_expression2
|
||||||
|
FACET Expression
|
||||||
|
REPR DefineExpr
|
||||||
|
INPUT idl/IExpression_DDefineExpr.json5
|
||||||
|
OUTPUT_HPP_DIR include/xo/expression2
|
||||||
|
OUTPUT_IMPL_SUBDIR detail
|
||||||
|
OUTPUT_CPP_DIR src/expression2
|
||||||
|
)
|
||||||
|
|
||||||
|
# ----------------------------------------------------------------
|
||||||
|
|
||||||
# note: manual target; generated code committed to git
|
# note: manual target; generated code committed to git
|
||||||
xo_add_genfacetimpl(
|
xo_add_genfacetimpl(
|
||||||
TARGET xo-expression2-facetimpl-gcobject-uniquestring
|
TARGET xo-expression2-facetimpl-gcobject-uniquestring
|
||||||
|
|
|
||||||
12
xo-expression2/idl/IExpression_DDefineExpr.json5
Normal file
12
xo-expression2/idl/IExpression_DDefineExpr.json5
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
{
|
||||||
|
mode: "implementation",
|
||||||
|
includes: [ "\"Expression.hpp\"" ],
|
||||||
|
local_types: [ ],
|
||||||
|
namespace1: "xo",
|
||||||
|
namespace2: "scm",
|
||||||
|
facet_idl: "idl/Expression.json5",
|
||||||
|
brief: "provide AExpression interface for DDefineExpr state",
|
||||||
|
using_doxygen: true,
|
||||||
|
repr: "DDefineExpr",
|
||||||
|
doc: ["doc for IExpression+DDefineExpr" ],
|
||||||
|
}
|
||||||
|
|
@ -15,6 +15,7 @@ namespace xo {
|
||||||
static constexpr int32_t s_link_global = -1;
|
static constexpr int32_t s_link_global = -1;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
Binding() : i_link_{-2}, j_slot_{-1} {}
|
||||||
Binding(int32_t i_link, int32_t j_slot)
|
Binding(int32_t i_link, int32_t j_slot)
|
||||||
: i_link_{i_link}, j_slot_{j_slot} {}
|
: i_link_{i_link}, j_slot_{j_slot} {}
|
||||||
|
|
||||||
|
|
@ -32,6 +33,7 @@ namespace xo {
|
||||||
* >= 0: number of parent links to traverse
|
* >= 0: number of parent links to traverse
|
||||||
* to a fixed-size frame
|
* to a fixed-size frame
|
||||||
* -1: resolve globally
|
* -1: resolve globally
|
||||||
|
* -2: sentinel (binding info not computed)
|
||||||
**/
|
**/
|
||||||
int32_t i_link_ = s_link_sentinel;
|
int32_t i_link_ = s_link_sentinel;
|
||||||
/** if @ref i_link_ >= 0, frame offset
|
/** if @ref i_link_ >= 0, frame offset
|
||||||
|
|
|
||||||
75
xo-expression2/include/xo/expression2/DDefineExpr.hpp
Normal file
75
xo-expression2/include/xo/expression2/DDefineExpr.hpp
Normal file
|
|
@ -0,0 +1,75 @@
|
||||||
|
/** @file DDefineExpr.hpp
|
||||||
|
*
|
||||||
|
* @author Roland Conybeare, Jan 2026
|
||||||
|
**/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Expression.hpp"
|
||||||
|
#include "DVariable.hpp"
|
||||||
|
#include <xo/alloc2/Allocator.hpp>
|
||||||
|
|
||||||
|
namespace xo {
|
||||||
|
namespace scm {
|
||||||
|
class DUniqueString; // see DUniqueString.hpp
|
||||||
|
|
||||||
|
/** @class DDefineExpr
|
||||||
|
* @brief an expression that introduces a variable.
|
||||||
|
*
|
||||||
|
* Variable may optionally be declared with a type,
|
||||||
|
* and may come with an expression specifying an initial value
|
||||||
|
**/
|
||||||
|
class DDefineExpr {
|
||||||
|
public:
|
||||||
|
using AAllocator = xo::mm::AAllocator;
|
||||||
|
using TypeDescr = xo::reflect::TypeDescr;
|
||||||
|
|
||||||
|
public:
|
||||||
|
/** create instance: define-expr using memory from @p mm
|
||||||
|
* with lhs name @p lhs_name and rhs expression @p rhs_expr
|
||||||
|
**/
|
||||||
|
static DDefineExpr * make(obj<AAllocator> mm,
|
||||||
|
const DUniqueString * lhs_name,
|
||||||
|
obj<AExpression> rhs_expr);
|
||||||
|
/** create empty skeleton. Rely on this for parsing
|
||||||
|
**/
|
||||||
|
static DDefineExpr * make_empty(obj<AAllocator> mm);
|
||||||
|
|
||||||
|
DVariable * lhs() const { return lhs_var_; }
|
||||||
|
obj<AExpression> rhs() const noexcept { return rhs_; }
|
||||||
|
|
||||||
|
const DUniqueString * name() const noexcept;
|
||||||
|
|
||||||
|
void assign_lhs_name(const DUniqueString * name);
|
||||||
|
/** CONCESSION. will use DUniqueString* once we have StringTable **/
|
||||||
|
void assign_lhs_name(std::string_view name);
|
||||||
|
|
||||||
|
/** @defgroup scm-defineexpr-expression-facet **/
|
||||||
|
///@{
|
||||||
|
|
||||||
|
exprtype extype() const noexcept { return exprtype::define; }
|
||||||
|
TypeRef typeref() const noexcept { return lhs_var_->typeref(); }
|
||||||
|
TypeDescr valuetype() const noexcept { return lhs_var_->typeref().td(); }
|
||||||
|
void assign_valuetype(TypeDescr td) noexcept;
|
||||||
|
|
||||||
|
///@}
|
||||||
|
|
||||||
|
private:
|
||||||
|
DDefineExpr(DVariable * lhs_var,
|
||||||
|
obj<AExpression> rhs);
|
||||||
|
|
||||||
|
private:
|
||||||
|
/** variable being defined by this expression.
|
||||||
|
**/
|
||||||
|
DVariable * lhs_var_ = nullptr;
|
||||||
|
|
||||||
|
/** expression for initial value of this expression
|
||||||
|
**/
|
||||||
|
obj<AExpression> rhs_;
|
||||||
|
|
||||||
|
// std::set<std::string> free_var_set_;
|
||||||
|
};
|
||||||
|
} /*namespace scm*/
|
||||||
|
} /*namespace xo*/
|
||||||
|
|
||||||
|
/* end DDefineExpr.hpp */
|
||||||
39
xo-expression2/include/xo/expression2/DGlobalSymtab.hpp
Normal file
39
xo-expression2/include/xo/expression2/DGlobalSymtab.hpp
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
/** @file DGlobalSymtab.hpp
|
||||||
|
*
|
||||||
|
* @author Roland Conybeare, Jan 2026
|
||||||
|
**/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Binding.hpp"
|
||||||
|
|
||||||
|
namespace xo {
|
||||||
|
namespace scm {
|
||||||
|
class DUniqueString;
|
||||||
|
|
||||||
|
/** @class DGlobalSymtab
|
||||||
|
* @brief symbol table for toplevel environment
|
||||||
|
**/
|
||||||
|
struct DGlobalSymtab {
|
||||||
|
public:
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
/** @defgroup xo-expression2-symboltable-facet symboltable facet**/
|
||||||
|
///@{
|
||||||
|
|
||||||
|
/** true for global symbol table **/
|
||||||
|
bool is_global_symtab() const noexcept { return true; }
|
||||||
|
|
||||||
|
/** lookup binding for variable @p sym **/
|
||||||
|
Binding lookup_binding(const DUniqueString * sym) const noexcept;
|
||||||
|
|
||||||
|
///@}
|
||||||
|
|
||||||
|
private:
|
||||||
|
};
|
||||||
|
|
||||||
|
} /*namespace scm*/
|
||||||
|
} /*namespace xo*/
|
||||||
|
|
||||||
|
/* end DGlobalSymtab.hpp */
|
||||||
|
|
@ -19,15 +19,33 @@ namespace xo {
|
||||||
**/
|
**/
|
||||||
class DVariable {
|
class DVariable {
|
||||||
public:
|
public:
|
||||||
|
using AAllocator = xo::mm::AAllocator;
|
||||||
using TypeDescr = xo::reflect::TypeDescr;
|
using TypeDescr = xo::reflect::TypeDescr;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DVariable(const DUniqueString & name, const TypeRef & typeref, Binding path)
|
/** create instance
|
||||||
: name_{name}, typeref_{typeref}, path_{path} {}
|
* @p mm memory allocator
|
||||||
|
* @p name variable name
|
||||||
|
* @p typeref type information for legal values
|
||||||
|
* (possibly just placeholder when relying on inference)
|
||||||
|
* @p path binding path to runtime value.
|
||||||
|
* This may be computed after parsing;
|
||||||
|
* mnust be resolved before execution.
|
||||||
|
**/
|
||||||
|
static DVariable * make(obj<AAllocator> mm,
|
||||||
|
const DUniqueString * name,
|
||||||
|
const TypeRef & typeref,
|
||||||
|
Binding path = Binding());
|
||||||
|
|
||||||
const DUniqueString & name() const { return name_; }
|
DVariable(const DUniqueString * name,
|
||||||
|
const TypeRef & typeref,
|
||||||
|
Binding path);
|
||||||
|
|
||||||
|
const DUniqueString * name() const { return name_; }
|
||||||
Binding path() const { return path_; }
|
Binding path() const { return path_; }
|
||||||
|
|
||||||
|
void assign_name(const DUniqueString * name) { this->name_ = name; }
|
||||||
|
|
||||||
/** @defgroup scm-variable-expression-facet**/
|
/** @defgroup scm-variable-expression-facet**/
|
||||||
///@{
|
///@{
|
||||||
|
|
||||||
|
|
@ -40,7 +58,7 @@ namespace xo {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/** symbol name **/
|
/** symbol name **/
|
||||||
const DUniqueString & name_;
|
const DUniqueString * name_;
|
||||||
/** variable value always has type consistent
|
/** variable value always has type consistent
|
||||||
* with this description
|
* with this description
|
||||||
**/
|
**/
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,66 @@
|
||||||
|
/** @file IExpression_DDefineExpr.hpp
|
||||||
|
*
|
||||||
|
* Generated automagically from ingredients:
|
||||||
|
* 1. code generator:
|
||||||
|
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||||
|
* arguments:
|
||||||
|
* --input [idl/IExpression_DDefineExpr.json5]
|
||||||
|
* 2. jinja2 template for abstract facet .hpp file:
|
||||||
|
* [iface_facet_repr.hpp.j2]
|
||||||
|
* 3. idl for facet methods
|
||||||
|
* [idl/IExpression_DDefineExpr.json5]
|
||||||
|
**/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Expression.hpp"
|
||||||
|
#include "Expression.hpp"
|
||||||
|
#include "DDefineExpr.hpp"
|
||||||
|
|
||||||
|
namespace xo { namespace scm { class IExpression_DDefineExpr; } }
|
||||||
|
|
||||||
|
namespace xo {
|
||||||
|
namespace facet {
|
||||||
|
template <>
|
||||||
|
struct FacetImplementation<xo::scm::AExpression,
|
||||||
|
xo::scm::DDefineExpr>
|
||||||
|
{
|
||||||
|
using ImplType = xo::scm::IExpression_Xfer
|
||||||
|
<xo::scm::DDefineExpr,
|
||||||
|
xo::scm::IExpression_DDefineExpr>;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace xo {
|
||||||
|
namespace scm {
|
||||||
|
/** @class IExpression_DDefineExpr
|
||||||
|
**/
|
||||||
|
class IExpression_DDefineExpr {
|
||||||
|
public:
|
||||||
|
/** @defgroup scm-expression-ddefineexpr-type-traits **/
|
||||||
|
///@{
|
||||||
|
using TypeDescr = xo::scm::AExpression::TypeDescr;
|
||||||
|
using Copaque = xo::scm::AExpression::Copaque;
|
||||||
|
using Opaque = xo::scm::AExpression::Opaque;
|
||||||
|
///@}
|
||||||
|
/** @defgroup scm-expression-ddefineexpr-methods **/
|
||||||
|
///@{
|
||||||
|
// const methods
|
||||||
|
/** expression type (constant | apply | ..) **/
|
||||||
|
static exprtype extype(const DDefineExpr & self) noexcept;
|
||||||
|
/** placeholder for type giving possible values for this expression **/
|
||||||
|
static TypeRef typeref(const DDefineExpr & self) noexcept;
|
||||||
|
/** type giving possible values for this expression. Maybe null before typecheck **/
|
||||||
|
static TypeDescr valuetype(const DDefineExpr & self) noexcept;
|
||||||
|
|
||||||
|
// non-const methods
|
||||||
|
/** assing to valuetype member. Useful when scaffolding expressions **/
|
||||||
|
static void assign_valuetype(DDefineExpr & self, TypeDescr td) noexcept;
|
||||||
|
///@}
|
||||||
|
};
|
||||||
|
|
||||||
|
} /*namespace scm*/
|
||||||
|
} /*namespace xo*/
|
||||||
|
|
||||||
|
/* end */
|
||||||
|
|
@ -23,8 +23,10 @@ namespace xo {
|
||||||
#ifdef NOT_YET
|
#ifdef NOT_YET
|
||||||
/** a literal constant that refers to a linkable named function **/
|
/** a literal constant that refers to a linkable named function **/
|
||||||
primitive,
|
primitive,
|
||||||
|
#endif
|
||||||
/** variable/function definition **/
|
/** variable/function definition **/
|
||||||
define,
|
define,
|
||||||
|
#ifdef NOT_YET
|
||||||
/** variable assignment **/
|
/** variable assignment **/
|
||||||
assign,
|
assign,
|
||||||
/** function call **/
|
/** function call **/
|
||||||
|
|
@ -55,7 +57,9 @@ namespace xo {
|
||||||
case exprtype::constant: return "constant";
|
case exprtype::constant: return "constant";
|
||||||
#ifdef NOT_YET
|
#ifdef NOT_YET
|
||||||
case exprtype::primitive: return "primitive";
|
case exprtype::primitive: return "primitive";
|
||||||
|
#endif
|
||||||
case exprtype::define: return "define";
|
case exprtype::define: return "define";
|
||||||
|
#ifdef NOT_YET
|
||||||
case exprtype::assign: return "assign";
|
case exprtype::assign: return "assign";
|
||||||
case exprtype::apply: return "apply";
|
case exprtype::apply: return "apply";
|
||||||
case exprtype::lambda: return "lambda";
|
case exprtype::lambda: return "lambda";
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,17 @@ set(SELF_SRCS
|
||||||
|
|
||||||
DConstant.cpp
|
DConstant.cpp
|
||||||
DVariable.cpp
|
DVariable.cpp
|
||||||
|
DDefineExpr.cpp
|
||||||
|
|
||||||
TypeRef.cpp
|
TypeRef.cpp
|
||||||
|
|
||||||
IExpression_Any.cpp
|
IExpression_Any.cpp
|
||||||
IExpression_DConstant.cpp
|
IExpression_DConstant.cpp
|
||||||
IExpression_DVariable.cpp
|
IExpression_DVariable.cpp
|
||||||
|
IExpression_DDefineExpr.cpp
|
||||||
|
|
||||||
|
DLocalSymtab.cpp
|
||||||
|
DGlobalSymtab.cpp
|
||||||
|
|
||||||
ISymbolTable_Any.cpp
|
ISymbolTable_Any.cpp
|
||||||
|
|
||||||
|
|
|
||||||
71
xo-expression2/src/expression2/DDefineExpr.cpp
Normal file
71
xo-expression2/src/expression2/DDefineExpr.cpp
Normal file
|
|
@ -0,0 +1,71 @@
|
||||||
|
/** @file DDefineExpr.cpp
|
||||||
|
*
|
||||||
|
* @author Roland Conybeare, Jan 2026
|
||||||
|
**/
|
||||||
|
|
||||||
|
#include "DDefineExpr.hpp"
|
||||||
|
#include <xo/indentlog/scope.hpp>
|
||||||
|
|
||||||
|
namespace xo {
|
||||||
|
using xo::facet::typeseq;
|
||||||
|
|
||||||
|
namespace scm {
|
||||||
|
|
||||||
|
DDefineExpr::DDefineExpr(DVariable * lhs_var,
|
||||||
|
obj<AExpression> rhs)
|
||||||
|
: lhs_var_{lhs_var}, rhs_{rhs}
|
||||||
|
{}
|
||||||
|
|
||||||
|
DDefineExpr *
|
||||||
|
DDefineExpr::make(obj<AAllocator> mm,
|
||||||
|
const DUniqueString * lhs_name,
|
||||||
|
obj<AExpression> rhs_expr)
|
||||||
|
{
|
||||||
|
void * mem = mm.alloc(typeseq::id<DDefineExpr>(),
|
||||||
|
sizeof(DDefineExpr));
|
||||||
|
|
||||||
|
auto lhs_var = DVariable::make(mm,
|
||||||
|
lhs_name,
|
||||||
|
rhs_expr.typeref());
|
||||||
|
|
||||||
|
return new (mem) DDefineExpr(lhs_var, rhs_expr);
|
||||||
|
}
|
||||||
|
|
||||||
|
DDefineExpr *
|
||||||
|
DDefineExpr::make_empty(obj<AAllocator> mm)
|
||||||
|
{
|
||||||
|
return make(mm,
|
||||||
|
nullptr /*lhs_name*/,
|
||||||
|
obj<AExpression>() /*rhs_expr*/);
|
||||||
|
}
|
||||||
|
|
||||||
|
const DUniqueString *
|
||||||
|
DDefineExpr::name() const noexcept
|
||||||
|
{
|
||||||
|
return lhs_var_->name();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
DDefineExpr::assign_lhs_name(const DUniqueString * name)
|
||||||
|
{
|
||||||
|
lhs_var_->assign_name(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
DDefineExpr::assign_lhs_name(std::string_view name)
|
||||||
|
{
|
||||||
|
scope log(XO_DEBUG(true), "bogus impl - will require unique string");
|
||||||
|
log && log(xtag("name", name));
|
||||||
|
|
||||||
|
//lhs_var_->assign_name(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
DDefineExpr::assign_valuetype(TypeDescr td) noexcept
|
||||||
|
{
|
||||||
|
lhs_var_->assign_valuetype(td);
|
||||||
|
}
|
||||||
|
} /*namespace scm*/
|
||||||
|
} /*namespace xo*/
|
||||||
|
|
||||||
|
/* end DDefineExpr.cpp */
|
||||||
27
xo-expression2/src/expression2/DGlobalSymtab.cpp
Normal file
27
xo-expression2/src/expression2/DGlobalSymtab.cpp
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
/** @file DGlobalSymtab.cpp
|
||||||
|
*
|
||||||
|
* @author Roland Conybeare, Jan 2026
|
||||||
|
**/
|
||||||
|
|
||||||
|
#include "DGlobalSymtab.hpp"
|
||||||
|
#include "DUniqueString.hpp"
|
||||||
|
#include <xo/indentlog/scope.hpp>
|
||||||
|
|
||||||
|
namespace xo {
|
||||||
|
namespace scm {
|
||||||
|
|
||||||
|
Binding
|
||||||
|
DGlobalSymtab::lookup_binding(const DUniqueString * sym) const noexcept
|
||||||
|
{
|
||||||
|
(void)sym;
|
||||||
|
|
||||||
|
scope log(XO_DEBUG(true), "stub");
|
||||||
|
log && log(xtag("sym", std::string_view(*sym)));
|
||||||
|
|
||||||
|
return Binding();
|
||||||
|
}
|
||||||
|
|
||||||
|
} /*namespace scm*/
|
||||||
|
} /*namespace xo*/
|
||||||
|
|
||||||
|
/* end DGlobalSymtab.cpp */
|
||||||
25
xo-expression2/src/expression2/DLocalSymtab.cpp
Normal file
25
xo-expression2/src/expression2/DLocalSymtab.cpp
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
/** @file DLocalSymtab.cpp
|
||||||
|
*
|
||||||
|
* @author Roland Conybeare, Jan 2026
|
||||||
|
**/
|
||||||
|
|
||||||
|
#include "DLocalSymtab.hpp"
|
||||||
|
#include "DUniqueString.hpp"
|
||||||
|
#include <xo/indentlog/scope.hpp>
|
||||||
|
|
||||||
|
namespace xo {
|
||||||
|
namespace scm {
|
||||||
|
|
||||||
|
Binding
|
||||||
|
DLocalSymtab::lookup_binding(const DUniqueString * sym) const noexcept
|
||||||
|
{
|
||||||
|
scope log(XO_DEBUG(true), "stub impl");
|
||||||
|
log && log(xtag("sym", std::string_view(*sym)));
|
||||||
|
|
||||||
|
return Binding();
|
||||||
|
}
|
||||||
|
|
||||||
|
} /*namespace scm*/
|
||||||
|
} /*namespace xo*/
|
||||||
|
|
||||||
|
/* end DLocalSymtab.cpp */
|
||||||
|
|
@ -7,12 +7,34 @@
|
||||||
#include "exprtype.hpp"
|
#include "exprtype.hpp"
|
||||||
|
|
||||||
namespace xo {
|
namespace xo {
|
||||||
|
using xo::facet::typeseq;
|
||||||
|
|
||||||
namespace scm {
|
namespace scm {
|
||||||
|
|
||||||
|
DVariable *
|
||||||
|
DVariable::make(obj<AAllocator> mm,
|
||||||
|
const DUniqueString * name,
|
||||||
|
const TypeRef & typeref,
|
||||||
|
Binding path)
|
||||||
|
{
|
||||||
|
void * mem = mm.alloc(typeseq::id<DVariable>(),
|
||||||
|
sizeof(DVariable));
|
||||||
|
|
||||||
|
return new (mem) DVariable(name, typeref, path);
|
||||||
|
}
|
||||||
|
|
||||||
|
DVariable::DVariable(const DUniqueString * name,
|
||||||
|
const TypeRef & typeref,
|
||||||
|
Binding path)
|
||||||
|
: name_{name}, typeref_{typeref}, path_{path}
|
||||||
|
{}
|
||||||
|
|
||||||
void
|
void
|
||||||
DVariable::assign_valuetype(TypeDescr td) noexcept
|
DVariable::assign_valuetype(TypeDescr td) noexcept
|
||||||
{
|
{
|
||||||
typeref_.resolve(td);
|
typeref_.resolve(td);
|
||||||
}
|
}
|
||||||
|
|
||||||
} /*namespace scm*/
|
} /*namespace scm*/
|
||||||
} /*namespace xo*/
|
} /*namespace xo*/
|
||||||
|
|
||||||
|
|
|
||||||
45
xo-expression2/src/expression2/IExpression_DDefineExpr.cpp
Normal file
45
xo-expression2/src/expression2/IExpression_DDefineExpr.cpp
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
/** @file IExpression_DDefineExpr.cpp
|
||||||
|
*
|
||||||
|
* Generated automagically from ingredients:
|
||||||
|
* 1. code generator:
|
||||||
|
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||||
|
* arguments:
|
||||||
|
* --input [idl/IExpression_DDefineExpr.json5]
|
||||||
|
* 2. jinja2 template for abstract facet .hpp file:
|
||||||
|
* [iface_facet_any.hpp.j2]
|
||||||
|
* 3. idl for facet methods
|
||||||
|
* [idl/IExpression_DDefineExpr.json5]
|
||||||
|
**/
|
||||||
|
|
||||||
|
#include "detail/IExpression_DDefineExpr.hpp"
|
||||||
|
|
||||||
|
namespace xo {
|
||||||
|
namespace scm {
|
||||||
|
auto
|
||||||
|
IExpression_DDefineExpr::extype(const DDefineExpr & self) noexcept -> exprtype
|
||||||
|
{
|
||||||
|
return self.extype();
|
||||||
|
}
|
||||||
|
|
||||||
|
auto
|
||||||
|
IExpression_DDefineExpr::typeref(const DDefineExpr & self) noexcept -> TypeRef
|
||||||
|
{
|
||||||
|
return self.typeref();
|
||||||
|
}
|
||||||
|
|
||||||
|
auto
|
||||||
|
IExpression_DDefineExpr::valuetype(const DDefineExpr & self) noexcept -> TypeDescr
|
||||||
|
{
|
||||||
|
return self.valuetype();
|
||||||
|
}
|
||||||
|
|
||||||
|
auto
|
||||||
|
IExpression_DDefineExpr::assign_valuetype(DDefineExpr & self, TypeDescr td) noexcept -> void
|
||||||
|
{
|
||||||
|
self.assign_valuetype(td);
|
||||||
|
}
|
||||||
|
|
||||||
|
} /*namespace scm*/
|
||||||
|
} /*namespace xo*/
|
||||||
|
|
||||||
|
/* end IExpression_DDefineExpr.cpp */
|
||||||
|
|
@ -92,7 +92,7 @@ namespace xo {
|
||||||
//static_assert(false && "expect specialization <AFacet,DRepr> which should provide ImplType trait");
|
//static_assert(false && "expect specialization <AFacet,DRepr> which should provide ImplType trait");
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Retrieve facet implementation for a (facet, datatype) pair **/
|
/** Retrieve facet implementation for a (facet,datatype) pair **/
|
||||||
template <typename AFacet, typename DRepr>
|
template <typename AFacet, typename DRepr>
|
||||||
using FacetImplType = FacetImplementation<AFacet, DRepr>::ImplType;
|
using FacetImplType = FacetImplementation<AFacet, DRepr>::ImplType;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,12 @@ namespace xo {
|
||||||
**/
|
**/
|
||||||
void _do_eval_constant_op();
|
void _do_eval_constant_op();
|
||||||
|
|
||||||
|
/** evaluate a define-expression
|
||||||
|
* Require:
|
||||||
|
* - expression in @ref expr_
|
||||||
|
**/
|
||||||
|
void _do_eval_define_op();
|
||||||
|
|
||||||
/** evaluate a variable expression
|
/** evaluate a variable expression
|
||||||
* Require:
|
* Require:
|
||||||
* - expression in @ref expr_
|
* - expression in @ref expr_
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,9 @@ namespace xo {
|
||||||
case exprtype::constant:
|
case exprtype::constant:
|
||||||
_do_eval_constant_op();
|
_do_eval_constant_op();
|
||||||
break;
|
break;
|
||||||
|
case exprtype::define:
|
||||||
|
_do_eval_define_op();
|
||||||
|
break;
|
||||||
case exprtype::variable:
|
case exprtype::variable:
|
||||||
_do_eval_variable_op();
|
_do_eval_variable_op();
|
||||||
break;
|
break;
|
||||||
|
|
@ -61,6 +64,13 @@ namespace xo {
|
||||||
this->pc_ = this->cont_;
|
this->pc_ = this->cont_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
VirtualSchematikaMachine::_do_eval_define_op()
|
||||||
|
{
|
||||||
|
// not implemented
|
||||||
|
assert(false);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
VirtualSchematikaMachine::_do_eval_variable_op()
|
VirtualSchematikaMachine::_do_eval_variable_op()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,15 @@
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
nonconst_methods: [
|
nonconst_methods: [
|
||||||
|
{
|
||||||
|
name: "on_symbol_token",
|
||||||
|
doc: ["operate state machine for incoming symbol-token @p tk"],
|
||||||
|
return_type: "void",
|
||||||
|
args: [
|
||||||
|
{type: "const Token &", name: "tk"},
|
||||||
|
{type: "ParserStateMachine *", name: "p_psm"},
|
||||||
|
],
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "on_def_token",
|
name: "on_def_token",
|
||||||
doc: ["update state machine for incoming define-keyword-token @p tk"],
|
doc: ["update state machine for incoming define-keyword-token @p tk"],
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,8 @@
|
||||||
#include "ParserStateMachine.hpp"
|
#include "ParserStateMachine.hpp"
|
||||||
//#include "SyntaxStateMachine.hpp"
|
//#include "SyntaxStateMachine.hpp"
|
||||||
#include "syntaxstatetype.hpp"
|
#include "syntaxstatetype.hpp"
|
||||||
|
#include <xo/expression2/detail/IExpression_DDefineExpr.hpp>
|
||||||
|
#include <xo/expression2/DDefineExpr.hpp>
|
||||||
#include <xo/facet/obj.hpp>
|
#include <xo/facet/obj.hpp>
|
||||||
|
|
||||||
namespace xo {
|
namespace xo {
|
||||||
|
|
@ -69,21 +71,29 @@ namespace xo {
|
||||||
**/
|
**/
|
||||||
class DDefineSsm {
|
class DDefineSsm {
|
||||||
public:
|
public:
|
||||||
|
using AAllocator = xo::mm::AAllocator;
|
||||||
using DArena = xo::mm::DArena;
|
using DArena = xo::mm::DArena;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/** @defgroup scm-define-ssm-facet constructors **/
|
/** @defgroup scm-define-ssm-facet constructors **/
|
||||||
///@{
|
///@{
|
||||||
|
|
||||||
DDefineSsm();
|
/** constructor; using @p def_expr for initial expression scaffold **/
|
||||||
|
explicit DDefineSsm(DDefineExpr * def_expr);
|
||||||
|
|
||||||
/** create instance using memory from @p parser_mm **/
|
/** create instance using memory from @p parser_mm.
|
||||||
static DDefineSsm * make(DArena & parser_mm);
|
* Initial expression scaffold @p def_expr
|
||||||
|
**/
|
||||||
|
static DDefineSsm * make(DArena & parser_mm,
|
||||||
|
DDefineExpr * def_expr);
|
||||||
|
|
||||||
/** start nested parser for a define-expression,
|
/** start nested parser for a define-expression,
|
||||||
* on top of parser state machine @p p_psm
|
* on top of parser state machine @p p_psm
|
||||||
|
* Use @p parser_mm to allocate syntax state machines,
|
||||||
|
* and @p expr_mm to allocate expressions
|
||||||
**/
|
**/
|
||||||
static void start(DArena & parser_mm,
|
static void start(DArena & parser_mm,
|
||||||
|
obj<AAllocator> expr_mm,
|
||||||
ParserStateMachine * p_psm);
|
ParserStateMachine * p_psm);
|
||||||
|
|
||||||
///@}
|
///@}
|
||||||
|
|
@ -98,6 +108,12 @@ namespace xo {
|
||||||
**/
|
**/
|
||||||
std::string_view get_expect_str() const noexcept;
|
std::string_view get_expect_str() const noexcept;
|
||||||
|
|
||||||
|
/** operate state machine for this syntax on incoming symbol-token @p tk
|
||||||
|
* with overall parser state in @p p_psm
|
||||||
|
**/
|
||||||
|
void on_symbol_token(const Token & tk,
|
||||||
|
ParserStateMachine * p_psm);
|
||||||
|
|
||||||
/** update state for this syntax on incoming token @p tk,
|
/** update state for this syntax on incoming token @p tk,
|
||||||
* overall parser state in @p p_psm
|
* overall parser state in @p p_psm
|
||||||
**/
|
**/
|
||||||
|
|
@ -121,6 +137,11 @@ namespace xo {
|
||||||
private:
|
private:
|
||||||
/** identify define-expression state **/
|
/** identify define-expression state **/
|
||||||
defexprstatetype defstate_;
|
defexprstatetype defstate_;
|
||||||
|
|
||||||
|
/** scaffolded define-expression.
|
||||||
|
* This will eventually be the output of this ssm
|
||||||
|
**/
|
||||||
|
obj<AExpression,DDefineExpr> def_expr_;
|
||||||
};
|
};
|
||||||
} /*namespace scm*/
|
} /*namespace scm*/
|
||||||
} /*namespace xo*/
|
} /*namespace xo*/
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,11 @@ namespace xo {
|
||||||
**/
|
**/
|
||||||
std::string_view get_expect_str() const noexcept;
|
std::string_view get_expect_str() const noexcept;
|
||||||
|
|
||||||
|
/** operate state machine for this syntax on incoming symbol token @p tk
|
||||||
|
* with overall parser state in @p p_psm
|
||||||
|
**/
|
||||||
|
void on_symbol_token(const Token & tk, ParserStateMachine * p_psm);
|
||||||
|
|
||||||
/** update state for this syntax on incoming token @p tk,
|
/** update state for this syntax on incoming token @p tk,
|
||||||
* overall parser state in @p p_psm
|
* overall parser state in @p p_psm
|
||||||
**/
|
**/
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,8 @@ namespace xo {
|
||||||
std::string_view error_src_fn_;
|
std::string_view error_src_fn_;
|
||||||
const DString * error_description_ = nullptr;
|
const DString * error_description_ = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
} /*namespace scm*/
|
} /*namespace scm*/
|
||||||
} /*namespace xo*/
|
} /*namespace xo*/
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "ParserResult.hpp"
|
#include "ParserResult.hpp"
|
||||||
|
#include <xo/expression2/DVariable.hpp>
|
||||||
#include <xo/tokenizer2/Token.hpp>
|
#include <xo/tokenizer2/Token.hpp>
|
||||||
#include <xo/alloc2/Allocator.hpp>
|
#include <xo/alloc2/Allocator.hpp>
|
||||||
#include <xo/arena/DArena.hpp>
|
#include <xo/arena/DArena.hpp>
|
||||||
|
|
@ -32,14 +33,14 @@ namespace xo {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ParserStateMachine(const ArenaConfig & config,
|
ParserStateMachine(const ArenaConfig & config,
|
||||||
obj<AAllocator> * expr_alloc);
|
obj<AAllocator> expr_alloc);
|
||||||
|
|
||||||
/** @defgroup scm-parserstatemachine-accessors accessor methods **/
|
/** @defgroup scm-parserstatemachine-accessors accessor methods **/
|
||||||
///@{
|
///@{
|
||||||
|
|
||||||
bool debug_flag() const noexcept { return debug_flag_; }
|
bool debug_flag() const noexcept { return debug_flag_; }
|
||||||
ParserStack * stack() const noexcept { return stack_; }
|
ParserStack * stack() const noexcept { return stack_; }
|
||||||
obj<AAllocator> * expr_alloc() const noexcept { return expr_alloc_; }
|
obj<AAllocator> expr_alloc() const noexcept { return expr_alloc_; }
|
||||||
const ParserResult & result() const noexcept { return result_; }
|
const ParserResult & result() const noexcept { return result_; }
|
||||||
|
|
||||||
/** true iff state machine is currently idle (at top-level) **/
|
/** true iff state machine is currently idle (at top-level) **/
|
||||||
|
|
@ -65,6 +66,9 @@ namespace xo {
|
||||||
/** pop syntax state machine from top of @ref stack_ **/
|
/** pop syntax state machine from top of @ref stack_ **/
|
||||||
void pop_ssm();
|
void pop_ssm();
|
||||||
|
|
||||||
|
/** add variable to current local environment (innermost lexical scope) **/
|
||||||
|
void upsert_var(DVariable * var);
|
||||||
|
|
||||||
/** reset result to none **/
|
/** reset result to none **/
|
||||||
void reset_result();
|
void reset_result();
|
||||||
|
|
||||||
|
|
@ -84,10 +88,13 @@ namespace xo {
|
||||||
**/
|
**/
|
||||||
void on_token(const Token & tk);
|
void on_token(const Token & tk);
|
||||||
|
|
||||||
/** update state for incoming define-token @p tk **/
|
/** operate state machine for incoming symbol-token @p tk **/
|
||||||
|
void on_symbol_token(const Token & tk);
|
||||||
|
|
||||||
|
/** operate state machine for incoming define-token @p tk **/
|
||||||
void on_def_token(const Token & tk);
|
void on_def_token(const Token & tk);
|
||||||
|
|
||||||
/** update state for incoming if-token @p tk **/
|
/** operate state machine for incoming if-token @p tk **/
|
||||||
void on_if_token(const Token & tk);
|
void on_if_token(const Token & tk);
|
||||||
|
|
||||||
///@}
|
///@}
|
||||||
|
|
@ -153,7 +160,7 @@ namespace xo {
|
||||||
* scenario, where top-level Expressions can be discarded
|
* scenario, where top-level Expressions can be discarded
|
||||||
* once compiled.
|
* once compiled.
|
||||||
**/
|
**/
|
||||||
obj<AAllocator> * expr_alloc_ = nullptr;
|
obj<AAllocator> expr_alloc_;
|
||||||
|
|
||||||
/** current output from parser **/
|
/** current output from parser **/
|
||||||
ParserResult result_;
|
ParserResult result_;
|
||||||
|
|
|
||||||
|
|
@ -167,7 +167,7 @@ namespace xo {
|
||||||
* @p debug_flag true to enable debug logging
|
* @p debug_flag true to enable debug logging
|
||||||
**/
|
**/
|
||||||
SchematikaParser(const ArenaConfig & config,
|
SchematikaParser(const ArenaConfig & config,
|
||||||
obj<AAllocator> * expr_alloc,
|
obj<AAllocator> expr_alloc,
|
||||||
bool debug_flag);
|
bool debug_flag);
|
||||||
|
|
||||||
bool debug_flag() const { return debug_flag_; }
|
bool debug_flag() const { return debug_flag_; }
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
*
|
*
|
||||||
* Generated automagically from ingredients:
|
* Generated automagically from ingredients:
|
||||||
* 1. code generator:
|
* 1. code generator:
|
||||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||||
* arguments:
|
* arguments:
|
||||||
* --input [idl/SyntaxStateMachine.json5]
|
* --input [idl/SyntaxStateMachine.json5]
|
||||||
* 2. jinja2 template for facet .hpp file:
|
* 2. jinja2 template for facet .hpp file:
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
*
|
*
|
||||||
* Generated automagically from ingredients:
|
* Generated automagically from ingredients:
|
||||||
* 1. code generator:
|
* 1. code generator:
|
||||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||||
* arguments:
|
* arguments:
|
||||||
* --input [idl/SyntaxStateMachine.json5]
|
* --input [idl/SyntaxStateMachine.json5]
|
||||||
* 2. jinja2 template for abstract facet .hpp file:
|
* 2. jinja2 template for abstract facet .hpp file:
|
||||||
|
|
@ -54,12 +54,14 @@ public:
|
||||||
virtual std::string_view get_expect_str(Copaque data) const noexcept = 0;
|
virtual std::string_view get_expect_str(Copaque data) const noexcept = 0;
|
||||||
|
|
||||||
// nonconst methods
|
// nonconst methods
|
||||||
/** update stat machine for incoming parsed symbol @p sym **/
|
/** operate state machine for incoming symbol-token @p tk **/
|
||||||
virtual void on_parsed_symbol(Opaque data, std::string_view sym, ParserStateMachine * p_psm) = 0;
|
virtual void on_symbol_token(Opaque data, const Token & tk, ParserStateMachine * p_psm) = 0;
|
||||||
/** update state machine for incoming define-keyword-token @p tk **/
|
/** update state machine for incoming define-keyword-token @p tk **/
|
||||||
virtual void on_def_token(Opaque data, const Token & tk, ParserStateMachine * p_psm) = 0;
|
virtual void on_def_token(Opaque data, const Token & tk, ParserStateMachine * p_psm) = 0;
|
||||||
/** update state machine for incoming if-keyword-token @p tk **/
|
/** update state machine for incoming if-keyword-token @p tk **/
|
||||||
virtual void on_if_token(Opaque data, const Token & tk, ParserStateMachine * p_psm) = 0;
|
virtual void on_if_token(Opaque data, const Token & tk, ParserStateMachine * p_psm) = 0;
|
||||||
|
/** update stat machine for incoming parsed symbol @p sym **/
|
||||||
|
virtual void on_parsed_symbol(Opaque data, std::string_view sym, ParserStateMachine * p_psm) = 0;
|
||||||
///@}
|
///@}
|
||||||
}; /*ASyntaxStateMachine*/
|
}; /*ASyntaxStateMachine*/
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
*
|
*
|
||||||
* Generated automagically from ingredients:
|
* Generated automagically from ingredients:
|
||||||
* 1. code generator:
|
* 1. code generator:
|
||||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||||
* arguments:
|
* arguments:
|
||||||
* --input [idl/SyntaxStateMachine.json5]
|
* --input [idl/SyntaxStateMachine.json5]
|
||||||
* 2. jinja2 template for abstract facet .hpp file:
|
* 2. jinja2 template for abstract facet .hpp file:
|
||||||
|
|
@ -59,9 +59,10 @@ namespace scm {
|
||||||
[[noreturn]] std::string_view get_expect_str(Copaque) const noexcept override { _fatal(); }
|
[[noreturn]] std::string_view get_expect_str(Copaque) const noexcept override { _fatal(); }
|
||||||
|
|
||||||
// nonconst methods
|
// nonconst methods
|
||||||
[[noreturn]] void on_parsed_symbol(Opaque, std::string_view, ParserStateMachine *) override;
|
[[noreturn]] void on_symbol_token(Opaque, const Token &, ParserStateMachine *) override;
|
||||||
[[noreturn]] void on_def_token(Opaque, const Token &, ParserStateMachine *) override;
|
[[noreturn]] void on_def_token(Opaque, const Token &, ParserStateMachine *) override;
|
||||||
[[noreturn]] void on_if_token(Opaque, const Token &, ParserStateMachine *) override;
|
[[noreturn]] void on_if_token(Opaque, const Token &, ParserStateMachine *) override;
|
||||||
|
[[noreturn]] void on_parsed_symbol(Opaque, std::string_view, ParserStateMachine *) override;
|
||||||
|
|
||||||
///@}
|
///@}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
*
|
*
|
||||||
* Generated automagically from ingredients:
|
* Generated automagically from ingredients:
|
||||||
* 1. code generator:
|
* 1. code generator:
|
||||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||||
* arguments:
|
* arguments:
|
||||||
* --input [idl/ISyntaxStateMachine_DDefineSsm.json5]
|
* --input [idl/ISyntaxStateMachine_DDefineSsm.json5]
|
||||||
* 2. jinja2 template for abstract facet .hpp file:
|
* 2. jinja2 template for abstract facet .hpp file:
|
||||||
|
|
@ -53,12 +53,14 @@ namespace xo {
|
||||||
static std::string_view get_expect_str(const DDefineSsm & self) noexcept;
|
static std::string_view get_expect_str(const DDefineSsm & self) noexcept;
|
||||||
|
|
||||||
// non-const methods
|
// non-const methods
|
||||||
/** update stat machine for incoming parsed symbol @p sym **/
|
/** operate state machine for incoming symbol-token @p tk **/
|
||||||
static void on_parsed_symbol(DDefineSsm & self, std::string_view sym, ParserStateMachine * p_psm);
|
static void on_symbol_token(DDefineSsm & self, const Token & tk, ParserStateMachine * p_psm);
|
||||||
/** update state machine for incoming define-keyword-token @p tk **/
|
/** update state machine for incoming define-keyword-token @p tk **/
|
||||||
static void on_def_token(DDefineSsm & self, const Token & tk, ParserStateMachine * p_psm);
|
static void on_def_token(DDefineSsm & self, const Token & tk, ParserStateMachine * p_psm);
|
||||||
/** update state machine for incoming if-keyword-token @p tk **/
|
/** update state machine for incoming if-keyword-token @p tk **/
|
||||||
static void on_if_token(DDefineSsm & self, const Token & tk, ParserStateMachine * p_psm);
|
static void on_if_token(DDefineSsm & self, const Token & tk, ParserStateMachine * p_psm);
|
||||||
|
/** update stat machine for incoming parsed symbol @p sym **/
|
||||||
|
static void on_parsed_symbol(DDefineSsm & self, std::string_view sym, ParserStateMachine * p_psm);
|
||||||
///@}
|
///@}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
*
|
*
|
||||||
* Generated automagically from ingredients:
|
* Generated automagically from ingredients:
|
||||||
* 1. code generator:
|
* 1. code generator:
|
||||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||||
* arguments:
|
* arguments:
|
||||||
* --input [idl/ISyntaxStateMachine_DExpectSymbolSsm.json5]
|
* --input [idl/ISyntaxStateMachine_DExpectSymbolSsm.json5]
|
||||||
* 2. jinja2 template for abstract facet .hpp file:
|
* 2. jinja2 template for abstract facet .hpp file:
|
||||||
|
|
@ -53,12 +53,14 @@ namespace xo {
|
||||||
static std::string_view get_expect_str(const DExpectSymbolSsm & self) noexcept;
|
static std::string_view get_expect_str(const DExpectSymbolSsm & self) noexcept;
|
||||||
|
|
||||||
// non-const methods
|
// non-const methods
|
||||||
/** update stat machine for incoming parsed symbol @p sym **/
|
/** operate state machine for incoming symbol-token @p tk **/
|
||||||
static void on_parsed_symbol(DExpectSymbolSsm & self, std::string_view sym, ParserStateMachine * p_psm);
|
static void on_symbol_token(DExpectSymbolSsm & self, const Token & tk, ParserStateMachine * p_psm);
|
||||||
/** update state machine for incoming define-keyword-token @p tk **/
|
/** update state machine for incoming define-keyword-token @p tk **/
|
||||||
static void on_def_token(DExpectSymbolSsm & self, const Token & tk, ParserStateMachine * p_psm);
|
static void on_def_token(DExpectSymbolSsm & self, const Token & tk, ParserStateMachine * p_psm);
|
||||||
/** update state machine for incoming if-keyword-token @p tk **/
|
/** update state machine for incoming if-keyword-token @p tk **/
|
||||||
static void on_if_token(DExpectSymbolSsm & self, const Token & tk, ParserStateMachine * p_psm);
|
static void on_if_token(DExpectSymbolSsm & self, const Token & tk, ParserStateMachine * p_psm);
|
||||||
|
/** update stat machine for incoming parsed symbol @p sym **/
|
||||||
|
static void on_parsed_symbol(DExpectSymbolSsm & self, std::string_view sym, ParserStateMachine * p_psm);
|
||||||
///@}
|
///@}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
*
|
*
|
||||||
* Generated automagically from ingredients:
|
* Generated automagically from ingredients:
|
||||||
* 1. code generator:
|
* 1. code generator:
|
||||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||||
* arguments:
|
* arguments:
|
||||||
* --input [idl/ISyntaxStateMachine_DExprSeqState.json5]
|
* --input [idl/ISyntaxStateMachine_DExprSeqState.json5]
|
||||||
* 2. jinja2 template for abstract facet .hpp file:
|
* 2. jinja2 template for abstract facet .hpp file:
|
||||||
|
|
@ -53,12 +53,14 @@ namespace xo {
|
||||||
static std::string_view get_expect_str(const DExprSeqState & self) noexcept;
|
static std::string_view get_expect_str(const DExprSeqState & self) noexcept;
|
||||||
|
|
||||||
// non-const methods
|
// non-const methods
|
||||||
/** update stat machine for incoming parsed symbol @p sym **/
|
/** operate state machine for incoming symbol-token @p tk **/
|
||||||
static void on_parsed_symbol(DExprSeqState & self, std::string_view sym, ParserStateMachine * p_psm);
|
static void on_symbol_token(DExprSeqState & self, const Token & tk, ParserStateMachine * p_psm);
|
||||||
/** update state machine for incoming define-keyword-token @p tk **/
|
/** update state machine for incoming define-keyword-token @p tk **/
|
||||||
static void on_def_token(DExprSeqState & self, const Token & tk, ParserStateMachine * p_psm);
|
static void on_def_token(DExprSeqState & self, const Token & tk, ParserStateMachine * p_psm);
|
||||||
/** update state machine for incoming if-keyword-token @p tk **/
|
/** update state machine for incoming if-keyword-token @p tk **/
|
||||||
static void on_if_token(DExprSeqState & self, const Token & tk, ParserStateMachine * p_psm);
|
static void on_if_token(DExprSeqState & self, const Token & tk, ParserStateMachine * p_psm);
|
||||||
|
/** update stat machine for incoming parsed symbol @p sym **/
|
||||||
|
static void on_parsed_symbol(DExprSeqState & self, std::string_view sym, ParserStateMachine * p_psm);
|
||||||
///@}
|
///@}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
*
|
*
|
||||||
* Generated automagically from ingredients:
|
* Generated automagically from ingredients:
|
||||||
* 1. code generator:
|
* 1. code generator:
|
||||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||||
* arguments:
|
* arguments:
|
||||||
* --input [idl/SyntaxStateMachine.json5]
|
* --input [idl/SyntaxStateMachine.json5]
|
||||||
* 2. jinja2 template for abstract facet .hpp file:
|
* 2. jinja2 template for abstract facet .hpp file:
|
||||||
|
|
@ -50,8 +50,8 @@ namespace scm {
|
||||||
}
|
}
|
||||||
|
|
||||||
// non-const methods
|
// non-const methods
|
||||||
void on_parsed_symbol(Opaque data, std::string_view sym, ParserStateMachine * p_psm) override {
|
void on_symbol_token(Opaque data, const Token & tk, ParserStateMachine * p_psm) override {
|
||||||
return I::on_parsed_symbol(_dcast(data), sym, p_psm);
|
return I::on_symbol_token(_dcast(data), tk, p_psm);
|
||||||
}
|
}
|
||||||
void on_def_token(Opaque data, const Token & tk, ParserStateMachine * p_psm) override {
|
void on_def_token(Opaque data, const Token & tk, ParserStateMachine * p_psm) override {
|
||||||
return I::on_def_token(_dcast(data), tk, p_psm);
|
return I::on_def_token(_dcast(data), tk, p_psm);
|
||||||
|
|
@ -59,6 +59,9 @@ namespace scm {
|
||||||
void on_if_token(Opaque data, const Token & tk, ParserStateMachine * p_psm) override {
|
void on_if_token(Opaque data, const Token & tk, ParserStateMachine * p_psm) override {
|
||||||
return I::on_if_token(_dcast(data), tk, p_psm);
|
return I::on_if_token(_dcast(data), tk, p_psm);
|
||||||
}
|
}
|
||||||
|
void on_parsed_symbol(Opaque data, std::string_view sym, ParserStateMachine * p_psm) override {
|
||||||
|
return I::on_parsed_symbol(_dcast(data), sym, p_psm);
|
||||||
|
}
|
||||||
|
|
||||||
///@}
|
///@}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
*
|
*
|
||||||
* Generated automagically from ingredients:
|
* Generated automagically from ingredients:
|
||||||
* 1. code generator:
|
* 1. code generator:
|
||||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||||
* arguments:
|
* arguments:
|
||||||
* --input [idl/SyntaxStateMachine.json5]
|
* --input [idl/SyntaxStateMachine.json5]
|
||||||
* 2. jinja2 template for abstract facet .hpp file:
|
* 2. jinja2 template for abstract facet .hpp file:
|
||||||
|
|
@ -55,8 +55,8 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
// non-const methods (still const in router!)
|
// non-const methods (still const in router!)
|
||||||
void on_parsed_symbol(std::string_view sym, ParserStateMachine * p_psm) {
|
void on_symbol_token(const Token & tk, ParserStateMachine * p_psm) {
|
||||||
return O::iface()->on_parsed_symbol(O::data(), sym, p_psm);
|
return O::iface()->on_symbol_token(O::data(), tk, p_psm);
|
||||||
}
|
}
|
||||||
void on_def_token(const Token & tk, ParserStateMachine * p_psm) {
|
void on_def_token(const Token & tk, ParserStateMachine * p_psm) {
|
||||||
return O::iface()->on_def_token(O::data(), tk, p_psm);
|
return O::iface()->on_def_token(O::data(), tk, p_psm);
|
||||||
|
|
@ -64,6 +64,9 @@ public:
|
||||||
void on_if_token(const Token & tk, ParserStateMachine * p_psm) {
|
void on_if_token(const Token & tk, ParserStateMachine * p_psm) {
|
||||||
return O::iface()->on_if_token(O::data(), tk, p_psm);
|
return O::iface()->on_if_token(O::data(), tk, p_psm);
|
||||||
}
|
}
|
||||||
|
void on_parsed_symbol(std::string_view sym, ParserStateMachine * p_psm) {
|
||||||
|
return O::iface()->on_parsed_symbol(O::data(), sym, p_psm);
|
||||||
|
}
|
||||||
|
|
||||||
///@}
|
///@}
|
||||||
/** @defgroup scm-syntaxstatemachine-member-vars **/
|
/** @defgroup scm-syntaxstatemachine-member-vars **/
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
/** @file DDefineSsm.cpp
|
/** @file DDefineSsm.cpp
|
||||||
*
|
*
|
||||||
* @author Roland Conybeare, Jan 2026
|
* @author Roland Conybeare, Jan 2026
|
||||||
**/
|
**/
|
||||||
|
|
||||||
#include "DDefineSsm.hpp"
|
#include "DDefineSsm.hpp"
|
||||||
|
#include "DExpectSymbolSsm.hpp"
|
||||||
#include "ssm/ISyntaxStateMachine_DDefineSsm.hpp"
|
#include "ssm/ISyntaxStateMachine_DDefineSsm.hpp"
|
||||||
|
|
||||||
#ifdef NOT_YET
|
#ifdef NOT_YET
|
||||||
|
|
@ -328,28 +329,33 @@ namespace xo {
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
DDefineSsm::DDefineSsm()
|
DDefineSsm::DDefineSsm(DDefineExpr * def_expr)
|
||||||
: defstate_{defexprstatetype::def_0}
|
: defstate_{defexprstatetype::def_0},
|
||||||
|
def_expr_{def_expr}
|
||||||
{}
|
{}
|
||||||
|
|
||||||
DDefineSsm *
|
DDefineSsm *
|
||||||
DDefineSsm::make(DArena & mm)
|
DDefineSsm::make(DArena & mm,
|
||||||
|
DDefineExpr * def_expr)
|
||||||
{
|
{
|
||||||
void * mem = mm.alloc(typeseq::id<DDefineSsm>(),
|
void * mem = mm.alloc(typeseq::id<DDefineSsm>(),
|
||||||
sizeof(DDefineSsm));
|
sizeof(DDefineSsm));
|
||||||
|
|
||||||
return new (mem) DDefineSsm();
|
return new (mem) DDefineSsm(def_expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
DDefineSsm::start(DArena & mm,
|
DDefineSsm::start(DArena & mm,
|
||||||
|
obj<AAllocator> expr_mm,
|
||||||
ParserStateMachine * p_psm)
|
ParserStateMachine * p_psm)
|
||||||
{
|
{
|
||||||
//scope log(XO_DEBUG(p_psm->debug_flag()));
|
//scope log(XO_DEBUG(p_psm->debug_flag()));
|
||||||
|
|
||||||
assert(p_psm->stack());
|
assert(p_psm->stack());
|
||||||
|
|
||||||
DDefineSsm * define_ssm = DDefineSsm::make(mm);
|
DDefineExpr * def_expr = DDefineExpr::make_empty(expr_mm);
|
||||||
|
|
||||||
|
DDefineSsm * define_ssm = DDefineSsm::make(mm, def_expr);
|
||||||
|
|
||||||
obj<ASyntaxStateMachine> ssm
|
obj<ASyntaxStateMachine> ssm
|
||||||
= with_facet<ASyntaxStateMachine>::mkobj(define_ssm);
|
= with_facet<ASyntaxStateMachine>::mkobj(define_ssm);
|
||||||
|
|
@ -387,7 +393,7 @@ namespace xo {
|
||||||
case defexprstatetype::def_0:
|
case defexprstatetype::def_0:
|
||||||
case defexprstatetype::n_defexprstatetype:
|
case defexprstatetype::n_defexprstatetype:
|
||||||
assert(false); // impossible
|
assert(false); // impossible
|
||||||
return nullptr;
|
return "impossible!?";
|
||||||
case defexprstatetype::def_1:
|
case defexprstatetype::def_1:
|
||||||
return "symbol";
|
return "symbol";
|
||||||
case defexprstatetype::def_2:
|
case defexprstatetype::def_2:
|
||||||
|
|
@ -409,11 +415,57 @@ namespace xo {
|
||||||
DDefineSsm::on_parsed_symbol(std::string_view sym,
|
DDefineSsm::on_parsed_symbol(std::string_view sym,
|
||||||
ParserStateMachine * p_psm)
|
ParserStateMachine * p_psm)
|
||||||
{
|
{
|
||||||
|
if (this->defstate_ == defexprstatetype::def_1) {
|
||||||
|
this->defstate_ = defexprstatetype::def_2;
|
||||||
|
|
||||||
|
def_expr_.data()->assign_lhs_name(sym);
|
||||||
|
|
||||||
|
// if this is a genuine top-level define (i.e. nesting level = 0),
|
||||||
|
// then we need to upsert so we can refer to rhs later.
|
||||||
|
//
|
||||||
|
// In other contexts (e.g. body-of-lambda) will be rewriting
|
||||||
|
// {
|
||||||
|
// def y = foo(x,x);
|
||||||
|
// bar(y,y);
|
||||||
|
// }
|
||||||
|
// into something like
|
||||||
|
// {
|
||||||
|
// (lambda (y123) bar(y123,y123))(foo(x,x));
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// This works in the body of lambda, because we don't evaluate anything
|
||||||
|
// until lambda definition is complete.
|
||||||
|
//
|
||||||
|
// For interactive top-level defs we want to evaluate as we go,
|
||||||
|
// so need incremental bindings.
|
||||||
|
|
||||||
|
if (p_psm->is_at_toplevel()) {
|
||||||
|
/** remember variable binding in current lexical context **/
|
||||||
|
p_psm->upsert_var(def_expr_.data()->lhs());
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
p_psm->illegal_input_on_symbol("DDefineSsm::on_parsed_symbol",
|
p_psm->illegal_input_on_symbol("DDefineSsm::on_parsed_symbol",
|
||||||
sym,
|
sym,
|
||||||
this->get_expect_str());
|
this->get_expect_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
DDefineSsm::on_symbol_token(const Token & tk,
|
||||||
|
ParserStateMachine * p_psm)
|
||||||
|
{
|
||||||
|
// note:
|
||||||
|
// in state def_1, DDefineSsm learns symbol via .on_parsed_symbol().
|
||||||
|
// symbol token arriving here means encountered symbol while
|
||||||
|
// in some other, which can't happen for valid Schematika input
|
||||||
|
|
||||||
|
p_psm->illegal_input_on_token("DDefineSssm::on_symbol_token",
|
||||||
|
tk,
|
||||||
|
this->get_expect_str());
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
DDefineSsm::on_def_token(const Token & tk,
|
DDefineSsm::on_def_token(const Token & tk,
|
||||||
ParserStateMachine * p_psm)
|
ParserStateMachine * p_psm)
|
||||||
|
|
@ -421,7 +473,8 @@ namespace xo {
|
||||||
if (this->defstate_ == defexprstatetype::def_0) {
|
if (this->defstate_ == defexprstatetype::def_0) {
|
||||||
this->defstate_ = defexprstatetype::def_1;
|
this->defstate_ = defexprstatetype::def_1;
|
||||||
|
|
||||||
// expect_symbol_xs::start(p_psm->parser_alloc(), p_psm);
|
DExpectSymbolSsm::start(p_psm->parser_alloc(), p_psm);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
p_psm->illegal_input_on_token("DDefineSsm::on_define_token",
|
p_psm->illegal_input_on_token("DDefineSsm::on_define_token",
|
||||||
|
|
|
||||||
|
|
@ -74,13 +74,48 @@ namespace xo {
|
||||||
return "impossible-DExprSeqState::get_expr_str";
|
return "impossible-DExprSeqState::get_expr_str";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
DExprSeqState::on_symbol_token(const Token & tk,
|
||||||
|
ParserStateMachine * p_psm)
|
||||||
|
{
|
||||||
|
switch (seqtype_) {
|
||||||
|
case exprseqtype::toplevel_interactive:
|
||||||
|
{
|
||||||
|
#ifdef NOT_YET
|
||||||
|
obj<AExpression,DVariable> var = p_psm->lookup_var(tk.text());
|
||||||
|
|
||||||
|
if (var) {
|
||||||
|
DProgressSsm::start(var, p_psm);
|
||||||
|
} else {
|
||||||
|
p_psm->unknown_variable_error("DExprSeqState::on_symbol_token",
|
||||||
|
tk,
|
||||||
|
this->get_expect_str(),
|
||||||
|
p_psm);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case exprseqtype::toplevel_batch:
|
||||||
|
break;
|
||||||
|
case exprseqtype::N:
|
||||||
|
assert(false); // unreachable
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
p_psm->illegal_input_on_token("DExprSeqState::on_symbol_token",
|
||||||
|
tk,
|
||||||
|
this->get_expect_str());
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
DExprSeqState::on_def_token(const Token & tk,
|
DExprSeqState::on_def_token(const Token & tk,
|
||||||
ParserStateMachine * p_psm)
|
ParserStateMachine * p_psm)
|
||||||
{
|
{
|
||||||
(void)tk;
|
(void)tk;
|
||||||
|
|
||||||
DDefineSsm::start(p_psm->parser_alloc(), p_psm);
|
DDefineSsm::start(p_psm->parser_alloc(),
|
||||||
|
p_psm->expr_alloc(),
|
||||||
|
p_psm);
|
||||||
|
|
||||||
/* keyword 'def' introduces a definition:
|
/* keyword 'def' introduces a definition:
|
||||||
* def pi : f64 = 3.14159265
|
* def pi : f64 = 3.14159265
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ ISyntaxStateMachine_Any::_valid
|
||||||
// nonconst methods
|
// nonconst methods
|
||||||
|
|
||||||
auto
|
auto
|
||||||
ISyntaxStateMachine_Any::on_parsed_symbol(Opaque, std::string_view, ParserStateMachine *) -> void
|
ISyntaxStateMachine_Any::on_symbol_token(Opaque, const Token &, ParserStateMachine *) -> void
|
||||||
{
|
{
|
||||||
_fatal();
|
_fatal();
|
||||||
}
|
}
|
||||||
|
|
@ -52,6 +52,12 @@ ISyntaxStateMachine_Any::on_if_token(Opaque, const Token &, ParserStateMachine *
|
||||||
_fatal();
|
_fatal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto
|
||||||
|
ISyntaxStateMachine_Any::on_parsed_symbol(Opaque, std::string_view, ParserStateMachine *) -> void
|
||||||
|
{
|
||||||
|
_fatal();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} /*namespace scm*/
|
} /*namespace scm*/
|
||||||
} /*namespace xo*/
|
} /*namespace xo*/
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
*
|
*
|
||||||
* Generated automagically from ingredients:
|
* Generated automagically from ingredients:
|
||||||
* 1. code generator:
|
* 1. code generator:
|
||||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||||
* arguments:
|
* arguments:
|
||||||
* --input [idl/ISyntaxStateMachine_DDefineSsm.json5]
|
* --input [idl/ISyntaxStateMachine_DDefineSsm.json5]
|
||||||
* 2. jinja2 template for abstract facet .hpp file:
|
* 2. jinja2 template for abstract facet .hpp file:
|
||||||
|
|
@ -28,9 +28,9 @@ namespace xo {
|
||||||
}
|
}
|
||||||
|
|
||||||
auto
|
auto
|
||||||
ISyntaxStateMachine_DDefineSsm::on_parsed_symbol(DDefineSsm & self, std::string_view sym, ParserStateMachine * p_psm) -> void
|
ISyntaxStateMachine_DDefineSsm::on_symbol_token(DDefineSsm & self, const Token & tk, ParserStateMachine * p_psm) -> void
|
||||||
{
|
{
|
||||||
self.on_parsed_symbol(sym, p_psm);
|
self.on_symbol_token(tk, p_psm);
|
||||||
}
|
}
|
||||||
auto
|
auto
|
||||||
ISyntaxStateMachine_DDefineSsm::on_def_token(DDefineSsm & self, const Token & tk, ParserStateMachine * p_psm) -> void
|
ISyntaxStateMachine_DDefineSsm::on_def_token(DDefineSsm & self, const Token & tk, ParserStateMachine * p_psm) -> void
|
||||||
|
|
@ -42,6 +42,11 @@ namespace xo {
|
||||||
{
|
{
|
||||||
self.on_if_token(tk, p_psm);
|
self.on_if_token(tk, p_psm);
|
||||||
}
|
}
|
||||||
|
auto
|
||||||
|
ISyntaxStateMachine_DDefineSsm::on_parsed_symbol(DDefineSsm & self, std::string_view sym, ParserStateMachine * p_psm) -> void
|
||||||
|
{
|
||||||
|
self.on_parsed_symbol(sym, p_psm);
|
||||||
|
}
|
||||||
|
|
||||||
} /*namespace scm*/
|
} /*namespace scm*/
|
||||||
} /*namespace xo*/
|
} /*namespace xo*/
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
*
|
*
|
||||||
* Generated automagically from ingredients:
|
* Generated automagically from ingredients:
|
||||||
* 1. code generator:
|
* 1. code generator:
|
||||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||||
* arguments:
|
* arguments:
|
||||||
* --input [idl/ISyntaxStateMachine_DExpectSymbolSsm.json5]
|
* --input [idl/ISyntaxStateMachine_DExpectSymbolSsm.json5]
|
||||||
* 2. jinja2 template for abstract facet .hpp file:
|
* 2. jinja2 template for abstract facet .hpp file:
|
||||||
|
|
@ -28,9 +28,9 @@ namespace xo {
|
||||||
}
|
}
|
||||||
|
|
||||||
auto
|
auto
|
||||||
ISyntaxStateMachine_DExpectSymbolSsm::on_parsed_symbol(DExpectSymbolSsm & self, std::string_view sym, ParserStateMachine * p_psm) -> void
|
ISyntaxStateMachine_DExpectSymbolSsm::on_symbol_token(DExpectSymbolSsm & self, const Token & tk, ParserStateMachine * p_psm) -> void
|
||||||
{
|
{
|
||||||
self.on_parsed_symbol(sym, p_psm);
|
self.on_symbol_token(tk, p_psm);
|
||||||
}
|
}
|
||||||
auto
|
auto
|
||||||
ISyntaxStateMachine_DExpectSymbolSsm::on_def_token(DExpectSymbolSsm & self, const Token & tk, ParserStateMachine * p_psm) -> void
|
ISyntaxStateMachine_DExpectSymbolSsm::on_def_token(DExpectSymbolSsm & self, const Token & tk, ParserStateMachine * p_psm) -> void
|
||||||
|
|
@ -42,6 +42,11 @@ namespace xo {
|
||||||
{
|
{
|
||||||
self.on_if_token(tk, p_psm);
|
self.on_if_token(tk, p_psm);
|
||||||
}
|
}
|
||||||
|
auto
|
||||||
|
ISyntaxStateMachine_DExpectSymbolSsm::on_parsed_symbol(DExpectSymbolSsm & self, std::string_view sym, ParserStateMachine * p_psm) -> void
|
||||||
|
{
|
||||||
|
self.on_parsed_symbol(sym, p_psm);
|
||||||
|
}
|
||||||
|
|
||||||
} /*namespace scm*/
|
} /*namespace scm*/
|
||||||
} /*namespace xo*/
|
} /*namespace xo*/
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
*
|
*
|
||||||
* Generated automagically from ingredients:
|
* Generated automagically from ingredients:
|
||||||
* 1. code generator:
|
* 1. code generator:
|
||||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||||
* arguments:
|
* arguments:
|
||||||
* --input [idl/ISyntaxStateMachine_DExprSeqState.json5]
|
* --input [idl/ISyntaxStateMachine_DExprSeqState.json5]
|
||||||
* 2. jinja2 template for abstract facet .hpp file:
|
* 2. jinja2 template for abstract facet .hpp file:
|
||||||
|
|
@ -28,9 +28,9 @@ namespace xo {
|
||||||
}
|
}
|
||||||
|
|
||||||
auto
|
auto
|
||||||
ISyntaxStateMachine_DExprSeqState::on_parsed_symbol(DExprSeqState & self, std::string_view sym, ParserStateMachine * p_psm) -> void
|
ISyntaxStateMachine_DExprSeqState::on_symbol_token(DExprSeqState & self, const Token & tk, ParserStateMachine * p_psm) -> void
|
||||||
{
|
{
|
||||||
self.on_parsed_symbol(sym, p_psm);
|
self.on_symbol_token(tk, p_psm);
|
||||||
}
|
}
|
||||||
auto
|
auto
|
||||||
ISyntaxStateMachine_DExprSeqState::on_def_token(DExprSeqState & self, const Token & tk, ParserStateMachine * p_psm) -> void
|
ISyntaxStateMachine_DExprSeqState::on_def_token(DExprSeqState & self, const Token & tk, ParserStateMachine * p_psm) -> void
|
||||||
|
|
@ -42,6 +42,11 @@ namespace xo {
|
||||||
{
|
{
|
||||||
self.on_if_token(tk, p_psm);
|
self.on_if_token(tk, p_psm);
|
||||||
}
|
}
|
||||||
|
auto
|
||||||
|
ISyntaxStateMachine_DExprSeqState::on_parsed_symbol(DExprSeqState & self, std::string_view sym, ParserStateMachine * p_psm) -> void
|
||||||
|
{
|
||||||
|
self.on_parsed_symbol(sym, p_psm);
|
||||||
|
}
|
||||||
|
|
||||||
} /*namespace scm*/
|
} /*namespace scm*/
|
||||||
} /*namespace xo*/
|
} /*namespace xo*/
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ namespace xo {
|
||||||
|
|
||||||
namespace scm {
|
namespace scm {
|
||||||
ParserStateMachine::ParserStateMachine(const ArenaConfig & config,
|
ParserStateMachine::ParserStateMachine(const ArenaConfig & config,
|
||||||
obj<AAllocator> * expr_alloc)
|
obj<AAllocator> expr_alloc)
|
||||||
: parser_alloc_{DArena::map(config)},
|
: parser_alloc_{DArena::map(config)},
|
||||||
expr_alloc_{expr_alloc},
|
expr_alloc_{expr_alloc},
|
||||||
debug_flag_{config.debug_flag_}
|
debug_flag_{config.debug_flag_}
|
||||||
|
|
@ -70,6 +70,13 @@ namespace xo {
|
||||||
this->stack_ = ParserStack::pop(stack_, parser_alloc_);
|
this->stack_ = ParserStack::pop(stack_, parser_alloc_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ParserStateMachine::upsert_var(DVariable * var)
|
||||||
|
{
|
||||||
|
scope log(XO_DEBUG(true), "stub impl");
|
||||||
|
log && log(xtag("var", std::string_view(*(var->name()))));
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParserStateMachine::reset_result()
|
ParserStateMachine::reset_result()
|
||||||
{
|
{
|
||||||
|
|
@ -111,6 +118,10 @@ namespace xo {
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (tk.tk_type()) {
|
switch (tk.tk_type()) {
|
||||||
|
case tokentype::tk_symbol:
|
||||||
|
this->on_symbol_token(tk);
|
||||||
|
break;
|
||||||
|
|
||||||
case tokentype::tk_def:
|
case tokentype::tk_def:
|
||||||
this->on_def_token(tk);
|
this->on_def_token(tk);
|
||||||
break;
|
break;
|
||||||
|
|
@ -125,7 +136,6 @@ namespace xo {
|
||||||
case tokentype::tk_i64:
|
case tokentype::tk_i64:
|
||||||
case tokentype::tk_f64:
|
case tokentype::tk_f64:
|
||||||
case tokentype::tk_string:
|
case tokentype::tk_string:
|
||||||
case tokentype::tk_symbol:
|
|
||||||
case tokentype::tk_leftparen:
|
case tokentype::tk_leftparen:
|
||||||
case tokentype::tk_rightparen:
|
case tokentype::tk_rightparen:
|
||||||
case tokentype::tk_leftbracket:
|
case tokentype::tk_leftbracket:
|
||||||
|
|
@ -165,6 +175,14 @@ namespace xo {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ParserStateMachine::on_symbol_token(const Token & tk)
|
||||||
|
{
|
||||||
|
scope log(XO_DEBUG(debug_flag_), xtag("tk", tk));
|
||||||
|
|
||||||
|
stack_->top().on_symbol_token(tk, this);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ParserStateMachine::on_def_token(const Token & tk)
|
ParserStateMachine::on_def_token(const Token & tk)
|
||||||
{
|
{
|
||||||
|
|
@ -205,7 +223,7 @@ namespace xo {
|
||||||
|
|
||||||
assert(expr_alloc_);
|
assert(expr_alloc_);
|
||||||
|
|
||||||
auto errmsg = DString::from_view(*expr_alloc_,
|
auto errmsg = DString::from_view(expr_alloc_,
|
||||||
std::string_view(errmsg_string));
|
std::string_view(errmsg_string));
|
||||||
|
|
||||||
this->capture_error(ssm_name, errmsg);
|
this->capture_error(ssm_name, errmsg);
|
||||||
|
|
@ -228,7 +246,7 @@ namespace xo {
|
||||||
|
|
||||||
assert(expr_alloc_);
|
assert(expr_alloc_);
|
||||||
|
|
||||||
auto errmsg = DString::from_view(*expr_alloc_,
|
auto errmsg = DString::from_view(expr_alloc_,
|
||||||
std::string_view(errmsg_string));
|
std::string_view(errmsg_string));
|
||||||
|
|
||||||
this->capture_error(ssm_name, errmsg);
|
this->capture_error(ssm_name, errmsg);
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ namespace xo {
|
||||||
// ----- SchematikaParser -----
|
// ----- SchematikaParser -----
|
||||||
|
|
||||||
SchematikaParser::SchematikaParser(const ArenaConfig & config,
|
SchematikaParser::SchematikaParser(const ArenaConfig & config,
|
||||||
obj<AAllocator> * expr_alloc,
|
obj<AAllocator> expr_alloc,
|
||||||
bool debug_flag)
|
bool debug_flag)
|
||||||
: psm_{config, expr_alloc},
|
: psm_{config, expr_alloc},
|
||||||
debug_flag_{debug_flag}
|
debug_flag_{debug_flag}
|
||||||
|
|
@ -38,13 +38,13 @@ namespace xo {
|
||||||
|
|
||||||
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_);
|
||||||
}
|
}
|
||||||
|
|
||||||
const ParserResult &
|
const ParserResult &
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ namespace xo {
|
||||||
DArena expr_arena = DArena::map(config);
|
DArena expr_arena = DArena::map(config);
|
||||||
obj<AAllocator> expr_alloc = with_facet<AAllocator>::mkobj(&expr_arena);
|
obj<AAllocator> expr_alloc = with_facet<AAllocator>::mkobj(&expr_arena);
|
||||||
|
|
||||||
SchematikaParser parser(config, &expr_alloc, false /*debug_flag*/);
|
SchematikaParser parser(config, expr_alloc, false /*debug_flag*/);
|
||||||
|
|
||||||
REQUIRE(parser.debug_flag() == false);
|
REQUIRE(parser.debug_flag() == false);
|
||||||
REQUIRE(parser.is_at_toplevel() == true);
|
REQUIRE(parser.is_at_toplevel() == true);
|
||||||
|
|
@ -42,7 +42,7 @@ namespace xo {
|
||||||
DArena expr_arena = DArena::map(config);
|
DArena expr_arena = DArena::map(config);
|
||||||
obj<AAllocator> expr_alloc = with_facet<AAllocator>::mkobj(&expr_arena);
|
obj<AAllocator> expr_alloc = with_facet<AAllocator>::mkobj(&expr_arena);
|
||||||
|
|
||||||
SchematikaParser parser(config, &expr_alloc, false /*debug_flag*/);
|
SchematikaParser parser(config, expr_alloc, false /*debug_flag*/);
|
||||||
|
|
||||||
parser.begin_interactive_session();
|
parser.begin_interactive_session();
|
||||||
|
|
||||||
|
|
@ -60,7 +60,7 @@ namespace xo {
|
||||||
DArena expr_arena = DArena::map(config);
|
DArena expr_arena = DArena::map(config);
|
||||||
obj<AAllocator> expr_alloc = with_facet<AAllocator>::mkobj(&expr_arena);
|
obj<AAllocator> expr_alloc = with_facet<AAllocator>::mkobj(&expr_arena);
|
||||||
|
|
||||||
SchematikaParser parser(config, &expr_alloc, false /*debug_flag*/);
|
SchematikaParser parser(config, expr_alloc, false /*debug_flag*/);
|
||||||
|
|
||||||
parser.begin_batch_session();
|
parser.begin_batch_session();
|
||||||
|
|
||||||
|
|
@ -78,20 +78,30 @@ namespace xo {
|
||||||
DArena expr_arena = DArena::map(config);
|
DArena expr_arena = DArena::map(config);
|
||||||
obj<AAllocator> expr_alloc = with_facet<AAllocator>::mkobj(&expr_arena);
|
obj<AAllocator> expr_alloc = with_facet<AAllocator>::mkobj(&expr_arena);
|
||||||
|
|
||||||
SchematikaParser parser(config, &expr_alloc, false /*debug_flag*/);
|
SchematikaParser parser(config, expr_alloc, false /*debug_flag*/);
|
||||||
|
|
||||||
parser.begin_batch_session();
|
parser.begin_batch_session();
|
||||||
|
|
||||||
auto & result = parser.on_token(Token::def_token());
|
{
|
||||||
|
auto & result = parser.on_token(Token::def_token());
|
||||||
|
|
||||||
|
// after begin_interactive_session, parser has toplevel exprseq
|
||||||
|
// but is still "at toplevel" in the sense of ready for input
|
||||||
|
REQUIRE(parser.has_incomplete_expr() == true);
|
||||||
|
REQUIRE(result.is_incomplete());
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
auto & result = parser.on_token(Token::symbol_token("foo"));
|
||||||
|
|
||||||
|
REQUIRE(parser.has_incomplete_expr() == true);
|
||||||
|
REQUIRE(result.is_error());
|
||||||
|
}
|
||||||
|
|
||||||
// define-expressions not properly implemented
|
// define-expressions not properly implemented
|
||||||
|
|
||||||
// after begin_interactive_session, parser has toplevel exprseq
|
|
||||||
// but is still "at toplevel" in the sense of ready for input
|
|
||||||
REQUIRE(parser.has_incomplete_expr() == true);
|
|
||||||
REQUIRE(result.is_error());
|
|
||||||
|
|
||||||
REQUIRE(result.error_description());
|
//REQUIRE(result.error_description());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("SchematikaParser-interactive-if", "[reader2][SchematikaParser]")
|
TEST_CASE("SchematikaParser-interactive-if", "[reader2][SchematikaParser]")
|
||||||
|
|
@ -103,7 +113,7 @@ namespace xo {
|
||||||
DArena expr_arena = DArena::map(config);
|
DArena expr_arena = DArena::map(config);
|
||||||
obj<AAllocator> expr_alloc = with_facet<AAllocator>::mkobj(&expr_arena);
|
obj<AAllocator> expr_alloc = with_facet<AAllocator>::mkobj(&expr_arena);
|
||||||
|
|
||||||
SchematikaParser parser(config, &expr_alloc, false /*debug_flag*/);
|
SchematikaParser parser(config, expr_alloc, false /*debug_flag*/);
|
||||||
|
|
||||||
parser.begin_interactive_session();
|
parser.begin_interactive_session();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue