class LL::Driver

Parser driver for generated parsers.

Public Instance Methods

id_to_terminal(id) click to toggle source

Returns the Symbol of the terminal index.

@param [Fixnum] id @return [Symbol]

# File lib/ll/driver.rb, line 63
def id_to_terminal(id)
  return self.class::CONFIG.terminals[id]
end
id_to_type(id) click to toggle source

Returns the Symbol that belongs to the stack type number.

@example

id_to_type(1) # => :terminal

@param [Fixnum] id @return [Symbol]

# File lib/ll/driver.rb, line 53
def id_to_type(id)
  return ConfigurationCompiler::TYPES.invert[id]
end
parser_error(stack_type, stack_value, token_type, token_value) click to toggle source

@param [Fixnum] stack_type @param [Fixnum] stack_value @param [Symbol] token_type @param [Mixed] token_value

# File lib/ll/driver.rb, line 12
def parser_error(stack_type, stack_value, token_type, token_value)
  message = parser_error_message(stack_type, stack_value, token_type)

  raise ParserError, message
end
parser_error_message(stack_type, stack_value, token_type) click to toggle source

@param [Fixnum] stack_type @param [Fixnum] stack_value @param [Symbol] token_type @return [String]

# File lib/ll/driver.rb, line 24
def parser_error_message(stack_type, stack_value, token_type)
  case id_to_type(stack_type)
  when :rule
    message = "Unexpected #{token_type} for rule #{stack_value}"
  when :terminal
    expected = id_to_terminal(stack_value)
    message  = "Unexpected #{token_type}, expected #{expected} instead"
  when :eof
    message = "Received #{token_type} but there's nothing left to parse"
  when :star
    message = %Q{Unexpected #{token_type} for a "*" operator}
  when :plus
    message = %Q{Unexpected #{token_type} for a "+" operator}
  when :question
    message = %Q{Unexpected #{token_type} for a "?" operator}
  end

  return message
end