Class: PackratParser::Success

Inherits:
Object
  • Object
show all
Defined in:
lib/packrat_parser/result.rb

Overview

The result of running a parser at some position in the input.

Success carries the parsed value and pos, the index of the next unconsumed character. Failure carries the pos where parsing failed and a human-readable message.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, pos) ⇒ Success

Returns a new instance of Success.



10
11
12
13
# File 'lib/packrat_parser/result.rb', line 10

def initialize(value, pos)
  @value = value
  @pos = pos
end

Instance Attribute Details

#posObject (readonly)

Returns the value of attribute pos.



8
9
10
# File 'lib/packrat_parser/result.rb', line 8

def pos
  @pos
end

#valueObject (readonly)

Returns the value of attribute value.



8
9
10
# File 'lib/packrat_parser/result.rb', line 8

def value
  @value
end

Instance Method Details

#success?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/packrat_parser/result.rb', line 15

def success?
  true
end

#to_sObject Also known as: inspect



19
20
21
# File 'lib/packrat_parser/result.rb', line 19

def to_s
  "Success(#{@value.inspect} @#{@pos})"
end