Class: Peg::Parser::Input

Inherits:
Object
  • Object
show all
Defined in:
lib/peg.backup/parser/input.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



6
7
8
# File 'lib/peg.backup/parser/input.rb', line 6

def content
  @content
end

#posObject (readonly)

Returns the value of attribute pos.



6
7
8
# File 'lib/peg.backup/parser/input.rb', line 6

def pos
  @pos
end

Instance Method Details

#==(other) ⇒ Object



21
22
23
24
25
# File 'lib/peg.backup/parser/input.rb', line 21

def ==(other)
  self.class === other &&
    other.content == content &&
    other.pos == pos
end

#advance(by = 1) ⇒ Object



8
9
10
# File 'lib/peg.backup/parser/input.rb', line 8

def advance(by=1)
  self.class.new(content.drop(by), pos+by)
end

#empty?Boolean

Returns:

  • (Boolean)


12
# File 'lib/peg.backup/parser/input.rb', line 12

def empty? = content.empty?

#show(count) ⇒ Object

Raises:

  • (ArgumentError)


14
15
16
17
18
19
# File 'lib/peg.backup/parser/input.rb', line 14

def show(count)
  raise ArgumentError, "count must be an integer > 5" unless Integer === count && count > 5
  return content.join("") if content.length < count

  "#{content.take(count-3).join}..."
end