Class: LL::Driver

Inherits:
Object
  • Object
show all
Defined in:
lib/ll/driver.rb

Overview

Parser driver for generated parsers.

Direct Known Subclasses

Parser

Instance Method Summary collapse

Instance Method Details

#id_to_terminal(id) ⇒ Symbol

Returns the Symbol of the terminal index.



57
58
59
# File 'lib/ll/driver.rb', line 57

def id_to_terminal(id)
  return self.class::CONFIG.terminals[id]
end

#id_to_type(id) ⇒ Symbol

Returns the Symbol that belongs to the stack type number.

Examples:

id_to_type(1) # => :terminal


47
48
49
# File 'lib/ll/driver.rb', line 47

def id_to_type(id)
  return ConfigurationCompiler::TYPES.invert[id]
end

#parser_error(stack_type, stack_value, token_type, token_value) ⇒ Object

Raises:



12
13
14
15
16
# 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) ⇒ String



24
25
26
27
28
29
30
31
32
33
34
35
36
# 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"
  end

  return message
end