class Emfrp::Parser::ParsingError
Public Class Methods
new(src_str, file_name, status)
click to toggle source
# File lib/emfrp/parser/parsing_error.rb, line 6 def initialize(src_str, file_name, status) @src_str = src_str @file_name = file_name @status = status end
Public Instance Methods
code()
click to toggle source
# File lib/emfrp/parser/parsing_error.rb, line 12 def code @status.message[:code] || :noname end
column_number()
click to toggle source
# File lib/emfrp/parser/parsing_error.rb, line 24 def column_number if @status.rest.length > 0 @status.rest[0].tag[:column_number] else @src_str.each_line.last.length end end
line()
click to toggle source
# File lib/emfrp/parser/parsing_error.rb, line 32 def line @src_str.each_line.to_a[line_number - 1] end
line_number()
click to toggle source
# File lib/emfrp/parser/parsing_error.rb, line 16 def line_number if @status.rest.length > 0 @status.rest[0].tag[:line_number] else @src_str.each_line.count end end
print_error(output_io)
click to toggle source
# File lib/emfrp/parser/parsing_error.rb, line 36 def print_error(output_io) output_io << "#{@file_name}:#{line_number}: " output_io << "SyntaxError, in `#{@status.message[:place]}`: " output_io << "#{@status.message[:required]} is expected" if @status.rest.length == 0 output_io << ", but parser reached end-of-file\n" else output_io << "\n#{line.chomp}\n" output_io << "#{" " * (column_number - 1)}#{"^".colorize(:green)}\n" end end