Class: NamedList

Inherits:
Object show all
Defined in:
lib/tecsgen/core/syntaxobj.rb

Instance Method Summary collapse

Constructor Details

#initialize(item, type) ⇒ NamedList

@type

string エラーメッセージ



220
221
222
223
224
225
# File 'lib/tecsgen/core/syntaxobj.rb', line 220

def initialize(item, type)
  @names = {}
  @items = []
  @type = type
  add_item(item)
end

Instance Method Details

#add_item(item) ⇒ Object

要素を加える

parse した時点で加えること(場所を記憶する)



229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# File 'lib/tecsgen/core/syntaxobj.rb', line 229

def add_item(item)
  if item
    assert_name item
    name = item.get_name
    prev = @names[name]
    if prev
      Generator.error("S2001 \'$1\' duplicate $2", name, @type)
      prev_locale = prev.get_locale
      puts "previous: #{prev_locale[0]}: line #{prev_locale[1]} \'#{name}\' defined here"
      return self
    end

    @names[name] = item
    @items << item
  end

  return self
end

#assert_name(item) ⇒ Object



312
313
314
315
316
# File 'lib/tecsgen/core/syntaxobj.rb', line 312

def assert_name(item)
  if !item.get_name.is_a? Symbol
    raise "Not symbol for NamedList item"
  end
end

#change_item(item) ⇒ Object



248
249
250
251
252
253
254
255
256
257
# File 'lib/tecsgen/core/syntaxobj.rb', line 248

def change_item(item)
  assert_name item
  name = item.get_name

  prev_one = @names[name]
  @names[name] = item

  @items = @items - [prev_one]
  @items << item
end

#clone_for_composite(ct_name, cell_name, locale) ⇒ Object

composite cell を clone した時に要素(JOIN) の clone する

mikan このメソッドは Join に特化されているので NamedList から分離すべき



289
290
291
292
293
# File 'lib/tecsgen/core/syntaxobj.rb', line 289

def clone_for_composite(ct_name, cell_name, locale)
  cl = self.clone
  cl.set_cloned(ct_name, cell_name, locale)
  return cl
end

#del_item(item) ⇒ Object



259
260
261
262
263
264
265
# File 'lib/tecsgen/core/syntaxobj.rb', line 259

def del_item(item)
  assert_name item
  name = item.get_name
  @names.delete name

  @items = @items - [item]
end

#get_item(name) ⇒ Object



267
268
269
270
271
272
273
274
275
276
277
278
279
280
# File 'lib/tecsgen/core/syntaxobj.rb', line 267

def get_item(name)
  if !name.is_a? Symbol
    print "get_item: '#{name}', items are below\n"
    @names.each{|nm, item|
      p nm
    }
    raise "get_item: #{name}: not Symbol"
  end
  if name
    return @names[name.to_sym]
  else
    return nil
  end
end

#get_itemsObject



282
283
284
# File 'lib/tecsgen/core/syntaxobj.rb', line 282

def get_items
  return @items
end

#set_cloned(ct_name, cell_name, locale) ⇒ Object

clone された NamedList インスタンスの参照するもの(item)を clone

mikan このメソッドは Join に特化されているので NamedList から分離すべき



298
299
300
301
302
303
304
305
306
307
308
309
310
# File 'lib/tecsgen/core/syntaxobj.rb', line 298

def set_cloned(ct_name, cell_name, locale)
  items = []
  names = {}
  @items.each {|i|
    dbgPrint "NamedList clone #{ct_name}, #{cell_name}, #{i.get_name}\n"

    cl = i.clone_for_composite(ct_name, cell_name, locale)
    names[cl.get_name] = cl
    items << cl
  }
  @items = items
  @names = names
end

#show_tree(indent) ⇒ Object



318
319
320
321
322
# File 'lib/tecsgen/core/syntaxobj.rb', line 318

def show_tree(indent)
  @items.each {|i|
    i.show_tree(indent)
  }
end