| 123456789101112131415161718192021222324252627282930 |
- //
- // exception.cxx
- // dice
- //
- // Created by Sam Jaffe on 12/17/18.
- // Copyright © 2018 Sam Jaffe. All rights reserved.
- //
- #include "dice-roll/exception.h"
- #include <cmath>
- #include <string>
- static std::string carrot(long long pos) {
- if (pos == -1) return "<END>"; // For safety
- std::string out;
- // resize(0) followed by back() will cause UB
- out.resize(std::max(pos, 1ll), '~');
- out.back() = '^';
- return out;
- }
- namespace dice {
- unexpected_token::unexpected_token(std::string const & reason, long long pos)
- : std::runtime_error(reason), position(pos) {}
-
- std::string unexpected_token::pointer(long long backup_length) const {
- return carrot(position == -1 ? backup_length : position);
- }
- }
|