xo-tokenizer: move to scm ns + print() diagnostic
This commit is contained in:
parent
0af24e9a2c
commit
2d0336058e
8 changed files with 49 additions and 19 deletions
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -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*/
|
||||
|
|
|
|||
|
|
@ -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*/
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
#include "tokentype.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace tok {
|
||||
namespace scm {
|
||||
char const *
|
||||
tokentype_descr(tokentype tk_type)
|
||||
{
|
||||
|
|
@ -18,27 +18,33 @@ namespace xo {
|
|||
CASE(tk_string);
|
||||
CASE(tk_symbol);
|
||||
CASE(tk_leftparen);
|
||||
|
||||
CASE(tk_rightparen);
|
||||
CASE(tk_leftbracket);
|
||||
CASE(tk_rightbracket);
|
||||
CASE(tk_leftbrace);
|
||||
CASE(tk_rightbrace);
|
||||
|
||||
CASE(tk_leftangle);
|
||||
CASE(tk_rightangle);
|
||||
CASE(tk_dot);
|
||||
CASE(tk_comma);
|
||||
CASE(tk_colon);
|
||||
|
||||
CASE(tk_doublecolon);
|
||||
CASE(tk_semicolon);
|
||||
CASE(tk_singleassign);
|
||||
CASE(tk_assign);
|
||||
CASE(tk_yields);
|
||||
|
||||
CASE(tk_type);
|
||||
CASE(tk_def);
|
||||
CASE(tk_lambda);
|
||||
CASE(tk_if);
|
||||
CASE(tk_let);
|
||||
|
||||
CASE(tk_in);
|
||||
CASE(tk_end);
|
||||
|
||||
case tokentype::tk_invalid:
|
||||
case tokentype::n_tokentype:
|
||||
|
|
@ -49,7 +55,7 @@ namespace xo {
|
|||
|
||||
return "???";
|
||||
} /*tokentype_descr*/
|
||||
} /*namespace tok*/
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@
|
|||
#include <memory>
|
||||
|
||||
namespace xo {
|
||||
using token = xo::tok::token<char>;
|
||||
using xo::tok::tokentype;
|
||||
using token = xo::scm::token<char>;
|
||||
using xo::scm::tokentype;
|
||||
|
||||
namespace ut {
|
||||
struct testcase_i64 {
|
||||
|
|
|
|||
|
|
@ -7,9 +7,9 @@
|
|||
#include <catch2/catch.hpp>
|
||||
|
||||
namespace xo {
|
||||
using xo::tok::tokentype;
|
||||
using token = xo::tok::token<char>;
|
||||
using xo::tok::span;
|
||||
using xo::scm::tokentype;
|
||||
using token = xo::scm::token<char>;
|
||||
using xo::scm::span;
|
||||
|
||||
namespace ut {
|
||||
namespace {
|
||||
|
|
@ -111,7 +111,7 @@ namespace xo {
|
|||
INFO(xtag("i_tc", i_tc));
|
||||
|
||||
using tokenizer
|
||||
= xo::tok::tokenizer<char>;
|
||||
= xo::scm::tokenizer<char>;
|
||||
|
||||
tokenizer tkz;
|
||||
tokenizer::span_type
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue