Documentation
¶
Index ¶
- type Characteristics
- type GameAlternative
- type GenericNotationParser
- type NotationParser
- func NewNotationParserAlgebraic(initialCharacteristics Characteristics) *NotationParser
- func NewNotationParserCoordinate(initialCharacteristics Characteristics) *NotationParser
- func NewNotationParserDescriptive(initialCharacteristics Characteristics) *NotationParser
- func NewNotationParserICCF(initialCharacteristics Characteristics) *NotationParser
- func NewNotationParserSmith(initialCharacteristics Characteristics) *NotationParser
- type ParseError
- type ParsedGame
- type ParserVariant
- type ParsingGame
- type Token
- type TokenType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Characteristics ¶
type Characteristics struct {
// contains filtered or unexported fields
}
type GameAlternative ¶
GameAlternative represents a single branch in the parsing game tree.
func (GameAlternative) Clone ¶
func (a GameAlternative) Clone() GameAlternative
Clone creates a deep copy of the GameAlternative.
func (GameAlternative) CurrentGame ¶
func (a GameAlternative) CurrentGame() core.Game
CurrentGame returns the current game state for this alternative.
type GenericNotationParser ¶
type GenericNotationParser struct {
// contains filtered or unexported fields
}
GenericNotationParser is a generic parser that works with any notation variant.
func NewGenericNotationParser ¶
func NewGenericNotationParser(variant ParserVariant) *GenericNotationParser
NewGenericNotationParser creates a new generic notation parser with the specified variant.
func (*GenericNotationParser) MatchHalfMove ¶
MatchHalfMove attempts to match a half move string against all possible actions in the current game. It uses the variant's ActionToStringVariants method to convert actions to notation strings. Returns a slice of actions that match the half move notation.
func (*GenericNotationParser) Parse ¶
func (p *GenericNotationParser) Parse(initialGame core.Game, s string) (*ParsedGame, error)
Parse performs the complete 3-step parsing process: 1. Initialize - extracts metadata and sets up parsing state 2. Loop through ParseHalfMove - processes all half moves 3. Finalize - completes parsing
func (*GenericNotationParser) ProcessToken ¶
func (p *GenericNotationParser) ProcessToken(pg *ParsingGame, token *Token) error
ProcessToken processes a token and updates the parsing game state. This handles all the generic logic: matching actions, branching, and applying moves.
type NotationParser ¶
type NotationParser struct {
// contains filtered or unexported fields
}
func NewNotationParserAlgebraic ¶
func NewNotationParserAlgebraic(initialCharacteristics Characteristics) *NotationParser
func NewNotationParserCoordinate ¶
func NewNotationParserCoordinate(initialCharacteristics Characteristics) *NotationParser
func NewNotationParserDescriptive ¶
func NewNotationParserDescriptive(initialCharacteristics Characteristics) *NotationParser
func NewNotationParserICCF ¶
func NewNotationParserICCF(initialCharacteristics Characteristics) *NotationParser
func NewNotationParserSmith ¶
func NewNotationParserSmith(initialCharacteristics Characteristics) *NotationParser
type ParseError ¶
type ParseError struct {
Reason string // "unknown-token" | "illegal-move" | "ambiguous" | "no-moves-found"
Token string // the failing token text (empty for unknown-token / no-moves-found)
MoveNumber int // 1-based full-move number at the failure point (0 = before first move)
LegalActions []core.Action // legal actions at the position (may be nil)
Msg string // user-facing prose
}
ParseError is a structured parse-failure error that carries machine-readable detail alongside the human-readable message. The api layer inspects these fields to build OutputParseError without reparsing the error string.
func (*ParseError) Error ¶
func (e *ParseError) Error() string
type ParsedGame ¶
ParsedGame represents the final parsed result.
type ParserVariant ¶
type ParserVariant interface {
// Initialize extracts notation-specific metadata (like tag pairs) and sets up the initial parsing state.
Initialize(initialGame core.Game, s string) (*ParsingGame, error)
// PopHalfMove pops the next half move token and any following comments or annotations.
// It handles all token peeking and position management internally.
// Returns:
// - token: the half move or result token (nil if no more half moves)
// - hasMore: true if another half move is available after this one, false otherwise
// - error: any error that occurred during token extraction
PopHalfMove(pg *ParsingGame) (*Token, bool, error)
// Finalize completes the parsing process (does nothing for now, but reserved for future use).
Finalize(pg *ParsingGame) error
// ActionToStringVariants converts an action to all possible string representations in this notation.
// For example, in PGN, an action might have multiple representations like "e4", "Pe4", "P4e4", etc.
ActionToStringVariants(a core.Action, g core.Game) []string
}
ParserVariant defines the interface for notation-specific parsing logic. Each notation type (PGN, Algebraic, Descriptive, etc.) implements this interface.
type ParsingGame ¶
type ParsingGame struct {
Alternatives []GameAlternative
Metadata map[string]string
Remaining string // Remaining notation string after metadata removed
Pos int // Current position in remaining string
}
ParsingGame represents a game in the process of being parsed. It contains the game alternatives and other parsing state.
func (*ParsingGame) Build ¶
func (pg *ParsingGame) Build() *ParsedGame
Build constructs the final ParsedGame from the ParsingGame. If multiple branches remain, it picks the first one.