xo-reader2 stack: convenience #includes + parsing examples
This commit is contained in:
parent
8f97502677
commit
b994c56bc5
4 changed files with 179 additions and 3 deletions
13
xo-expression2/include/xo/expression2/DefineExpr.hpp
Normal file
13
xo-expression2/include/xo/expression2/DefineExpr.hpp
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
/** @file DefineExpr.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Feb 2026
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "DDefineExpr.hpp"
|
||||
#include "detail/IExpression_DDefineExpr.hpp"
|
||||
//#include "detail/IGCObject_DDefineExpr.hpp"
|
||||
#include "detail/IPrintable_DDefineExpr.hpp"
|
||||
|
||||
/* end DefineExpr.hpp */
|
||||
12
xo-object2/include/xo/object2/Float.hpp
Normal file
12
xo-object2/include/xo/object2/Float.hpp
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
/** @file Float.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Feb 2026
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "DFloat.hpp"
|
||||
#include "number/IGCObject_DFloat.hpp"
|
||||
#include "number/IPrintable_DFloat.hpp"
|
||||
|
||||
/* end Float.hpp */
|
||||
12
xo-object2/include/xo/object2/String.hpp
Normal file
12
xo-object2/include/xo/object2/String.hpp
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
/** @file String.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Feb 22026
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "DString.hpp"
|
||||
#include "string/IGCObject_DString.hpp"
|
||||
#include "string/IPrintable_DString.hpp"
|
||||
|
||||
/* end String.hpp */
|
||||
|
|
@ -9,8 +9,11 @@
|
|||
#include <xo/reader2/ssm/ISyntaxStateMachine_DExpectExprSsm.hpp>
|
||||
#include <xo/reader2/ssm/ISyntaxStateMachine_DDefineSsm.hpp>
|
||||
#include <xo/reader2/init_reader2.hpp>
|
||||
#include <xo/expression2/DefineExpr.hpp>
|
||||
#include <xo/expression2/Constant.hpp>
|
||||
#include <xo/object2/Float.hpp>
|
||||
#include <xo/object2/Integer.hpp>
|
||||
#include <xo/object2/String.hpp>
|
||||
#include <xo/alloc2/arena/IAllocator_DArena.hpp>
|
||||
#include <catch2/catch.hpp>
|
||||
|
||||
|
|
@ -20,15 +23,18 @@ namespace xo {
|
|||
using xo::scm::syntaxstatetype;
|
||||
// using xo::scm::DDefineSsm;
|
||||
using xo::scm::DExpectExprSsm;
|
||||
|
||||
using xo::scm::AExpression;
|
||||
using xo::scm::DDefineExpr;
|
||||
using xo::scm::DConstant;
|
||||
// using xo::scm::defexprstatetype;
|
||||
|
||||
//using xo::scm::ParserResult;
|
||||
//using xo::scm::parser_result_type;
|
||||
using xo::scm::Token;
|
||||
using xo::scm::DString;
|
||||
using xo::scm::DInteger;
|
||||
using xo::mm::AGCObject;
|
||||
using xo::scm::DString;
|
||||
using xo::scm::DFloat;
|
||||
using xo::scm::DInteger;
|
||||
|
||||
using xo::mm::ArenaConfig;
|
||||
using xo::mm::AAllocator;
|
||||
using xo::mm::DArena;
|
||||
|
|
@ -196,6 +202,9 @@ namespace xo {
|
|||
log && log(xtag("result", result));
|
||||
|
||||
REQUIRE(parser.has_incomplete_expr() == false);
|
||||
|
||||
auto expr = obj<AExpression,DDefineExpr>::from(result.result_expr());
|
||||
REQUIRE(expr);
|
||||
}
|
||||
|
||||
// define-expressions not properly implemented
|
||||
|
|
@ -268,6 +277,136 @@ namespace xo {
|
|||
//REQUIRE(result.error_description());
|
||||
}
|
||||
|
||||
TEST_CASE("SchematikaParser-interactive-float", "[reader2][SchematikaParser]")
|
||||
{
|
||||
const auto & testname = Catch::getResultCapture().getCurrentTestName();
|
||||
|
||||
constexpr bool c_debug_flag = true;
|
||||
scope log(XO_DEBUG(c_debug_flag), xtag("test", testname));
|
||||
|
||||
ArenaConfig config;
|
||||
config.name_ = "test-arena";
|
||||
config.size_ = 16 * 1024;
|
||||
|
||||
DArena expr_arena = DArena::map(config);
|
||||
obj<AAllocator> expr_alloc = with_facet<AAllocator>::mkobj(&expr_arena);
|
||||
|
||||
SchematikaParser parser(config, 4096, expr_alloc, false /*debug_flag*/);
|
||||
|
||||
parser.begin_interactive_session();
|
||||
|
||||
/** Walkthrough parsing input equivalent to:
|
||||
*
|
||||
* 3.14159265 ;
|
||||
*
|
||||
**/
|
||||
|
||||
{
|
||||
auto & result = parser.on_token(Token::f64_token("3.14159265"));
|
||||
|
||||
log && log("after float token:");
|
||||
log && log(xtag("parser", &parser));
|
||||
log && log(xtag("result", result));
|
||||
|
||||
REQUIRE(parser.has_incomplete_expr() == true);
|
||||
REQUIRE(!result.is_error());
|
||||
REQUIRE(result.is_incomplete());
|
||||
}
|
||||
|
||||
{
|
||||
auto & result = parser.on_token(Token::semicolon_token());
|
||||
|
||||
log && log("after semicolon token:");
|
||||
log && log(xtag("parser", &parser));
|
||||
log && log(xtag("result", result));
|
||||
|
||||
REQUIRE(parser.has_incomplete_expr() == false);
|
||||
REQUIRE(!result.is_error());
|
||||
REQUIRE(result.is_expression());
|
||||
REQUIRE(result.result_expr());
|
||||
|
||||
auto expr = obj<AExpression,DConstant>::from(result.result_expr());
|
||||
REQUIRE(expr);
|
||||
|
||||
REQUIRE(expr->value());
|
||||
|
||||
auto value_f64 = obj<AGCObject,DFloat>::from(expr->value());
|
||||
|
||||
REQUIRE(value_f64);
|
||||
|
||||
REQUIRE(value_f64->value() == 3.14159265);
|
||||
}
|
||||
|
||||
//REQUIRE(result.is_error());
|
||||
//// illegal input on token
|
||||
//REQUIRE(result.error_description());
|
||||
}
|
||||
|
||||
TEST_CASE("SchematikaParser-interactive-string", "[reader2][SchematikaParser]")
|
||||
{
|
||||
const auto & testname = Catch::getResultCapture().getCurrentTestName();
|
||||
|
||||
constexpr bool c_debug_flag = true;
|
||||
scope log(XO_DEBUG(c_debug_flag), xtag("test", testname));
|
||||
|
||||
ArenaConfig config;
|
||||
config.name_ = "test-arena";
|
||||
config.size_ = 16 * 1024;
|
||||
|
||||
DArena expr_arena = DArena::map(config);
|
||||
obj<AAllocator> expr_alloc = with_facet<AAllocator>::mkobj(&expr_arena);
|
||||
|
||||
SchematikaParser parser(config, 4096, expr_alloc, false /*debug_flag*/);
|
||||
|
||||
parser.begin_interactive_session();
|
||||
|
||||
/** Walkthrough parsing input equivalent to:
|
||||
*
|
||||
* "hello world" ;
|
||||
*
|
||||
**/
|
||||
|
||||
{
|
||||
auto & result = parser.on_token(Token::string_token("hello world"));
|
||||
|
||||
log && log("after string token:");
|
||||
log && log(xtag("parser", &parser));
|
||||
log && log(xtag("result", result));
|
||||
|
||||
REQUIRE(parser.has_incomplete_expr() == true);
|
||||
REQUIRE(!result.is_error());
|
||||
REQUIRE(result.is_incomplete());
|
||||
}
|
||||
|
||||
{
|
||||
auto & result = parser.on_token(Token::semicolon_token());
|
||||
|
||||
log && log("after semicolon token:");
|
||||
log && log(xtag("parser", &parser));
|
||||
log && log(xtag("result", result));
|
||||
|
||||
REQUIRE(parser.has_incomplete_expr() == false);
|
||||
REQUIRE(!result.is_error());
|
||||
REQUIRE(result.is_expression());
|
||||
REQUIRE(result.result_expr());
|
||||
|
||||
auto expr = obj<AExpression,DConstant>::from(result.result_expr());
|
||||
REQUIRE(expr);
|
||||
|
||||
REQUIRE(expr->value());
|
||||
|
||||
auto value_str = obj<AGCObject,DString>::from(expr->value());
|
||||
|
||||
REQUIRE(value_str);
|
||||
|
||||
REQUIRE(strcmp(value_str->chars(), "hello world") == 0);
|
||||
}
|
||||
|
||||
//REQUIRE(result.is_error());
|
||||
//// illegal input on token
|
||||
//REQUIRE(result.error_description());
|
||||
}
|
||||
|
||||
TEST_CASE("SchematikaParser-interactive-lambda", "[reader2][SchematikaParser]")
|
||||
{
|
||||
constexpr bool c_debug_flag = true;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue