Exception: Citrus::ParseError

Inherits:
Error show all
Defined in:
lib/citrus.rb

Overview

Raised when a parse fails.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input) ⇒ ParseError

The input given here is an instance of Citrus::Input.



125
126
127
128
129
130
131
132
133
134
135
# File 'lib/citrus.rb', line 125

def initialize(input)
  @offset = input.max_offset
  @line_offset = input.line_offset(offset)
  @line_number = input.line_number(offset)
  @line = input.line(offset)

  message = "Failed to parse input on line #{line_number}"
  message << " at offset #{line_offset}\n#{detail}"

  super(message)
end

Instance Attribute Details

#line ⇒ Object (readonly)

The text of the line in the input where the error occurred.



150
151
152
# File 'lib/citrus.rb', line 150

def line
  @line
end

#line_number ⇒ Object (readonly)

The 1-based number of the line in the input where the error occurred.



147
148
149
# File 'lib/citrus.rb', line 147

def line_number
  @line_number
end

#line_offset ⇒ Object (readonly)

The 0-based offset at which the error occurred on the line on which it occurred in the input.



144
145
146
# File 'lib/citrus.rb', line 144

def line_offset
  @line_offset
end

#offset ⇒ Object (readonly)

The 0-based offset at which the error occurred in the input, i.e. the maximum offset in the input that was successfully parsed before the error occurred.



140
141
142
# File 'lib/citrus.rb', line 140

def offset
  @offset
end

Instance Method Details

#detail ⇒ Object

Returns a string that, when printed, gives a visual representation of exactly where the error occurred on its line in the input.



154
155
156
# File 'lib/citrus.rb', line 154

def detail
  "#{line}\n#{' ' * line_offset}^"
end