diff options
Diffstat (limited to 'lib/libtmi8/include/tmi8/kv1_lexer.hpp')
| -rw-r--r-- | lib/libtmi8/include/tmi8/kv1_lexer.hpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/lib/libtmi8/include/tmi8/kv1_lexer.hpp b/lib/libtmi8/include/tmi8/kv1_lexer.hpp new file mode 100644 index 0000000..df6a57c --- /dev/null +++ b/lib/libtmi8/include/tmi8/kv1_lexer.hpp | |||
| @@ -0,0 +1,46 @@ | |||
| 1 | // vim:set sw=2 ts=2 sts et: | ||
| 2 | |||
| 3 | #ifndef OEUF_LIBTMI8_KV1_LEXER_HPP | ||
| 4 | #define OEUF_LIBTMI8_KV1_LEXER_HPP | ||
| 5 | |||
| 6 | #include <cstdint> | ||
| 7 | #include <cstring> | ||
| 8 | #include <iostream> | ||
| 9 | #include <string> | ||
| 10 | #include <vector> | ||
| 11 | #include <variant> | ||
| 12 | |||
| 13 | enum Kv1TokenType { | ||
| 14 | KV1_TOKEN_CELL, | ||
| 15 | KV1_TOKEN_ROW_END, | ||
| 16 | }; | ||
| 17 | struct Kv1Token { Kv1TokenType type; std::string data; }; | ||
| 18 | |||
| 19 | struct Kv1Lexer { | ||
| 20 | std::vector<std::string> errors; | ||
| 21 | std::vector<Kv1Token> tokens; | ||
| 22 | |||
| 23 | explicit Kv1Lexer(std::string_view input); | ||
| 24 | |||
| 25 | void lex(); | ||
| 26 | |||
| 27 | private: | ||
| 28 | // Does not eat newline character. | ||
| 29 | void eatRestOfLine(); | ||
| 30 | void lexOptionalHeader(); | ||
| 31 | void lexOptionalComment(); | ||
| 32 | |||
| 33 | static bool isWhitespace(int c); | ||
| 34 | |||
| 35 | void readQuotedColumn(); | ||
| 36 | void readUnquotedColumn(); | ||
| 37 | void lexRow(); | ||
| 38 | // Returns true when a line ending was consumed. | ||
| 39 | bool eatWhitespace(); | ||
| 40 | |||
| 41 | std::string_view input; | ||
| 42 | std::string_view slice; | ||
| 43 | std::string colbuf; | ||
| 44 | }; | ||
| 45 | |||
| 46 | #endif // OEUF_LIBTMI8_KV1_LEXER_HPP | ||