Module: Sashite::Feen::Parser

Defined in:
lib/sashite/feen/parser.rb,
lib/sashite/feen/parser/style_turn.rb,
lib/sashite/feen/parser/pieces_in_hand.rb,
lib/sashite/feen/parser/piece_placement.rb

Overview

Parser for FEEN (Forsyth–Edwards Enhanced Notation) strings.

Parses a complete FEEN string by splitting it into three space-separated fields and delegating parsing to specialized parsers for each component.

Defined Under Namespace

Modules: PiecePlacement, PiecesInHand, StyleTurn

Constant Summary collapse

FIELD_SEPARATOR =

Field separator in FEEN notation.

" "
FIELD_COUNT =

Number of required fields in a valid FEEN string.

3

Class Method Summary collapse

Class Method Details

.parse(string) ⇒ Position

Parse a FEEN string into an immutable Position object.

Validates the overall FEEN structure, splits the string into three space-separated fields, and delegates parsing of each field to the appropriate specialized parser.

Examples:

Parse a complete FEEN string

position = Parser.parse("+rnbq+kbn+r/+p+p+p+p+p+p+p+p/8/8/8/8/+P+P+P+P+P+P+P+P/+RNBQ+KBN+R / C/c")

Parameters:

  • string (String)

    A FEEN notation string

Returns:

  • (Position)

    Immutable position object

Raises:



37
38
39
40
41
42
43
44
45
# File 'lib/sashite/feen/parser.rb', line 37

def self.parse(string)
  fields = split_fields(string)

  placement = Parser::PiecePlacement.parse(fields[0])
  hands     = Parser::PiecesInHand.parse(fields[1])
  styles    = Parser::StyleTurn.parse(fields[2])

  Position.new(placement, hands, styles)
end