Class: Bchess::PGN::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/pgn/parser.rb

Constant Summary collapse

@@parser =
SexpParser.new

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input) ⇒ Parser

Returns a new instance of Parser.



13
14
15
# File 'lib/pgn/parser.rb', line 13

def initialize(input)
  @input = input
end

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error.



8
9
10
# File 'lib/pgn/parser.rb', line 8

def error
  @error
end

#inputObject (readonly)

Returns the value of attribute input.



8
9
10
# File 'lib/pgn/parser.rb', line 8

def input
  @input
end

#outputObject (readonly)

Returns the value of attribute output.



8
9
10
# File 'lib/pgn/parser.rb', line 8

def output
  @output
end

#treeObject (readonly)

Returns the value of attribute tree.



8
9
10
# File 'lib/pgn/parser.rb', line 8

def tree
  @tree
end

Instance Method Details

#parseObject



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/pgn/parser.rb', line 17

def parse
  if input.is_a?(String)
    @tree = @@parser.parse(input)
  elsif input.is_a?(Bchess::PGN::PGNFile)
    @tree = @@parser.parse(input.load_games)
  end

  unless tree
    raise PGN::ParserException, "Parse error at offset: #{@@parser.index}"
  end

  sanitize_tree(tree)
end