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_parser.hpp | 87 +++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 lib/libtmi8/include/tmi8/kv1_parser.hpp (limited to 'lib/libtmi8/include/tmi8/kv1_parser.hpp') 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 @@ +// vim:set sw=2 ts=2 sts et: + +#ifndef OEUF_LIBTMI8_KV1_PARSER_HPP +#define OEUF_LIBTMI8_KV1_PARSER_HPP + +#include +#include +#include +#include +#include + +#include +#include + +struct Kv1Parser { + explicit Kv1Parser(std::vector tokens, Kv1Records &parse_into); + + void parse(); + + private: + // Method pointer to a method of Kv1Parser (i.e. a function that takes + // 'this'; is not static) that takes no arguments and also does not return + // anything. + using ParseFunc = void (Kv1Parser::*)(); + static const std::unordered_map type_parsers; + + bool atEnd() const; + void eatRowEnds(); + const Kv1Token *cur() const; + const std::string *eatCell(std::string_view parsing_what); + std::string parseHeader(); + void eatRestOfRow(); + + void requireString(std::string_view field, bool mandatory, size_t max_length, std::string_view value); + std::optional requireBoolean(std::string_view field, bool mandatory, std::string_view value); + std::optional requireNumber(std::string_view field, bool mandatory, size_t max_digits, std::string_view value); + std::optional requireRgbColor(std::string_view field, bool mandatory, std::string_view value); + std::optional requireRdCoord(std::string_view field, bool mandatory, size_t min_digits, std::string_view value); + + std::string eatString(std::string_view field, bool mandatory, size_t max_length); + std::optional eatBoolean(std::string_view field, bool mandatory); + std::optional eatNumber(std::string_view field, bool mandatory, size_t max_digits); + std::optional eatRgbColor(std::string_view field, bool mandatory); + std::optional eatRdCoord(std::string_view field, bool mandatory, size_t min_digits); + + void parseOrganizationalUnit(); + void parseHigherOrganizationalUnit(); + void parseUserStopPoint(); + void parseUserStopArea(); + void parseTimingLink(); + void parseLink(); + void parseLine(); + void parseDestination(); + void parseJourneyPattern(); + void parseConcessionFinancerRelation(); + void parseConcessionArea(); + void parseFinancer(); + void parseJourneyPatternTimingLink(); + void parsePoint(); + void parsePointOnLink(); + void parseIcon(); + void parseNotice(); + void parseNoticeAssignment(); + void parseTimeDemandGroup(); + void parseTimeDemandGroupRunTime(); + void parsePeriodGroup(); + void parseSpecificDay(); + void parseTimetableVersion(); + void parsePublicJourney(); + void parsePeriodGroupValidity(); + void parseExceptionalOperatingDay(); + void parseScheduleVersion(); + void parsePublicJourneyPassingTimes(); + void parseOperatingDay(); + + size_t pos = 0; + std::vector tokens; + const std::chrono::time_zone *amsterdam = std::chrono::locate_zone("Europe/Amsterdam"); + + public: + std::vector warns; + std::vector global_errors; + std::vector record_errors; + Kv1Records &records; +}; + +#endif // OEUF_LIBTMI8_KV1_PARSER_HPP -- cgit v1.2.3