# File lib/toml/parser.rb, line 5
    def initialize(markup)
      # Make sure we have a newline on the end
      
      markup += "\n" unless markup.end_with?("\n") || markup.length == 0
      begin
        tree = Parslet.new.parse(markup)
      rescue Parslet::ParseFailed => failure
        puts failure.cause.ascii_tree
      end
      
      
      parts = Transformer.new.apply(tree) || []
      @parsed = {}
      @current = @parsed
      @current_path = ''
      
      parts.each do |part|
        if part.is_a? Key
          # If @current is an array then we're in a key-group
          if @current.is_a? Array
            # Make sure there's a table to work with.
            @current << {} if @current.last.nil?
            # Set the key on the table.
            @current.last[part.key] = part.value
            next
          end
          # Make sure the key isn't already set
          if !@current.is_a?(Hash) || @current.has_key?(part.key)
            err = "Cannot override key '#{part.key}'"
            unless @current_path.empty?
              err += " at path '#{@current_path}'"
            end
            raise err
          end
          # Set the key-value into the current hash
          @current[part.key] = part.value
        elsif part.is_a?(TableArray)
          resolve_table_array(part)
        elsif part.is_a?(Table)
          resolve_table(part)
        else
          raise "Unrecognized part: #{part.inspect}"
        end
      end
    end