Method: #stringify_root

Defined in:
lib/interscript/utils/regexp_converter.rb

#stringify_root(root, indent: 0) ⇒ Object



236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
# File 'lib/interscript/utils/regexp_converter.rb', line 236

def stringify_root(root, indent: 0)
  warning = ''
  root[:from] = [""] if root[:from] == []
  str = " "*indent+"sub #{stringify(root[:from])}, #{root[:to]}"
  [:before, :not_before, :after, :not_after].each do |look|
    # puts "#{look.inspect} = #{root[look]}"
    next unless root[look]
    str_look = stringify(root[look])
    str_look = "\"\"" if root[look] == [] || root[look] == nil
    #if str_look.empty?  #apparently it is empty sometimes. iso-mal-Mlym-Latn for example
    #  warning << "warning: #{look} is empty string;"
    #else
      str << ", #{look}: #{str_look}"
    #end
  end
  str = " "*indent+"# #{str} # warning: :" if str =~ /[^\[]:[^ \]]/
  str = " "*indent+"# #{str} # #{warning}" if !warning.empty?

  str = " "*indent+"# #{str} # warning: :missing unimplemented" if str.include?(':missing')
  str = " "*indent+"# #{str} # warning: :interval unimplemented" if str.include?(':interval')
  str = " "*indent+"# #{str} # warning: :adding_ranges unimplemented" if str.include?(':adding_ranges')
  if str.include?('zero_or_one')
    str = " "*indent+"# #{str} # warning: zero_or_one"
    puts "str.includes 'zero_or_one'"
    pp root
  end
  # str = " "*indent+"# #{str} # warning: one_or_more" if str.include?('one_or_more')
   str = " "*indent+"# #{str} # warning: :lookahead_start" if str.include?(':lookahead_start')
  # str += " # original: #{root[:from]}"
  str
end