class LL::Message
A warning/error generated during the compilation of a grammar.
Constants
- COLORS
The colours to use for the various message types.
@return [Hash]
Attributes
message[R]
source_line[R]
type[R]
Public Class Methods
new(type, message, source_line)
click to toggle source
@param [Symbol] type @param [String] message @param [LL::SourceLine] source_line
# File lib/ll/message.rb, line 23 def initialize(type, message, source_line) @type = type @message = message @source_line = source_line end
Public Instance Methods
column()
click to toggle source
@return [Fixnum]
# File lib/ll/message.rb, line 87 def column return source_line.column end
determine_path()
click to toggle source
Returns the path to the source of the message. If the path resides in the current working directory (or a child directory) the path is relative, otherwise it's absolute.
@return [String]
# File lib/ll/message.rb, line 59 def determine_path if source_line.file == SourceLine::DEFAULT_FILE return source_line.file end full_path = File.expand_path(source_line.file) pwd = Dir.pwd if full_path.start_with?(pwd) from = Pathname.new(full_path) to = Pathname.new(pwd) return from.relative_path_from(to).to_s else return full_path end end
inspect()
click to toggle source
@return [String]
# File lib/ll/message.rb, line 47 def inspect return "Message(type: #{type.inspect}, message: #{message.inspect}, " \ "file: #{determine_path.inspect}, line: #{line}, column: #{column})" end
line()
click to toggle source
@return [Fixnum]
# File lib/ll/message.rb, line 80 def line return source_line.line end
to_s()
click to toggle source
Returns a String containing details of the message, complete with ANSI colour sequences.
@return [String]
# File lib/ll/message.rb, line 35 def to_s location = ANSI.ansi("#{determine_path}:#{line}:#{column}", :white, :bold) type_label = ANSI.ansi(type.to_s, COLORS[type], :bold) msg_line = "#{location}:#{type_label}: #{message}" return "#{msg_line}\n#{source_line.source}\n#{marker}" end
Private Instance Methods
marker()
click to toggle source
@return [String]
# File lib/ll/message.rb, line 96 def marker padding = ' ' * (column - 1) return padding + ANSI.ansi('^', :magenta, :bold) end