Improve parser

This commit is contained in:
Loic Guegan 2022-01-27 08:04:32 +01:00
parent 92350c7cc9
commit 3fb48d4f29

View file

@ -190,35 +190,46 @@ loctype PGN::ParseHalfMove(loctype loc, HalfMove *hm) {
} }
hm->move = move; hm->move = move;
// Check for NAG
loc = GotoNextToken(loc); loc = GotoNextToken(loc);
EOF_CHECK(loc); EOF_CHECK(loc);
c = pgn_content[loc]; c = pgn_content[loc];
if (c == '$') {
hm->NAG += c; while (c == '{' || c == '$' || c == '(' || c == ';' || c == '%') {
loc++; if (c == '{') {
EOF_CHECK(loc); // Parse comment
c = pgn_content[loc]; loc = ParseComment(loc, hm);
while (IS_DIGIT(c)) { } else if (c == '$') {
hm->NAG += c; // Check for NAG
loc++; loc = GotoNextToken(loc);
EOF_CHECK(loc); EOF_CHECK(loc);
c = pgn_content[loc]; c = pgn_content[loc];
if (c == '$') {
hm->NAG += c;
loc++;
EOF_CHECK(loc);
c = pgn_content[loc];
while (IS_DIGIT(c)) {
hm->NAG += c;
loc++;
EOF_CHECK(loc);
c = pgn_content[loc];
}
}
} else if (c == '(') {
// Check for variations
loc = GotoNextToken(loc);
while (!IS_EOF && pgn_content[loc] == '(') {
loc++; // Skip '('
HalfMove *var = new HalfMove;
loc = ParseHalfMove(loc, var);
hm->variations.push_back(var);
loc++; // Skip ')'
// Goto next var
loc = GotoNextToken(loc);
EOF_CHECK(loc);
c = pgn_content[loc];
}
} }
}
// Parse comment
loc = ParseComment(loc, hm);
// Check for variations
loc = GotoNextToken(loc);
while (!IS_EOF && pgn_content[loc] == '(') {
loc++; // Skip '('
HalfMove *var = new HalfMove;
loc = ParseHalfMove(loc, var);
hm->variations.push_back(var);
loc++; // Skip ')'
// Goto next var
loc = GotoNextToken(loc); loc = GotoNextToken(loc);
EOF_CHECK(loc); EOF_CHECK(loc);
c = pgn_content[loc]; c = pgn_content[loc];