diff options
author | Toni Uhlig <matzeton@googlemail.com> | 2021-04-27 11:23:17 +0200 |
---|---|---|
committer | Toni Uhlig <matzeton@googlemail.com> | 2021-04-27 11:23:17 +0200 |
commit | 514cb71a6a3e116c229c5dc874369f8632530dc7 (patch) | |
tree | dbc61581e04809fca19fefb3f4954b76e1e3e2c8 /include/inja/token.hpp |
Squashed 'deps/inja/' content from commit 811e173
git-subtree-dir: deps/inja
git-subtree-split: 811e1730e13bca4ea1805a42d5f0a4b5c91046e1
Diffstat (limited to 'include/inja/token.hpp')
-rw-r--r-- | include/inja/token.hpp | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/include/inja/token.hpp b/include/inja/token.hpp new file mode 100644 index 0000000..c000138 --- /dev/null +++ b/include/inja/token.hpp @@ -0,0 +1,76 @@ +// Copyright (c) 2020 Pantor. All rights reserved. + +#ifndef INCLUDE_INJA_TOKEN_HPP_ +#define INCLUDE_INJA_TOKEN_HPP_ + +#include <string> + +#include "string_view.hpp" + +namespace inja { + +/*! + * \brief Helper-class for the inja Lexer. + */ +struct Token { + enum class Kind { + Text, + ExpressionOpen, // {{ + ExpressionClose, // }} + LineStatementOpen, // ## + LineStatementClose, // \n + StatementOpen, // {% + StatementClose, // %} + CommentOpen, // {# + CommentClose, // #} + Id, // this, this.foo + Number, // 1, 2, -1, 5.2, -5.3 + String, // "this" + Plus, // + + Minus, // - + Times, // * + Slash, // / + Percent, // % + Power, // ^ + Comma, // , + Dot, // . + Colon, // : + LeftParen, // ( + RightParen, // ) + LeftBracket, // [ + RightBracket, // ] + LeftBrace, // { + RightBrace, // } + Equal, // == + NotEqual, // != + GreaterThan, // > + GreaterEqual, // >= + LessThan, // < + LessEqual, // <= + Unknown, + Eof, + }; + + Kind kind {Kind::Unknown}; + nonstd::string_view text; + + explicit constexpr Token() = default; + explicit constexpr Token(Kind kind, nonstd::string_view text) : kind(kind), text(text) {} + + std::string describe() const { + switch (kind) { + case Kind::Text: + return "<text>"; + case Kind::LineStatementClose: + return "<eol>"; + case Kind::Eof: + return "<eof>"; + default: + return static_cast<std::string>(text); + } + } +}; + +} // namespace inja + +#endif // INCLUDE_INJA_TOKEN_HPP_ |