xo-reader2: working on example parser repl

This commit is contained in:
Roland Conybeare 2026-01-22 21:03:40 -05:00
commit 8c038ed669
8 changed files with 393 additions and 2 deletions

View file

@ -67,7 +67,7 @@ namespace xo {
/** pretty-printing support **/
bool pretty(const ppindentinfo & ppii) const;
private:
public:
/** none|expression|error_description
*
* @text

View file

@ -0,0 +1,54 @@
/** @file ReaderConfig.hpp
*
* @author Roland Conybeare, Jan 2026
**/
#pragma once
#include <xo/arena/CircularBufferConfig.hpp>
#include <xo/arena/ArenaConfig.hpp>
namespace xo {
namespace scm {
/** @brief Configuration for SchemtikaReader
**/
struct ReaderConfig {
using CircularBufferConfig = xo::mm::CircularBufferConfig;
using ArenaConfig = xo::mm::ArenaConfig;
using size_t = std::size_t;
/** tokenizer circular buffer config **/
CircularBufferConfig tk_buffer_config_ {.name_ = "tk-buffer",
.max_capacity_ = 2*1024*1024,
.hugepage_z_ = 2*1024*1024,
.threshold_move_efficiency_ = 50.0,
.max_captured_span_ = 128 };
/** debug flag for schematika tokenizer **/
bool tk_debug_flag_ = false;
/** arena configuration for parser stack **/
ArenaConfig parser_arena_config_ { .name_ = "parer-arena",
.size_ = 2*1024*1024,
.hugepage_z_ = 2*1024*1024,
.store_header_flag_ = false,
.header_{},
.debug_flag_ = false };
/** max size (in bytes) of stringtable **/
size_t max_stringtable_cap_ = 64*1024;
/** debug flag for schematika parser **/
bool parser_debug_flag_ = false;
#ifdef NOT_YET
/** arena configuration for output expressions **/
ArenaConfig expr_arena_config_ { .name_ = "expr-arena",
.size_ = 2*1024*1024,
.hugepage_z_ = 2*1024*1024,
.store_header_flag_ = false,
.header_{},
.debug_flag_ = false };
#endif
};
} /*namespace scm*/
} /*namepspace xo*/
/* end ReaderConfig.hpp */

View file

@ -162,7 +162,7 @@ namespace xo {
/** create parser in initial state;
* parser is ready to receive tokens via @ref include_token
*
* @p config arena configuration for parser memory
* @p config arena configuration for parser stack
* @p expr_alloc allocator for schematika expressions.
* Probably shared with execution.
* @p debug_flag true to enable debug logging

View file

@ -0,0 +1,70 @@
/** @file SchematikaReader.hpp
*
* @author Roland Conybeare, Jan 2026
**/
#pragma once
#include "ReaderConfig.hpp"
#include "SchematikaParser.hpp"
#include <xo/tokenizer2/Tokenizer.hpp>
namespace xo {
namespace scm {
struct ReaderResult {
using span_type = xo::mm::span<const char>;
bool is_tk_error() const { return tk_error_.is_error(); }
/** schematika expression parsed from input **/
obj<AExpression> expr_;
/** input span up to end of expression.
* only relevant when result type is expression.
* (otherwise treat entire input as consumed)
**/
span_type consumed_;
/** {src_function, error_description, input_state, error_pos} **/
TokenizerError tk_error_;
};
/** @class SchematikaReader
* @brief Pipeline comprising Schematika tokenizer and parser
*
* Consumes text; produces expressions
**/
class SchematikaReader {
public:
using AAllocator = xo::mm::AAllocator;
public:
SchematikaReader(const ReaderConfig & config,
obj<AAllocator> expr_alloc);
/** prepare interactive session
* (allows rvalue expressions at toplevel)
**/
void begin_interactive_session();
/** consume input @p input_cstr **/
const ReaderResult & read_expr(const char * input_cstr, bool eof);
private:
/** tokenizer converts a stream of chars
* to a stream of lexical tokens
**/
Tokenizer tokenizer_;
/** parser converts a stream of tokens
* to a stream of expressions
**/
SchematikaParser parser_;
/** current output from reader **/
ReaderResult result_;
};
} /*namespace scm*/
} /*namespace xo*/
/* end SchematikaReader.hpp */