#
# DO NOT MODIFY!!!!
# This file is automatically generated by Racc 1.4.14
# from Racc grammer file "".
#

require 'racc/parser.rb'

require_relative './lexer'

class HCLParser < Racc::Parser

module_eval(<<'...end parse.y/module_eval...', 'parse.y', 119)
  #//
  #//       HCL is unclear on what one should do when duplicate
  #//       keys are encountered.
  #//
  #//       from decoder.go: if we're at the root or we're directly within
  #//                        a list, decode  to hashes, otherwise lists
  #//
  #//       from object.go:  there is a flattened list structure
  #//
  def flatten_objectlist(list)
    list.each_with_object({}) do |a, h|
      h[a.first] =
        case a.last
        when Hash
          deep_merge(h[a.first] || {}, a.last)
        else
          h[a.first] = a.last
        end
    end
  end


  def on_error(error_token_id, error_value, value_stack)
    error_message = value_stack.to_s.split(',').last.gsub(']', '')
    header = "Parse error at #{error_message} #{error_value} (invalid token: #{error_value})"
    raise Racc::ParseError, header
  end


  def parse(input)
    @lexer = HCLLexer.new.lex(input)
    do_parse
    return @result
  end


  def next_token
    @lexer.shift
  end

  def deep_merge(hash1, hash2)
    hash2.keys.each do |key|
      value1 = hash1[key]
      value2 = hash2[key]

      if value1.is_a?(Hash) && value2.is_a?(Hash)
        hash1[key] = deep_merge(value1, value2)
      else
        hash1[key] = value2
      end
    end

    hash1
  end
...end parse.y/module_eval...
##### State transition tables begin ###

racc_action_table = [
    20,    26,    25,    18,    26,    25,     5,    21,     6,    13,
    33,    24,    13,    12,    24,    30,    26,    25,    38,     5,
    -9,     6,    33,     5,    13,     6,    24,    37,    28,     5,
    -8,     6,    10,    16,    36,    17,   nil,    13 ]

racc_action_check = [
    12,    12,    12,    10,    24,    24,     0,    12,     0,    12,
    24,    12,    24,     7,    24,    24,    38,    38,    29,     3,
     6,     3,    38,    13,    38,    13,    38,    29,    13,    27,
     5,    27,     1,     9,    27,     9,   nil,     9 ]

racc_action_pointer = [
    -1,    32,   nil,    12,   nil,    22,    12,     5,   nil,    26,
     3,   nil,    -2,    16,   nil,   nil,   nil,   nil,   nil,   nil,
   nil,   nil,   nil,   nil,     1,   nil,   nil,    22,   nil,    13,
   nil,   nil,   nil,   nil,   nil,   nil,   nil,   nil,    13,   nil ]

racc_action_default = [
    -2,   -31,    -1,    -3,    -4,   -18,   -19,   -31,   -15,   -31,
   -31,    -5,   -31,   -31,   -16,   -17,   -18,   -19,    40,   -10,
   -11,   -12,   -13,   -14,   -31,   -29,   -30,   -31,    -7,   -31,
   -21,   -22,   -25,   -26,   -27,   -28,    -6,   -20,   -24,   -23 ]

racc_goto_table = [
    11,    31,    14,     3,    15,    22,    29,    19,     2,     1,
    23,   nil,   nil,   nil,   nil,    39,    27,   nil,   nil,   nil,
   nil,   nil,   nil,   nil,    11 ]

racc_goto_check = [
     4,    12,     5,     3,     9,     5,    11,     7,     2,     1,
     8,   nil,   nil,   nil,   nil,    12,     3,   nil,   nil,   nil,
   nil,   nil,   nil,   nil,     4 ]

racc_goto_pointer = [
   nil,     9,     8,     3,    -3,    -7,   nil,    -5,    -2,    -5,
   nil,   -18,   -23 ]

racc_goto_default = [
   nil,   nil,   nil,   nil,     4,    35,     7,    32,    34,     8,
     9,   nil,   nil ]

racc_reduce_table = [
  0, 0, :racc_error,
  1, 19, :_reduce_1,
  0, 20, :_reduce_2,
  1, 20, :_reduce_none,
  1, 21, :_reduce_4,
  2, 21, :_reduce_5,
  3, 23, :_reduce_6,
  2, 23, :_reduce_7,
  1, 24, :_reduce_8,
  1, 24, :_reduce_9,
  3, 22, :_reduce_10,
  3, 22, :_reduce_11,
  3, 22, :_reduce_12,
  3, 22, :_reduce_13,
  3, 22, :_reduce_14,
  1, 22, :_reduce_15,
  2, 27, :_reduce_16,
  2, 27, :_reduce_17,
  1, 28, :_reduce_18,
  1, 28, :_reduce_19,
  3, 26, :_reduce_20,
  2, 26, :_reduce_21,
  1, 29, :_reduce_22,
  3, 29, :_reduce_23,
  2, 29, :_reduce_24,
  1, 30, :_reduce_25,
  1, 30, :_reduce_26,
  1, 30, :_reduce_27,
  1, 30, :_reduce_28,
  1, 25, :_reduce_29,
  1, 25, :_reduce_30 ]

racc_reduce_n = 31

racc_shift_n = 40

racc_token_table = {
  false => 0,
  :error => 1,
  :BOOL => 2,
  :FLOAT => 3,
  :NUMBER => 4,
  :COMMA => 5,
  :COMMAEND => 6,
  :IDENTIFIER => 7,
  :EQUAL => 8,
  :STRING => 9,
  :MINUS => 10,
  :LEFTBRACE => 11,
  :RIGHTBRACE => 12,
  :LEFTBRACKET => 13,
  :RIGHTBRACKET => 14,
  :PERIOD => 15,
  :EPLUS => 16,
  :EMINUS => 17 }

racc_nt_base = 18

racc_use_result_var = true

Racc_arg = [
  racc_action_table,
  racc_action_check,
  racc_action_default,
  racc_action_pointer,
  racc_goto_table,
  racc_goto_check,
  racc_goto_default,
  racc_goto_pointer,
  racc_nt_base,
  racc_reduce_table,
  racc_token_table,
  racc_shift_n,
  racc_reduce_n,
  racc_use_result_var ]

Racc_token_to_s_table = [
  "$end",
  "error",
  "BOOL",
  "FLOAT",
  "NUMBER",
  "COMMA",
  "COMMAEND",
  "IDENTIFIER",
  "EQUAL",
  "STRING",
  "MINUS",
  "LEFTBRACE",
  "RIGHTBRACE",
  "LEFTBRACKET",
  "RIGHTBRACKET",
  "PERIOD",
  "EPLUS",
  "EMINUS",
  "$start",
  "target",
  "top",
  "objectlist",
  "objectitem",
  "object",
  "objectkey",
  "number",
  "list",
  "block",
  "block_id",
  "listitems",
  "listitem" ]

Racc_debug_parser = false

##### State transition tables end #####

# reduce 0 omitted

module_eval(<<'.,.,', 'parse.y', 19)
  def _reduce_1(val, _values, result)
     @result = flatten_objectlist(val[0])
    result
  end
.,.,

module_eval(<<'.,.,', 'parse.y', 22)
  def _reduce_2(val, _values, result)
     result = val[0] 
    result
  end
.,.,

# reduce 3 omitted

module_eval(<<'.,.,', 'parse.y', 29)
  def _reduce_4(val, _values, result)
     result = [val[0]] 
    result
  end
.,.,

module_eval(<<'.,.,', 'parse.y', 31)
  def _reduce_5(val, _values, result)
     result = val[0] << val[1]  
    result
  end
.,.,

module_eval(<<'.,.,', 'parse.y', 36)
  def _reduce_6(val, _values, result)
     result = flatten_objectlist(val[1]) 
    result
  end
.,.,

module_eval(<<'.,.,', 'parse.y', 38)
  def _reduce_7(val, _values, result)
     return 
    result
  end
.,.,

module_eval(<<'.,.,', 'parse.y', 43)
  def _reduce_8(val, _values, result)
     result = val[0] 
    result
  end
.,.,

module_eval(<<'.,.,', 'parse.y', 45)
  def _reduce_9(val, _values, result)
     result = val[0] 
    result
  end
.,.,

module_eval(<<'.,.,', 'parse.y', 50)
  def _reduce_10(val, _values, result)
     result = val[0], val[2] 
    result
  end
.,.,

module_eval(<<'.,.,', 'parse.y', 52)
  def _reduce_11(val, _values, result)
     result = val[0], val[2] 
    result
  end
.,.,

module_eval(<<'.,.,', 'parse.y', 54)
  def _reduce_12(val, _values, result)
     result = val[0], val[2] 
    result
  end
.,.,

module_eval(<<'.,.,', 'parse.y', 56)
  def _reduce_13(val, _values, result)
     result = val[0], val[2] 
    result
  end
.,.,

module_eval(<<'.,.,', 'parse.y', 58)
  def _reduce_14(val, _values, result)
     result = val[0], val[2] 
    result
  end
.,.,

module_eval(<<'.,.,', 'parse.y', 60)
  def _reduce_15(val, _values, result)
     result = val[0] 
    result
  end
.,.,

module_eval(<<'.,.,', 'parse.y', 65)
  def _reduce_16(val, _values, result)
     result = val[0], val[1] 
    result
  end
.,.,

module_eval(<<'.,.,', 'parse.y', 67)
  def _reduce_17(val, _values, result)
     result = val[0], {val[1][0] => val[1][1]} 
    result
  end
.,.,

module_eval(<<'.,.,', 'parse.y', 72)
  def _reduce_18(val, _values, result)
     result = val[0] 
    result
  end
.,.,

module_eval(<<'.,.,', 'parse.y', 74)
  def _reduce_19(val, _values, result)
     result = val[0] 
    result
  end
.,.,

module_eval(<<'.,.,', 'parse.y', 79)
  def _reduce_20(val, _values, result)
     result = val[1] 
    result
  end
.,.,

module_eval(<<'.,.,', 'parse.y', 81)
  def _reduce_21(val, _values, result)
     return 
    result
  end
.,.,

module_eval(<<'.,.,', 'parse.y', 86)
  def _reduce_22(val, _values, result)
     result = [val[0]] 
    result
  end
.,.,

module_eval(<<'.,.,', 'parse.y', 88)
  def _reduce_23(val, _values, result)
     result = val[0] << val[2] 
    result
  end
.,.,

module_eval(<<'.,.,', 'parse.y', 90)
  def _reduce_24(val, _values, result)
     result = val[0] 
    result
  end
.,.,

module_eval(<<'.,.,', 'parse.y', 95)
  def _reduce_25(val, _values, result)
     result = val[0] 
    result
  end
.,.,

module_eval(<<'.,.,', 'parse.y', 97)
  def _reduce_26(val, _values, result)
     result = val[0] 
    result
  end
.,.,

module_eval(<<'.,.,', 'parse.y', 99)
  def _reduce_27(val, _values, result)
     result = val[0] 
    result
  end
.,.,

module_eval(<<'.,.,', 'parse.y', 101)
  def _reduce_28(val, _values, result)
     result = val[0] 
    result
  end
.,.,

module_eval(<<'.,.,', 'parse.y', 106)
  def _reduce_29(val, _values, result)
     result = val[0] 
    result
  end
.,.,

module_eval(<<'.,.,', 'parse.y', 108)
  def _reduce_30(val, _values, result)
     result = val[0] 
    result
  end
.,.,

def _reduce_none(val, _values, result)
  val[0]
end

end   # class HCLParser
