17#ifndef HOOVER_CHESS_UTILS__PGN_READER__PGNSCANNER_H_INCLUDED
18#define HOOVER_CHESS_UTILS__PGN_READER__PGNSCANNER_H_INCLUDED
52 PgnScanner(
const char *inputData, std::size_t inputLen) noexcept :
53 yyFlexLexer {
nullptr,
nullptr },
100 std::string_view { YYText(), static_cast<std::size_t>(YYLeng()) }));
130#define C(tok) case tok: return #tok
185 return LexerInput(buf,
static_cast<std::size_t
>(maxSize));
197 const std::size_t copySize { std::min(maxSize,
m_inputLeft) };
228 template <
typename RetType,
bool digitsOnly>
238 if constexpr (!digitsOnly)
240 if (
static_cast<unsigned char>(c -
'0') > 9U)
245 ret +=
static_cast<RetType
>(c -
'0');
250 std::format(
"Integer overflow when tokenizing {}", tokenType));
266 const std::uint8_t col {
static_cast<std::uint8_t
>(colChar -
'a') };
267 const std::uint8_t row {
static_cast<std::uint8_t
>(rowChar -
'1') };
278 const std::uint8_t col {
static_cast<std::uint8_t
>(colChar -
'a') };
289 const std::uint8_t row {
static_cast<std::uint8_t
>(rowChar -
'1') };
PGN error exception.
Definition pgnreader-error.h:70
The PGN scanner (lexer)
Definition pgnscanner.h:40
static constexpr SquareSet colCharToMask(char colChar) noexcept
Translates column coordinate (file) to a square set.
Definition pgnscanner.h:276
PgnScanner(const char *inputData, std::size_t inputLen) noexcept
Constructor.
Definition pgnscanner.h:52
RetType asciiToUnsigned(const char *str, const char *end, const char *tokenType)
Ascii to unsigned integer conversion.
Definition pgnscanner.h:229
static constexpr PgnScannerToken getMovePieceScannerTokenForChar(char c) noexcept
Definition pgnscanner.h:369
static constexpr std::array< PgnScannerToken, 32 > ctCharToMovePieceTable
Definition pgnscanner.h:328
const char * m_inputData
Definition pgnscanner.h:42
void setTokenInfo_RESULT(PgnResult result)
PgnScannerToken m_curToken
Definition pgnscanner.h:44
PgnScannerToken tokenizeUnusualPawnMove(std::string_view str)
PgnScannerToken nextTokenNoThrowOnErrorToken()
Scans input and returns the next token. On bad input, error token is returned instead of throwing an ...
Definition pgnscanner.h:71
PgnScannerToken tokenizePieceMove(std::string_view str)
PgnScanner(PgnScanner &&)=delete
void setTokenInfo_ERROR(const char *errorMessage)
int LexerInput(char *buf, int maxSize)
Provides more input to the parent class (general flex version)
Definition pgnscanner.h:183
void setTokenInfo_NAG(std::uint8_t nag)
PgnScanner & operator=(const PgnScanner &) &=delete
void setTokenInfo_MOVENUM(const char *str, const char *end)
void setTokenInfo_PIECE_MOVE(SquareSet srcMask, bool capture, Square dstSq)
PgnScannerTokenInfo m_tokenInfo
Definition pgnscanner.h:45
static constexpr SquareSet rowCharToMask(char rowChar) noexcept
Translates row coordinate (rank) to a square set.
Definition pgnscanner.h:287
const PgnScannerTokenInfo & getTokenInfo() const noexcept
Returns additional information on the token.
Definition pgnscanner.h:125
static constexpr Piece getPieceForChar(char c) noexcept
Definition pgnscanner.h:363
std::size_t m_inputLeft
Definition pgnscanner.h:43
PgnScannerToken getCurrentToken() const noexcept
Returns the previously scanned token.
Definition pgnscanner.h:117
PgnScannerToken nextToken()
Scans input and returns the next token.
Definition pgnscanner.h:89
static constexpr const char * scannerTokenToString(PgnScannerToken token) noexcept
Returns a string for a scanner token.
Definition pgnscanner.h:136
void setTokenInfo_PAWN_MOVE(SquareSet srcMask, Square dstSq, Piece promoPiece)
static constexpr std::array< Piece, 32 > ctCharToPieceTable
Definition pgnscanner.h:294
static constexpr Square charCoordToSq(char colChar, char rowChar) noexcept
Translates character coordinates to a square.
Definition pgnscanner.h:264
PgnScanner(const PgnScanner &)=delete
PgnScannerToken yylexex()
The generated lexer.
std::size_t LexerInput(char *buf, std::size_t maxSize)
Provides more input to the parent class (Apple flex version)
Definition pgnscanner.h:195
Set of squares. Implemented using a bit-mask.
Definition chessboard-types-squareset.h:35
static constexpr SquareSet column(RowColumn col) noexcept
Returns a set of squares in column number col.
Definition chessboard-types-squareset.h:471
static constexpr SquareSet row(RowColumn row) noexcept
Returns a set of squares in row number row.
Definition chessboard-types-squareset.h:485
PgnResult
Game result.
Definition pgnreader-types.h:32
Piece
Named piece.
Definition chessboard-types.h:204
Square
Named square.
Definition chessboard-types.h:122
constexpr Square makeSquare(RowColumn col, RowColumn row) noexcept
Constructs a square from column and row.
Definition chessboard-types.h:316
@ BAD_CHARACTER
Unexpected character in PGN input (tokenizer error)
@ NONE
Value representing no piece.
PgnScannerToken
PGN scanner token.
Definition pgnscannertokens.h:37
@ VARIATION_START
Variation start ('(')
Definition pgnscannertokens.h:57
@ VARIATION_END
Variation end ('(')
Definition pgnscannertokens.h:60
@ COMMENT_TEXT
Block comment text line OR single line comment.
Definition pgnscannertokens.h:127
@ TAG_START
PGN tag start ('[')
Definition pgnscannertokens.h:45
@ MOVENUM
Move number.
Definition pgnscannertokens.h:65
@ MOVE_PIECE_ROOK
Rook move.
Definition pgnscannertokens.h:100
@ ERROR
Tokenizer error.
Definition pgnscannertokens.h:146
@ COMMENT_NEWLINE
New line within a block comment.
Definition pgnscannertokens.h:130
@ MOVE_PIECE_KNIGHT
Knight move.
Definition pgnscannertokens.h:90
@ MOVE_PIECE_BISHOP
Bishop move.
Definition pgnscannertokens.h:95
@ MOVE_PAWN
Pawn advance (non-promoting)
Definition pgnscannertokens.h:70
@ TAG_KEY
PGN tag key.
Definition pgnscannertokens.h:48
@ MOVE_PAWN_PROMO
Pawn capture (promoting)
Definition pgnscannertokens.h:80
@ TAG_END
PGN tag end (']')
Definition pgnscannertokens.h:54
@ NAG
Numeric annotation glyph.
Definition pgnscannertokens.h:121
@ MOVE_SHORT_CASTLE
Short castling move.
Definition pgnscannertokens.h:113
@ MOVE_PAWN_CAPTURE
Pawn capture (non-promoting)
Definition pgnscannertokens.h:75
@ NONE
Null token (placeholder only)
Definition pgnscannertokens.h:39
@ COMMENT_END
Block comment end.
Definition pgnscannertokens.h:133
@ END_OF_FILE
End of file.
Definition pgnscannertokens.h:42
@ RESULT
PGN game result (terminator)
Definition pgnscannertokens.h:138
@ MOVE_PIECE_KING
King move.
Definition pgnscannertokens.h:110
@ TAG_VALUE
PGN tag value.
Definition pgnscannertokens.h:51
@ MOVE_LONG_CASTLE
Long castling move.
Definition pgnscannertokens.h:116
@ MOVE_PAWN_PROMO_CAPTURE
Pawn capture (promoting)
Definition pgnscannertokens.h:85
@ COMMENT_START
Block comment start.
Definition pgnscannertokens.h:124
@ MOVE_PIECE_QUEEN
Queen move.
Definition pgnscannertokens.h:105
Definition chessboard-types-squareset.h:30
#define C(tok)
Definition pgnscanner.h:130
Union of all additional scanner information. The applicable union member depends the PGN scanner toke...
Definition pgnscannertokens.h:225