class Riemann::Tools::Utils::StringTokenizer

Attributes

tokens[R]

Public Class Methods

new(text) click to toggle source
# File lib/riemann/tools/utils.rb, line 11
def initialize(text)
  @scanner = StringScanner.new(text)

  @lineno = 1
  @pos = 0
  @line = next_line
  @tokens = []
end

Public Instance Methods

eos?() click to toggle source
# File lib/riemann/tools/utils.rb, line 24
def eos?
  @scanner.eos?
end
matched() click to toggle source
# File lib/riemann/tools/utils.rb, line 28
def matched
  @scanner.matched
end
next_line() click to toggle source
# File lib/riemann/tools/utils.rb, line 32
def next_line
  (@scanner.check_until(/\n/) || @scanner.rest).chomp
end
push_token(token, value = nil) click to toggle source
# File lib/riemann/tools/utils.rb, line 36
def push_token(token, value = nil)
  value ||= @scanner.matched

  if value == "\n"
    @lineno += 1
    @line = next_line
    @pos = pos = 0
  else
    pos = @pos
    @pos += @scanner.matched.length
  end

  @tokens << [token, { value: value, line: @line, lineno: @lineno, pos: pos }] if token
end
scan(expression) click to toggle source
# File lib/riemann/tools/utils.rb, line 20
def scan(expression)
  @scanner.scan(expression)
end
unexpected_token() click to toggle source
# File lib/riemann/tools/utils.rb, line 51
def unexpected_token
  raise(Racc::ParseError, "unexpected data on line #{@lineno}:\n#{@line}\n#{' ' * @pos}^")
end