diff --git a/include/xo/parser/reader.hpp b/include/xo/parser/reader.hpp index b36489d6..4009f722 100644 --- a/include/xo/parser/reader.hpp +++ b/include/xo/parser/reader.hpp @@ -31,6 +31,7 @@ namespace xo { * Use: * @code * reader rdr; + * rdr.begin_translation_unit() * * bool eof = false; * while (!eof) { @@ -63,6 +64,22 @@ namespace xo { public: reader() = default; + /** call once before calling .read_expr(): + * 1. with new reader + * 2. if last read_expr() call had eof=true + **/ + void begin_translation_unit(); + + /** counterpart to .begin_translation_unit(), + * provided for symmetry's sake + * + * Equivalent to: + * @code + * read_expr(span_type(nullptr, nullptr), true); + * @endcode + **/ + reader_result end_translation_unit(); + /** Try to read one expression from @p input. * Return struct containing parsed expression * and span of characters comprising that expression diff --git a/src/parser/reader.cpp b/src/parser/reader.cpp index 84d00b30..c24ebf94 100644 --- a/src/parser/reader.cpp +++ b/src/parser/reader.cpp @@ -4,6 +4,16 @@ namespace xo { namespace scm { + void + reader::begin_translation_unit() { + parser_.begin_translation_unit(); + } + + reader_result + reader::end_translation_unit() { + return this->read_expr(span_type(nullptr, nullptr), true /*eof*/); + } + reader_result reader::read_expr(const span_type & input_arg, bool eof) {