endplay.parsers.pbn

Parser for PBN files

Classes:

PBNDecoder()

Functions:

dump(boards, fp)

Serialize a list of Board objects to a PBN file

dumps(boards)

Serialize a list of Board objects to a PBN string

load(fp)

Read a PBN file object into a list of Board objects

loads(s)

Read a PBN string into a list of Board objects

class endplay.parsers.pbn.PBNDecoder

Bases: object

Classes:

State(value)

An enumeration.

Methods:

_get_comment(text, iscont)

Returns the comment contained in text, and a flag which is set to True if the comment requires continuation or False otherwise

_parse_commentblock(curline)

_parse_conttable(curline)

_parse_meta(curline)

_parse_none(curline)

_tags_to_board()

parse_file(f)

Parse a PBN file

Attributes:

re_bcomment_begin

re_bcomment_end

re_bcomment_line

re_colname

re_fileformat

re_ignore

re_lcomment

re_metatag

re_note

re_pbnversion

re_tagpair

class State(value)

Bases: Enum

An enumeration.

Attributes:

COMMENTBLOCK

DATA

META

NONE

COMMENTBLOCK = 3
DATA = 2
META = 1
NONE = 0
_get_comment(text: str, iscont: bool)

Returns the comment contained in text, and a flag which is set to True if the comment requires continuation or False otherwise

_parse_commentblock(curline)
_parse_conttable(curline)
_parse_meta(curline)
_parse_none(curline)
_tags_to_board()
parse_file(f: TextIO) list[endplay.types.board.Board]

Parse a PBN file

re_bcomment_begin = re.compile('\\s*{\\s*(.*)')
re_bcomment_end = re.compile('(.*)}')
re_bcomment_line = re.compile('\\s*{\\s*(.*?)}')
re_colname = re.compile('([+-]?)(\\w+)(?:\\\\(\\d+)([LR]?))?', re.IGNORECASE)
re_fileformat = re.compile('%\\s*(EXPORT|IMPORT)', re.IGNORECASE)
re_ignore = re.compile('%.*')
re_lcomment = re.compile('\\s*;\\s*(.*?)')
re_metatag = re.compile('%\\s*([\\w-]+):\\s*(.*?)')
re_note = re.compile('(\\d+):(.*)')
re_pbnversion = re.compile('%\\s*PBN (\\d+)\\.(\\d+)', re.IGNORECASE)
re_tagpair = re.compile('\\[(\\w+)\\s+\\"(.*?)\\"\\](\\s*[;{]?.*)')
endplay.parsers.pbn.dump(boards: list[endplay.types.board.Board], fp: TextIO) None

Serialize a list of Board objects to a PBN file

endplay.parsers.pbn.dumps(boards: list[endplay.types.board.Board]) str

Serialize a list of Board objects to a PBN string

endplay.parsers.pbn.load(fp: TextIO) list[endplay.types.board.Board]

Read a PBN file object into a list of Board objects

endplay.parsers.pbn.loads(s: str) list[endplay.types.board.Board]

Read a PBN string into a list of Board objects