From ff471bbc72eb51533a03d73f6c623697e1d8e7a3 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Fri, 27 Mar 2026 11:16:28 -0400 Subject: [PATCH] xo-interpreter2 stack: wrap TokenizerError as DRuntimeError Also fix _read_eval_print() to report them! --- cmake/xo_tokenizer2Config.cmake.in | 1 + include/xo/tokenizer2/TokenizerError.hpp | 6 ++++++ src/tokenizer2/CMakeLists.txt | 1 + src/tokenizer2/TokenizerError.cpp | 14 ++++++++++++++ 4 files changed, 22 insertions(+) diff --git a/cmake/xo_tokenizer2Config.cmake.in b/cmake/xo_tokenizer2Config.cmake.in index eccd2745..0c0dad0b 100644 --- a/cmake/xo_tokenizer2Config.cmake.in +++ b/cmake/xo_tokenizer2Config.cmake.in @@ -6,6 +6,7 @@ include(CMakeFindDependencyMacro) # must coordinate with xo_dependency() calls # in src/tokenizer2/CMakeLists.txt # +find_dependency(xo_stringtable2) find_dependency(xo_arena) find_dependency(indentlog) diff --git a/include/xo/tokenizer2/TokenizerError.hpp b/include/xo/tokenizer2/TokenizerError.hpp index bf7702b1..b08889bd 100644 --- a/include/xo/tokenizer2/TokenizerError.hpp +++ b/include/xo/tokenizer2/TokenizerError.hpp @@ -8,6 +8,8 @@ #include "TkInputState.hpp" #include "tokentype.hpp" #include "span.hpp" +#include +#include #include namespace xo { @@ -19,6 +21,7 @@ namespace xo { **/ class TokenizerError { public: + using AAllocator = xo::mm::AAllocator; using CharT = char; using span_type = xo::mm::span; @@ -89,6 +92,9 @@ namespace xo { /** Print human-oriented error report on @p os. **/ void report(std::ostream & os) const; + /** Similar to report, but capture as string, allocated from @p mm **/ + DString * report_to_string(obj mm) const; + ///@} private: diff --git a/src/tokenizer2/CMakeLists.txt b/src/tokenizer2/CMakeLists.txt index ccf1b551..3a748e70 100644 --- a/src/tokenizer2/CMakeLists.txt +++ b/src/tokenizer2/CMakeLists.txt @@ -11,6 +11,7 @@ set(SELF_SRCS xo_add_shared_library4(${SELF_LIB} ${PROJECT_NAME}Targets ${PROJECT_VERSION} 1 ${SELF_SRCS}) # deps must coordinate with xo-tokenizer/cmake/xo_tokenizer2Config.cmake.in +xo_dependency(${SELF_LIB} xo_stringtable2) xo_dependency(${SELF_LIB} xo_arena) xo_dependency(${SELF_LIB} indentlog) diff --git a/src/tokenizer2/TokenizerError.cpp b/src/tokenizer2/TokenizerError.cpp index ffe3c8b4..c80996d9 100644 --- a/src/tokenizer2/TokenizerError.cpp +++ b/src/tokenizer2/TokenizerError.cpp @@ -54,6 +54,20 @@ namespace xo { } } + DString * + TokenizerError::report_to_string(obj dest_mm) const + { + // FIXME: + // using heap here for scratch space. + // Would prefer to checkpoint + realloc. + + std::stringstream ss; + + this->report(ss); + + return DString::from_str(dest_mm, ss.str()); + } + } /*namespace scm*/ } /*namespace xo*/