Remove source lines from parser error messages.

This was a gimmick in the first place. It doesn't work well with IO instances
(= requires re-reading of the input), the code was too complex and it wasn't
that useful in the end. Lets just get rid of it.

This fixes #53.
This commit is contained in:
Yorick Peterse committed 2014-09-25 22:58:06 +02:00
1 parent 8db77c0a09
commit 3307e2f4d2
2 files changed
+7 -60

No files matched your search

+3 -36
View File
@@ -265,43 +265,10 @@ end
# @raise [Racc::ParseError]
#
def on_error(type, value, stack)
name = token_to_str(type)
name = TOKEN_ERROR_MAPPING[name] || name
index = @line - 1
index_range = (index - 5)..(index + 5)
code = ''
name = token_to_str(type)
name = TOKEN_ERROR_MAPPING[name] || name
# For IO we sadly have to re-read the input :<
if @data.respond_to?(:rewind)
@data.rewind
end
# Show up to 5 lines before and after the offending line (if they exist).
@data.each_line.with_index do |line, line_index|
next unless index_range.cover?(line_index)
number = line_index + 1
if line_index == index
prefix = '=> '
else
prefix = ' '
end
line = line.strip
if line.length > 80
line = line[0..79] + ' (more)'
end
code << "#{prefix}#{number}: #{line}\n"
end
raise Racc::ParseError, <<-EOF.strip
Unexpected #{name} on line #{@line}:
#{code}
EOF
raise Racc::ParseError, "Unexpected #{name} on line #{@line}"
end
##