xo-tokenizer: example tokenrepl restored to wokring order
Now with CBufferedInput in Tokenizer
This commit is contained in:
parent
1575f8a147
commit
a7ed10c16a
2 changed files with 18 additions and 11 deletions
|
|
@ -51,6 +51,8 @@ main() {
|
|||
using xo::scm::operator<<;
|
||||
using xo::mm::CircularBufferConfig;
|
||||
using xo::mm::span;
|
||||
using xo::scope;
|
||||
using xo::xtag;
|
||||
using replxx::Replxx;
|
||||
|
||||
using namespace std;
|
||||
|
|
@ -65,10 +67,13 @@ main() {
|
|||
rx.set_max_history_size(1000);
|
||||
rx.history_load("repl_history.txt");
|
||||
|
||||
constexpr bool c_debug_flag = true;
|
||||
scope log(XO_DEBUG(c_debug_flag));
|
||||
|
||||
Tokenizer tkz(CircularBufferConfig{.name_ = "tokenrepl-input",
|
||||
.max_capacity_ = 4*1024,
|
||||
.max_captured_span_ = 128},
|
||||
true /*debug_flag*/);
|
||||
c_debug_flag);
|
||||
|
||||
const char * input_cstr = nullptr;;
|
||||
|
||||
|
|
@ -84,9 +89,17 @@ main() {
|
|||
if (input_cstr && *input_cstr) {
|
||||
auto [error, input] = tkz.buffer_input_line(input_cstr, false /*!eof*/);
|
||||
|
||||
if (log) {
|
||||
log(xtag("msg", "buffered input line"));
|
||||
log(xtag("input", input));
|
||||
}
|
||||
|
||||
while (!input.empty())
|
||||
{
|
||||
auto [tk, consumed, error] = tkz.scan(input);
|
||||
|
||||
log && log(xtag("consumed", consumed), xtag("tk", tk));
|
||||
|
||||
if (tk.is_valid()) {
|
||||
cout << tk << endl;
|
||||
} else if (error.is_error()) {
|
||||
|
|
|
|||
|
|
@ -622,15 +622,9 @@ namespace xo {
|
|||
auto buf_input_0 = input_buffer_.input_range().hi();
|
||||
|
||||
auto remainder = input_buffer_.append
|
||||
(DCircularBuffer::const_span_type
|
||||
((const byte *)input_cstr,
|
||||
(const byte *)input_cstr + strlen(input_cstr)));
|
||||
|
||||
const char * newline_cstr = "\n";
|
||||
(DCircularBuffer::const_span_type::from_cstr(input_cstr));
|
||||
auto remainder2 = input_buffer_.append
|
||||
(DCircularBuffer::const_span_type
|
||||
((const byte *)newline_cstr,
|
||||
(const byte *)newline_cstr + strlen(newline_cstr)));
|
||||
(DCircularBuffer::const_span_type::from_cstr("\n"));
|
||||
|
||||
if (!remainder.empty() || !remainder2.empty()) {
|
||||
throw std::runtime_error(tostr("Tokenizer::buffer_line: line too long!",
|
||||
|
|
@ -639,8 +633,8 @@ namespace xo {
|
|||
|
||||
auto buf_input_1 = input_buffer_.input_range().hi();
|
||||
|
||||
span_type input = span_type((const char *)buf_input_0,
|
||||
(const char *)buf_input_1);
|
||||
span_type input = span_type(buf_input_0,
|
||||
buf_input_1);
|
||||
|
||||
return this->input_state_.capture_current_line(input, eof_flag);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue