Class: Rattler::Runtime::ParseFailure
- Inherits:
-
Object
- Object
- Rattler::Runtime::ParseFailure
- Defined in:
- lib/rattler/runtime/parse_failure.rb
Overview
A ParseFailure
represents a position and explanation of a failed parse.
Instance Attribute Summary collapse
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#pos ⇒ Object
readonly
Returns the value of attribute pos.
Instance Method Summary collapse
-
#column ⇒ Integer
The (1-based) column number where the parse error occurred.
-
#initialize(source, pos, message_or_rule_name = nil) ⇒ ParseFailure
constructor
Create a new parse error object.
-
#line ⇒ Integer
The (1-based) line number where the parse error occurred.
-
#to_s ⇒ String
Return a string representation of the parse error suitable for showing to the user, e.g.
Constructor Details
#initialize(source, pos) ⇒ ParseFailure #initialize(source, pos, message) ⇒ ParseFailure #initialize(source, pos, rule_name) ⇒ ParseFailure
Create a new parse error object.
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rattler/runtime/parse_failure.rb', line 28 def initialize(source, pos, =nil) @source = source @pos = pos if @message ||= case when Symbol then "#{} expected" else end end @lc = Rattler::Util::LineCounter.new(source) end |
Instance Attribute Details
#message ⇒ Object (readonly)
Returns the value of attribute message.
40 41 42 |
# File 'lib/rattler/runtime/parse_failure.rb', line 40 def @message end |
#pos ⇒ Object (readonly)
Returns the value of attribute pos.
40 41 42 |
# File 'lib/rattler/runtime/parse_failure.rb', line 40 def pos @pos end |
Instance Method Details
#column ⇒ Integer
Returns the (1-based) column number where the parse error occurred.
44 45 46 |
# File 'lib/rattler/runtime/parse_failure.rb', line 44 def column @lc.column(pos) end |
#line ⇒ Integer
Returns the (1-based) line number where the parse error occurred.
50 51 52 |
# File 'lib/rattler/runtime/parse_failure.rb', line 50 def line @lc.line(pos) end |
#to_s ⇒ String
Return a string representation of the parse error suitable for showing to the user, e.g. “parse error at line 17, column 42: expr expected”
59 60 61 |
# File 'lib/rattler/runtime/parse_failure.rb', line 59 def to_s ? "#{intro_str}:\n #{}" : intro_str end |