8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/pgn/parser.rb', line 8
def lex(input)
line = 1
offset = 0
ending = input.length
@@pgn ||= ''
@@game_comment ||= nil
until offset == ending
next_token(input, offset, line).tap do |token|
if !token.nil?
token[:offset] = offset
line, token[:line] = token[:line], line
yield token unless token[:discarded]
@@pgn += token[:value]
offset += token[:value].length
else
raise Whittle::UnconsumedInputError,
"Unmatched input #{input[offset..-1].inspect} on line #{line}"
end
end
end
yield ({ name: :$end, line: line, value: nil, offset: offset })
end
|