module; #include #include #include export module jlx:source_stream; namespace jlx { export template class source_stream { public: using char_traits = std::char_traits; using str = std::basic_string; protected: str::size_type pos = 0; std::size_t line = 1; std::size_t col = 0; const str input; public: source_stream(const str input) : input(std::move(input)){ } std::optional next() { if (pos >= input.length()) { return std::nullopt; } auto ch = input.at(pos++); if(char_traits::to_int_type(ch) == 10) { line += 1; col = 0; } else { col++; } return ch; } std::optional peek() const { if (pos >= input.length()) { return std::nullopt; } return input.at(pos); } bool eof() { return pos >= input.length(); } size_t current_line() const { return line; } size_t current_col() const { return col; } }; }