Skip to content

Commit

Permalink
Canonicalize the error printer.
Browse files Browse the repository at this point in the history
  • Loading branch information
tswhison committed May 16, 2024
1 parent 9b73aab commit 96354a7
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions include/c_lexer/Lexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,21 @@ class Lexer {
Lexeme eat();
void preload(std::size_t);

template <typename... Args>
std::ostream &print_error(std::ostream &os, Args... args) {
template <typename S, typename... Args>
S &print_error(S &os, Args &&...args) {
return printer(os, "c_lexer[", row_, ',', col_, "]: ", args...);
}

protected:
Lexeme scan_token();

template <typename... Args>
std::ostream &printer(std::ostream &os, Args... args) {
auto tmp = {(os << args, 0)...};
(void)tmp;
template <typename S, typename T0, typename... Ts>
S &printer(S &os, T0 &&t0, Ts &&...ts) {
os << std::forward<T0>(t0);

if constexpr (sizeof...(ts))
printer(os, std::forward<Ts>(ts)...);

return os;
}

Expand Down

0 comments on commit 96354a7

Please sign in to comment.