xo-tokenizer: move to scm ns + print() diagnostic

This commit is contained in:
Roland Conybeare 2024-08-05 14:44:39 -04:00
commit 2d0336058e
8 changed files with 49 additions and 19 deletions

View file

@ -9,7 +9,7 @@
#include <new>
namespace xo {
namespace tok {
namespace scm {
/**
* @class buffer buffer.hpp
*
@ -318,7 +318,7 @@ namespace xo {
swap(buffer<CharT> & lhs, buffer<CharT> & rhs) {
lhs.swap(rhs);
}
} /*namespace tok*/
} /*namespace scm*/
} /*namespace xo*/
/* end buffer.hpp */

View file

@ -7,7 +7,7 @@
#include <cassert>
namespace xo {
namespace tok {
namespace scm {
/** @class span compression/span.hpp
*
* @brief Represents a contiguous memory range, without ownership.
@ -137,5 +137,5 @@ namespace xo {
x.print(os);
return os;
}
} /*namespace tok*/
} /*namespace scm*/
} /*namespace xo*/

View file

@ -8,11 +8,12 @@
#include "tokentype.hpp"
#include "xo/indentlog/print/tag.hpp"
#include <stdexcept>
#include <ostream>
#include <string>
#include <cstdint>
namespace xo {
namespace tok {
namespace scm {
namespace detail {
/* compute a * b^p, p >= 0 */
constexpr double
@ -101,6 +102,9 @@ namespace xo {
**/
double f64_value() const;
/** print human-readable token representation on stream @p os **/
void print(std::ostream & os) const;
private:
/** category for this token **/
tokentype tk_type_ = tokentype::tk_invalid;
@ -327,7 +331,25 @@ namespace xo {
return retval;
} /*f64_value*/
} /*Namespace tok*/
template <typename CharT>
void
token<CharT>::print(std::ostream & os) const {
os << "<token"
<< xtag("type", tk_type_)
<< xtag("text", text_)
<< ">";
} /*print*/
template <typename CharT>
inline std::ostream &
operator<< (std::ostream & os,
const token<CharT> & tk)
{
tk.print(os);
return os;
}
} /*Namespace scm*/
} /*namespace xo*/

View file

@ -11,7 +11,7 @@
#include <cassert>
namespace xo {
namespace tok {
namespace scm {
/**
* Use:
* @code
@ -619,7 +619,7 @@ namespace xo {
return tk;
} /*notify_eof*/
} /*namespace tok*/
} /*namespace scm*/
} /*namespace xo*/
/* end tokenizer.hpp */

View file

@ -9,7 +9,7 @@
#include <ostream>
namespace xo {
namespace tok {
namespace scm {
/** @enum tokentype
* @brief enum to identify different schematica input token types
*
@ -124,6 +124,9 @@ namespace xo {
/** keyword 'in' **/
tk_in,
/** keyword 'end' **/
tk_end,
n_tokentype /* comes last, counts #of entries */
}; /*tokentype*/
@ -135,8 +138,7 @@ namespace xo {
os << tokentype_descr(tk_type);
return os;
}
} /*namespace tok*/
} /*namespace scm*/
} /*namespace xo*/
/* end tokentype.hpp */