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 collapse
- COLORS =
The colours to use for the various message types.
{ :error => :red, :warning => :yellow }
Instance Attribute Summary collapse
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#source_line ⇒ Object
readonly
Returns the value of attribute source_line.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #column ⇒ Fixnum
-
#determine_path ⇒ String
Returns the path to the source of the message.
-
#initialize(type, message, source_line) ⇒ Message
constructor
A new instance of Message.
- #inspect ⇒ String
- #line ⇒ Fixnum
- #marker ⇒ String private
-
#to_s ⇒ String
Returns a String containing details of the message, complete with ANSI colour sequences.
Constructor Details
#initialize(type, message, source_line) ⇒ Message
23 24 25 26 27 |
# File 'lib/ll/message.rb', line 23 def initialize(type, , source_line) @type = type = @source_line = source_line end |
Instance Attribute Details
#message ⇒ Object (readonly)
Returns the value of attribute message.
6 7 8 |
# File 'lib/ll/message.rb', line 6 def end |
#source_line ⇒ Object (readonly)
Returns the value of attribute source_line.
6 7 8 |
# File 'lib/ll/message.rb', line 6 def source_line @source_line end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
6 7 8 |
# File 'lib/ll/message.rb', line 6 def type @type end |
Instance Method Details
#column ⇒ Fixnum
87 88 89 |
# File 'lib/ll/message.rb', line 87 def column return source_line.column end |
#determine_path ⇒ String
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 |
#inspect ⇒ String
47 48 49 50 |
# 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 ⇒ Fixnum
80 81 82 |
# File 'lib/ll/message.rb', line 80 def line return source_line.line end |
#marker ⇒ String (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 |
#to_s ⇒ String
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}: #{message}" return "#{msg_line}\n#{source_line.source}\n#{marker}" end |