6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/worte/printer/simple.rb', line 6
def print(text, tokens, where=STDOUT)
text.split("\n").each_with_index do |line, l|
line_tokens = tokens.select { |t| t.position[0] == l }
if line_tokens.collect(&:correct).all?
next
end
where.print "#{l + 1}: "
where.puts line
col = 0
where.print ' ' * ((l + 1).to_s.length + 2)
line_tokens.each do |token|
if !token.correct
if col != token.position[1]
where.print (' ' * (token.position[1] - col))
col = token.position[1]
end
where.print error_marker(token.word.length)
col += token.word.length
end
end
where.puts
end
end
|