Exception: DMark::Lexer::LexerError
- Inherits:
-
StandardError
- Object
- StandardError
- DMark::Lexer::LexerError
- Defined in:
- lib/dmark/lexer.rb
Defined Under Namespace
Classes: Coloriser, NullColoriser
Instance Method Summary collapse
- #formatted_message(coloriser) ⇒ Object
-
#initialize(message, line, line_nr, col_nr) ⇒ LexerError
constructor
A new instance of LexerError.
- #message ⇒ Object
- #message_for_tty ⇒ Object
Constructor Details
#initialize(message, line, line_nr, col_nr) ⇒ LexerError
Returns a new instance of LexerError.
94 95 96 97 98 99 |
# File 'lib/dmark/lexer.rb', line 94 def initialize(, line, line_nr, col_nr) @message = @line = line @line_nr = line_nr @col_nr = col_nr end |
Instance Method Details
#formatted_message(coloriser) ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/dmark/lexer.rb', line 137 def (coloriser) line_excerpt_start = [@col_nr - 38, 0].max line_excerpt_end = @col_nr + 38 line_excerpt = @line[line_excerpt_start..line_excerpt_end] if line_excerpt_start > 0 line_excerpt[0] = '…' end if line_excerpt_end < @line.size line_excerpt[-1] = '…' end [ "#{coloriser.red}#{coloriser.bold}ERROR#{coloriser.reset} (line #{@line_nr}, col #{@col_nr}): #{coloriser.red}#{@message}#{coloriser.reset}", '', line_excerpt, coloriser.red + ' ' * (@col_nr - 1 - line_excerpt_start) + '^' + coloriser.reset, '', ].join("\n") end |
#message ⇒ Object
129 130 131 |
# File 'lib/dmark/lexer.rb', line 129 def (NullColoriser.new) end |