Inja 3.3.0
A Template Engine for Modern C++
Loading...
Searching...
No Matches
token.hpp
1#ifndef INCLUDE_INJA_TOKEN_HPP_
2#define INCLUDE_INJA_TOKEN_HPP_
3
4#include <string>
5
6#include "string_view.hpp"
7
8namespace inja {
9
13struct Token {
14 enum class Kind {
15 Text,
16 ExpressionOpen, // {{
17 ExpressionClose, // }}
18 LineStatementOpen, // ##
19 LineStatementClose, // \n
20 StatementOpen, // {%
21 StatementClose, // %}
22 CommentOpen, // {#
23 CommentClose, // #}
24 Id, // this, this.foo
25 Number, // 1, 2, -1, 5.2, -5.3
26 String, // "this"
27 Plus, // +
28 Minus, // -
29 Times, // *
30 Slash, // /
31 Percent, // %
32 Power, // ^
33 Comma, // ,
34 Dot, // .
35 Colon, // :
36 LeftParen, // (
37 RightParen, // )
38 LeftBracket, // [
39 RightBracket, // ]
40 LeftBrace, // {
41 RightBrace, // }
42 Equal, // ==
43 NotEqual, // !=
44 GreaterThan, // >
45 GreaterEqual, // >=
46 LessThan, // <
47 LessEqual, // <=
48 Unknown,
49 Eof,
50 };
51
52 Kind kind {Kind::Unknown};
53 nonstd::string_view text;
54
55 explicit constexpr Token() = default;
56 explicit constexpr Token(Kind kind, nonstd::string_view text) : kind(kind), text(text) {}
57
58 std::string describe() const {
59 switch (kind) {
60 case Kind::Text:
61 return "<text>";
62 case Kind::LineStatementClose:
63 return "<eol>";
64 case Kind::Eof:
65 return "<eof>";
66 default:
67 return static_cast<std::string>(text);
68 }
69 }
70};
71
72} // namespace inja
73
74#endif // INCLUDE_INJA_TOKEN_HPP_
Helper-class for the inja Lexer.
Definition: token.hpp:13