lib/tomlrb/handler.rb in tomlrb-1.0.2 vs lib/tomlrb/handler.rb in tomlrb-1.0.3
- old
+ new
@@ -4,10 +4,11 @@
def initialize(**options)
@output = {}
@current = @output
@stack = []
+ @array_names = []
@symbolize_keys = options[:symbolize_keys]
end
def set_context(identifiers, is_array_of_tables: false)
@current = @output
@@ -26,12 +27,19 @@
end
end
def deal_with_array_of_tables(identifiers, is_array_of_tables)
identifiers.map!{|n| n.gsub("\"", '')}
- last_identifier = identifiers.pop if is_array_of_tables
+ stringified_identifier = identifiers.join('.')
+ if is_array_of_tables
+ @array_names << stringified_identifier
+ last_identifier = identifiers.pop
+ elsif @array_names.include?(stringified_identifier)
+ raise ParseError.new('Cannot define a normal table with the same name as an already established array')
+ end
+
yield(identifiers)
if is_array_of_tables
last_identifier = last_identifier.to_sym if @symbolize_keys
@current[last_identifier] ||= []
@@ -54,10 +62,9 @@
end
def end_(type)
array = []
while (value = @stack.pop) != [type]
- raise if value.nil?
array.unshift(value)
end
array
end
end