Class: LL::Message
- Inherits:
-
Object
- Object
- LL::Message
- Defined in:
- lib/ll/message.rb
Overview
A warning/error generated during the compilation of a grammar.
Constant Summary
- COLORS =
The colours to use for the various message types.
{ :error => :red, :warning => :yellow }
Instance Attribute Summary (collapse)
-
- (Object) message
readonly
Returns the value of attribute message.
-
- (Object) source_line
readonly
Returns the value of attribute source_line.
-
- (Object) type
readonly
Returns the value of attribute type.
Instance Method Summary (collapse)
-
- (Fixnum) column
-
- (String) determine_path
Returns the path to the source of the message.
-
- (Message) initialize(type, message, source_line)
constructor
A new instance of Message.
-
- (String) inspect
-
- (Fixnum) line
-
- (String) marker
private
-
- (String) to_s
Returns a String containing details of the message, complete with ANSI colour sequences.
Constructor Details
- (Message) initialize(type, message, source_line)
Returns a new instance of Message
23 24 25 26 27 |
# File 'lib/ll/message.rb', line 23 def initialize(type, , source_line) @type = type @message = @source_line = source_line end |
Instance Attribute Details
- (Object) message (readonly)
Returns the value of attribute message
6 7 8 |
# File 'lib/ll/message.rb', line 6 def @message end |
- (Object) source_line (readonly)
Returns the value of attribute source_line
6 7 8 |
# File 'lib/ll/message.rb', line 6 def source_line @source_line end |
- (Object) type (readonly)
Returns the value of attribute type
6 7 8 |
# File 'lib/ll/message.rb', line 6 def type @type end |
Instance Method Details
- (Fixnum) column
87 88 89 |
# File 'lib/ll/message.rb', line 87 def column return source_line.column end |
- (String) determine_path
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.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# 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.(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 |
- (String) inspect
47 48 49 50 |
# File 'lib/ll/message.rb', line 47 def inspect return "Message(type: #{type.inspect}, message: #{.inspect}, " \ "file: #{determine_path.inspect}, line: #{line}, column: #{column})" end |
- (Fixnum) line
80 81 82 |
# File 'lib/ll/message.rb', line 80 def line return source_line.line end |
- (String) marker (private)
96 97 98 99 100 |
# File 'lib/ll/message.rb', line 96 def marker padding = ' ' * (column - 1) return padding + ANSI.ansi('^', :magenta, :bold) end |
- (String) to_s
Returns a String containing details of the message, complete with ANSI colour sequences.
35 36 37 38 39 40 41 42 |
# 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}: #{}" return "#{msg_line}\n#{source_line.source}\n#{marker}" end |