36 std::vector<tokens__> _toks;
43 [[nodiscard]]
static tokens__::TYPE f_token(
char c)
noexcept {
44 return (tokens__::TYPE)c;
52 [[nodiscard]]
static bool f_reserved(tokens__::TYPE token_type)
noexcept {
54 case tokens__::TYPE::TK_PAREN_L:
55 case tokens__::TYPE::TK_PAREN_R:
56 case tokens__::TYPE::TK_COMMA:
57 case tokens__::TYPE::TK_COLON:
58 case tokens__::TYPE::TK_BRACE_L:
59 case tokens__::TYPE::TK_BRACE_R:
60 case tokens__::TYPE::TK_DOLLA:
61 case tokens__::TYPE::TK_CURL_L:
62 case tokens__::TYPE::TK_CURL_R:
63 case tokens__::TYPE::TK_STAR:
64 case tokens__::TYPE::TK_SLASH:
65 case tokens__::TYPE::TK_EOF:
66 case tokens__::TYPE::TK_QUOTE_DOUBLE:
67 case tokens__::TYPE::TK_QUOTE_SINGLE:
77 void f_print()
const noexcept {
78 for (
const auto &t : _toks) {
87 [[nodiscard]]
bool f_eof()
const noexcept {
88 return (f_token(_in[_end]) == tokens__::TYPE::TK_EOF);
95 [[nodiscard]]
char f_peek_next()
const noexcept {
103 [[nodiscard]]
char f_peek()
const noexcept {
112 [[nodiscard]]
char f_peek_at(std::size_t offset)
const noexcept {
113 return _in[_end + offset];
121 char f_advance()
noexcept {
125 if (_in[_end] ==
'\n') {
139 char f_previous()
const noexcept {
140 return _in[_end - 1];
147 std::string to_substr()
const noexcept {
148 return _in.substr(_beg, _end - _beg);
157 std::string to_substr(std::size_t new_beg, std::size_t new_end)
const noexcept {
158 return _in.substr(new_beg, new_end);
164 void scan_number()
noexcept {
165 while (!f_eof() && std::isdigit(f_peek()))
168 if (!f_eof() && f_peek() ==
'.') {
170 while (!f_eof() && std::isdigit(f_peek()))
172 insert(tokens__::TYPE::TK_LITERAL_FLOAT, to_substr(), std::stof(to_substr()));
174 insert(tokens__::TYPE::TK_LITERAL_INT, to_substr(), std::stoi(to_substr()));
181 void scan_identifier()
noexcept {
182 while (!f_eof() && std::isalnum(f_peek())) {
185 insert(tokens__::TYPE::TK_IDENTIFIER, to_substr(), to_substr());
191 void scan_singular_reserve()
noexcept {
192 if (f_reserved(f_token(f_previous()))) {
193 insert(f_token(f_previous()), to_substr(), f_previous());
201 while (!f_eof() && traits::none_of(f_token(f_advance()), tokens__::TYPE::TK_QUOTE_DOUBLE));
203 insert(tokens__::TYPE::TK_LITERAL_STRING, to_substr(), to_substr());
209 void scan_comments()
noexcept {
210 if (f_token(f_peek()) == tokens__::TYPE::TK_SLASH) {
211 while (!f_eof() && f_token(f_peek()) != tokens__::TYPE::TK_NEWLINE)
215 if (f_token(f_advance()) == tokens__::TYPE::TK_STAR) {
216 const auto curr = f_token(f_peek());
217 while (!f_eof() && traits::none_of(curr, tokens__::TYPE::TK_STAR, tokens__::TYPE::TK_SLASH)) {
226 void scan_unknown()
noexcept {
227 insert(tokens__::TYPE::TK_UNKNOWN, to_substr(), to_substr());
238 template <
typename T>
239 [[nodiscard]]
constexpr tokens__ create_token(tokens__::TYPE type, std::string embedded,
const T &literal)
noexcept {
240 tokens__ tok(type, embedded, literal, std::make_pair(_row, _col));
251 template <
typename T>
252 constexpr void insert(tokens__::TYPE type, std::string embedded,
const T &lit)
noexcept {
253 _toks.push_back(create_token(type, embedded, lit));
259 void process_unit() {
260 char c = f_advance();
261 if (f_token(c) == tokens__::TYPE::TK_SLASH) {
264 if (f_reserved(f_token(c))) {
265 if (traits::none_of(f_token(c), tokens__::TYPE::TK_SLASH, tokens__::TYPE::TK_QUOTE_DOUBLE))
266 scan_singular_reserve();
267 else if (traits::any_of(f_token(c), tokens__::TYPE::TK_QUOTE_DOUBLE))
269 }
else if (std::isdigit(c)) {
271 }
else if (std::isalnum(c)) {
274 if (!std::isspace(c))
283 [[nodiscard]] std::vector<tokens__> f_lex() &
noexcept {
288 insert(tokens__::TYPE::TK_EOF, to_substr(), f_peek());
290#if CIRCUS_DEBUG_PEDANTIC__
314 [[nodiscard]] std::vector<tokens__>
operator()(
const std::string &input)
noexcept {