Module: BisonParser::Base

Included in:
BisonParser
Defined in:
lib/bison_parser/base.rb

Instance Method Summary collapse

Instance Method Details

#begin_tokenObject



30
31
32
33
# File 'lib/bison_parser/base.rb', line 30

def begin_token
  self.token_row = row
  self.token_col = col
end

#error(msg, row, col) ⇒ Object

Raises:



35
36
37
# File 'lib/bison_parser/base.rb', line 35

def error(msg, row, col)
  raise Error.new(msg, source, row, col)
end

#initialize(io) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/bison_parser/base.rb', line 7

def initialize(io)
  if String === io
    io = ::File.open(io, 'r')
  end
  @source = io.respond_to?(:path) ? io.path : nil
  @io, @row, @col = io, 1, 0
end

#peakObject



26
27
28
# File 'lib/bison_parser/base.rb', line 26

def peak
  io.read(1).tap{ |c| io.ungetc(c) if c }
end

#readObject



15
16
17
18
19
20
21
22
23
24
# File 'lib/bison_parser/base.rb', line 15

def read
  io.read(1).tap do |c|
    if c == "\n"
      self.row += 1
      self.col = 0
    elsif c
      self.col += 1
    end
  end
end