Exception: Grammar::ParserError
- Inherits:
-
StandardError
- Object
- StandardError
- Grammar::ParserError
- Defined in:
- lib/emerald/grammar.rb
Overview
When the parser fails on a line from user input
Direct Known Subclasses
Constant Summary collapse
- LINES_BEFORE =
3- LINES_AFTER =
1
Instance Method Summary collapse
-
#initialize(line_number, reason, source) ⇒ ParserError
constructor
A new instance of ParserError.
- #message ⇒ Object
Constructor Details
#initialize(line_number, reason, source) ⇒ ParserError
26 27 28 29 30 |
# File 'lib/emerald/grammar.rb', line 26 def initialize(line_number, reason, source) @line_number = line_number @reason = reason @source = source end |
Instance Method Details
#message ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/emerald/grammar.rb', line 32 def = [] if match = @reason.match(/(Expected .+?) at line/) << match[1] else << @reason end lines = @source.split(/\n/) LINES_BEFORE.downto(1).each do |i| << ' ' + lines[@line_number - i - 1] if lines[@line_number - i - 1] end << '>>> ' + lines[@line_number - 1] 1.upto(LINES_AFTER).each do |i| << ' ' + lines[@line_number + i - 1] if lines[@line_number + i - 1] end .join("\n") end |