From e063e1453c611ac0d862ece2d2797582573c801f Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Tue, 25 Jan 2022 16:51:37 +0100 Subject: Improve parser --- src/PGN.hpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/PGN.hpp') diff --git a/src/PGN.hpp b/src/PGN.hpp index 0f59bd0..c4e27d0 100644 --- a/src/PGN.hpp +++ b/src/PGN.hpp @@ -14,15 +14,23 @@ private: std::vector tagkeys; /// @brief Contains game result (last PGN word) std::string result; - /// @brief COntains the parsed PGN moves + /// @brief Contains the parsed PGN moves HalfMove *moves; /// @brief Contains the PGN data std::string pgn_content; + /// @brief Contains the location of the end of the last parsed game (1 PGN file may have multiple games) + int LastGameEndLoc; public: + PGN(); ~PGN(); void FromFile(std::string); void FromString(std::string); + /** + * Parse the next available game. Note that it raises a @a NoGameFound exception if no more game is available. + * A call to this method flush all the last parsed game data. Be careful. + */ + void ParseNextGame(); /// @brief Check if PGN contains a specific tag bool HasTag(std::string); /// @brief Perform a Seven Tag Roster compliance check @@ -62,6 +70,10 @@ struct InvalidGameResult : public std::exception { const char *what() const throw() { return "Invalid game result"; } }; +struct NoGameFound : public std::exception { + const char *what() const throw() { return "No game (or more game) found"; } +}; + struct UnexpectedCharacter : public std::exception { std::string msg; UnexpectedCharacter(char actual, char required, int loc) { -- cgit v1.2.3