From 17a3ea880402338420699e03bcb24181e4ff3924 Mon Sep 17 00:00:00 2001 From: Rutger Broekhoff Date: Thu, 2 May 2024 20:27:40 +0200 Subject: Initial commit Based on dc4ba6a --- lib/libtmi8/include/tmi8/kv1_lexer.hpp | 46 ++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 lib/libtmi8/include/tmi8/kv1_lexer.hpp (limited to 'lib/libtmi8/include/tmi8/kv1_lexer.hpp') 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 @@ +// vim:set sw=2 ts=2 sts et: + +#ifndef OEUF_LIBTMI8_KV1_LEXER_HPP +#define OEUF_LIBTMI8_KV1_LEXER_HPP + +#include +#include +#include +#include +#include +#include + +enum Kv1TokenType { + KV1_TOKEN_CELL, + KV1_TOKEN_ROW_END, +}; +struct Kv1Token { Kv1TokenType type; std::string data; }; + +struct Kv1Lexer { + std::vector errors; + std::vector tokens; + + explicit Kv1Lexer(std::string_view input); + + void lex(); + + private: + // Does not eat newline character. + void eatRestOfLine(); + void lexOptionalHeader(); + void lexOptionalComment(); + + static bool isWhitespace(int c); + + void readQuotedColumn(); + void readUnquotedColumn(); + void lexRow(); + // Returns true when a line ending was consumed. + bool eatWhitespace(); + + std::string_view input; + std::string_view slice; + std::string colbuf; +}; + +#endif // OEUF_LIBTMI8_KV1_LEXER_HPP -- cgit v1.3.1