Class: Pegex::Input

Inherits:
Object
  • Object
show all
Defined in:
lib/pegex/input.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Input

Returns a new instance of Input.

Yields:

  • (_self)

Yield Parameters:

  • _self (Pegex::Input)

    the object that the method was called on



7
8
9
10
11
12
# File 'lib/pegex/input.rb', line 7

def initialize
  @is_eof = false
  @is_open = false
  @is_close = false
  yield self
end

Instance Attribute Details

#fileObject

Returns the value of attribute file.



5
6
7
# File 'lib/pegex/input.rb', line 5

def file
  @file
end

#stringObject

Returns the value of attribute string.



4
5
6
# File 'lib/pegex/input.rb', line 4

def string
  @string
end

Instance Method Details

#closeObject



27
28
29
30
31
32
33
34
# File 'lib/pegex/input.rb', line 27

def close
  fail "Attempted to close an unopen Pegex::Input object" \
    if @is_close
  @is_open = false
  @is_close = true
  @buffer = nil
  return self
end

#openObject



21
22
23
24
25
# File 'lib/pegex/input.rb', line 21

def open
  @buffer = @string \
    or fail "Pegex::Input::open failed. No source to open"
  @is_open = true
end

#open?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/pegex/input.rb', line 36

def open?
  @is_open
end

#readObject



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

def read
  buffer = @buffer
  @buffer = nil
  @eof = true
  return buffer
end