aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2022-01-26 14:41:38 +0100
committerLoic Guegan <manzerbredes@mailbox.org>2022-01-26 14:41:38 +0100
commitf4f436870f9ce0368d81c504e93b012e3928a851 (patch)
tree61ea2ac873997600ca0aeb29669e9fef6f65bfe0 /src
parentbb914f047b0d96464f3e55234907df4e7c416e97 (diff)
- Debug parser (carriage returns)
- Improve test framework
Diffstat (limited to 'src')
-rw-r--r--src/LargeFileStream.cpp2
-rw-r--r--src/LargeFileStream.hpp2
-rw-r--r--src/PGN.cpp30
-rw-r--r--src/PGN.hpp1
4 files changed, 21 insertions, 14 deletions
diff --git a/src/LargeFileStream.cpp b/src/LargeFileStream.cpp
index 547415b..86e2dcf 100644
--- a/src/LargeFileStream.cpp
+++ b/src/LargeFileStream.cpp
@@ -58,6 +58,6 @@ char LargeFileStream::operator[](long loc) {
return buffer[offset];
}
-bool LargeFileStream::IsEOF(long loc) { return (eof); }
+bool LargeFileStream::IsEOF() { return (eof); }
} // namespace pgnp \ No newline at end of file
diff --git a/src/LargeFileStream.hpp b/src/LargeFileStream.hpp
index 6ac87e8..b80d8e4 100644
--- a/src/LargeFileStream.hpp
+++ b/src/LargeFileStream.hpp
@@ -36,7 +36,7 @@ public:
/// @brief Allow array like access to the file
char operator[](long loc);
/// @brief Check if we reach the EOF
- bool IsEOF(long loc);
+ bool IsEOF();
// Various Exceptions
struct BackwardRead : public std::exception {
diff --git a/src/PGN.cpp b/src/PGN.cpp
index 953f225..aac5614 100644
--- a/src/PGN.cpp
+++ b/src/PGN.cpp
@@ -3,14 +3,14 @@
#include <iostream>
#include <string>
-#define IS_BLANK(c) (c == ' ' || c == '\n' || c == '\t')
+#define IS_BLANK(c) (c == ' ' || c == '\n' || c == '\t' || c == '\r')
#define IS_DIGIT(c) \
(c == '0' || c == '1' || c == '2' || c == '3' || c == '4' || c == '5' || \
c == '6' || c == '7' || c == '8' || c == '9')
-#define IS_EOF(loc) (pgn_content.IsEOF(loc))
+#define IS_EOF (pgn_content.IsEOF())
#define EOF_CHECK(loc) \
{ \
- if (IS_EOF(loc)) \
+ if (IS_EOF) \
throw UnexpectedEOF(); \
}
@@ -42,17 +42,16 @@ void PGN::ParseNextGame() {
moves = new HalfMove();
// Search for new game
- if (IS_EOF(LastGameEndLoc)) {
+ if (IS_EOF) {
throw NoGameFound();
}
int loc = NextNonBlank(LastGameEndLoc);
-
- if (IS_EOF(loc)) {
+ if (IS_EOF) {
throw NoGameFound();
}
// Parse game
- while (!IS_EOF(loc)) {
+ while (!IS_EOF) {
char c = pgn_content[loc];
if (!IS_BLANK(c)) {
if (c == '[') {
@@ -108,7 +107,8 @@ long PGN::ParseComment(long loc, HalfMove *hm) {
EOF_CHECK(loc);
char c = pgn_content[loc];
- if (c == '{') {
+ // Parse a sequence of comment
+ while (!IS_EOF && c == '{') {
loc++;
EOF_CHECK(loc);
c = pgn_content[loc];
@@ -119,6 +119,12 @@ long PGN::ParseComment(long loc, HalfMove *hm) {
c = pgn_content[loc];
}
loc++; // Skip '}'
+
+ // Goto next non blank to look for another comment token
+ loc = NextNonBlank(loc);
+ if(!IS_EOF){
+ c = pgn_content[loc];
+ }
}
return (loc);
}
@@ -204,7 +210,7 @@ long PGN::ParseHalfMove(long loc, HalfMove *hm) {
// Check for variations
loc = NextNonBlank(loc);
- while (!IS_EOF(loc) && pgn_content[loc] == '(') {
+ while (!IS_EOF && pgn_content[loc] == '(') {
loc++; // Skip '('
HalfMove *var = new HalfMove;
loc = ParseHalfMove(loc, var);
@@ -226,7 +232,7 @@ long PGN::ParseHalfMove(long loc, HalfMove *hm) {
// Parse next HalfMove
loc = NextNonBlank(loc);
- if (!IS_EOF(loc)) {
+ if (!IS_EOF) {
HalfMove *next_hm = new HalfMove;
next_hm->count = hm->count;
loc = ParseHalfMove(loc, next_hm);
@@ -259,7 +265,7 @@ long PGN::ParseNextTag(long start_loc) {
long valueloc = NextNonBlank(keyloc) + 1;
EOF_CHECK(keyloc);
c = pgn_content[valueloc];
- while (c != '"' or IS_EOF(valueloc)) {
+ while (c != '"' or IS_EOF) {
value += c;
valueloc++;
EOF_CHECK(keyloc);
@@ -308,7 +314,7 @@ long PGN::NextNonBlank(long loc) {
char c = pgn_content[loc];
while (IS_BLANK(c)) {
loc++;
- if (IS_EOF(loc)) {
+ if (IS_EOF) {
return (loc);
}
c = pgn_content[loc];
diff --git a/src/PGN.hpp b/src/PGN.hpp
index 7e4d0e2..2102fa3 100644
--- a/src/PGN.hpp
+++ b/src/PGN.hpp
@@ -58,6 +58,7 @@ private:
long NextNonBlank(long);
/// @brief Parse a HalfMove at a specific location into @a pgn_content
long ParseHalfMove(long, HalfMove *);
+ /// @brief Parse a consecutive sequence of comment
long ParseComment(long, HalfMove *);
};