aboutsummaryrefslogtreecommitdiffstats
path: root/lib/libtmi8/include/tmi8/kv1_lexer.hpp
diff options
context:
space:
mode:
authorRutger Broekhoff2024-05-02 20:27:40 +0200
committerRutger Broekhoff2024-05-02 20:27:40 +0200
commit17a3ea880402338420699e03bcb24181e4ff3924 (patch)
treeda666ef91e0b60d20aa0b01529644c136fd1f4ab /lib/libtmi8/include/tmi8/kv1_lexer.hpp
downloadoeuf-17a3ea880402338420699e03bcb24181e4ff3924.tar.gz
oeuf-17a3ea880402338420699e03bcb24181e4ff3924.zip
Initial commit
Based on dc4ba6a
Diffstat (limited to 'lib/libtmi8/include/tmi8/kv1_lexer.hpp')
-rw-r--r--lib/libtmi8/include/tmi8/kv1_lexer.hpp46
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
13enum Kv1TokenType {
14 KV1_TOKEN_CELL,
15 KV1_TOKEN_ROW_END,
16};
17struct Kv1Token { Kv1TokenType type; std::string data; };
18
19struct 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