diff options
author | Rutger Broekhoff | 2024-05-02 20:27:40 +0200 |
---|---|---|
committer | Rutger Broekhoff | 2024-05-02 20:27:40 +0200 |
commit | 17a3ea880402338420699e03bcb24181e4ff3924 (patch) | |
tree | da666ef91e0b60d20aa0b01529644c136fd1f4ab /lib/libtmi8/include/tmi8/kv1_parser.hpp | |
download | oeuf-17a3ea880402338420699e03bcb24181e4ff3924.tar.gz oeuf-17a3ea880402338420699e03bcb24181e4ff3924.zip |
Initial commit
Based on dc4ba6a
Diffstat (limited to 'lib/libtmi8/include/tmi8/kv1_parser.hpp')
-rw-r--r-- | lib/libtmi8/include/tmi8/kv1_parser.hpp | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/lib/libtmi8/include/tmi8/kv1_parser.hpp b/lib/libtmi8/include/tmi8/kv1_parser.hpp new file mode 100644 index 0000000..ccd8ec6 --- /dev/null +++ b/lib/libtmi8/include/tmi8/kv1_parser.hpp | |||
@@ -0,0 +1,87 @@ | |||
1 | // vim:set sw=2 ts=2 sts et: | ||
2 | |||
3 | #ifndef OEUF_LIBTMI8_KV1_PARSER_HPP | ||
4 | #define OEUF_LIBTMI8_KV1_PARSER_HPP | ||
5 | |||
6 | #include <optional> | ||
7 | #include <string> | ||
8 | #include <string_view> | ||
9 | #include <unordered_map> | ||
10 | #include <vector> | ||
11 | |||
12 | #include <tmi8/kv1_lexer.hpp> | ||
13 | #include <tmi8/kv1_types.hpp> | ||
14 | |||
15 | struct Kv1Parser { | ||
16 | explicit Kv1Parser(std::vector<Kv1Token> tokens, Kv1Records &parse_into); | ||
17 | |||
18 | void parse(); | ||
19 | |||
20 | private: | ||
21 | // Method pointer to a method of Kv1Parser (i.e. a function that takes | ||
22 | // 'this'; is not static) that takes no arguments and also does not return | ||
23 | // anything. | ||
24 | using ParseFunc = void (Kv1Parser::*)(); | ||
25 | static const std::unordered_map<std::string_view, ParseFunc> type_parsers; | ||
26 | |||
27 | bool atEnd() const; | ||
28 | void eatRowEnds(); | ||
29 | const Kv1Token *cur() const; | ||
30 | const std::string *eatCell(std::string_view parsing_what); | ||
31 | std::string parseHeader(); | ||
32 | void eatRestOfRow(); | ||
33 | |||
34 | void requireString(std::string_view field, bool mandatory, size_t max_length, std::string_view value); | ||
35 | std::optional<bool> requireBoolean(std::string_view field, bool mandatory, std::string_view value); | ||
36 | std::optional<double> requireNumber(std::string_view field, bool mandatory, size_t max_digits, std::string_view value); | ||
37 | std::optional<RgbColor> requireRgbColor(std::string_view field, bool mandatory, std::string_view value); | ||
38 | std::optional<double> requireRdCoord(std::string_view field, bool mandatory, size_t min_digits, std::string_view value); | ||
39 | |||
40 | std::string eatString(std::string_view field, bool mandatory, size_t max_length); | ||
41 | std::optional<bool> eatBoolean(std::string_view field, bool mandatory); | ||
42 | std::optional<double> eatNumber(std::string_view field, bool mandatory, size_t max_digits); | ||
43 | std::optional<RgbColor> eatRgbColor(std::string_view field, bool mandatory); | ||
44 | std::optional<double> eatRdCoord(std::string_view field, bool mandatory, size_t min_digits); | ||
45 | |||
46 | void parseOrganizationalUnit(); | ||
47 | void parseHigherOrganizationalUnit(); | ||
48 | void parseUserStopPoint(); | ||
49 | void parseUserStopArea(); | ||
50 | void parseTimingLink(); | ||
51 | void parseLink(); | ||
52 | void parseLine(); | ||
53 | void parseDestination(); | ||
54 | void parseJourneyPattern(); | ||
55 | void parseConcessionFinancerRelation(); | ||
56 | void parseConcessionArea(); | ||
57 | void parseFinancer(); | ||
58 | void parseJourneyPatternTimingLink(); | ||
59 | void parsePoint(); | ||
60 | void parsePointOnLink(); | ||
61 | void parseIcon(); | ||
62 | void parseNotice(); | ||
63 | void parseNoticeAssignment(); | ||
64 | void parseTimeDemandGroup(); | ||
65 | void parseTimeDemandGroupRunTime(); | ||
66 | void parsePeriodGroup(); | ||
67 | void parseSpecificDay(); | ||
68 | void parseTimetableVersion(); | ||
69 | void parsePublicJourney(); | ||
70 | void parsePeriodGroupValidity(); | ||
71 | void parseExceptionalOperatingDay(); | ||
72 | void parseScheduleVersion(); | ||
73 | void parsePublicJourneyPassingTimes(); | ||
74 | void parseOperatingDay(); | ||
75 | |||
76 | size_t pos = 0; | ||
77 | std::vector<Kv1Token> tokens; | ||
78 | const std::chrono::time_zone *amsterdam = std::chrono::locate_zone("Europe/Amsterdam"); | ||
79 | |||
80 | public: | ||
81 | std::vector<std::string> warns; | ||
82 | std::vector<std::string> global_errors; | ||
83 | std::vector<std::string> record_errors; | ||
84 | Kv1Records &records; | ||
85 | }; | ||
86 | |||
87 | #endif // OEUF_LIBTMI8_KV1_PARSER_HPP | ||