Module: EDNGRAMMAR::String2

Defined in:
lib/parser/edngrammar.rb

Instance Method Summary collapse

Instance Method Details

#astObject



460
461
462
463
464
465
466
467
468
# File 'lib/parser/edngrammar.rb', line 460

def ast
  arr = [elements[0].ast] + elements[1].elements.map {|x| x.elements[1].ast}
  charr = arr.chunk(&:class).to_a
  if charr.size == 1
    unpack_chunk(*charr.first)
  else
    CBOR::Tagged.new(888, charr.map {|x| unpack_chunk(*x)})
  end
end

#join1(s) ⇒ Object



447
448
449
# File 'lib/parser/edngrammar.rb', line 447

def join1(s)
  s.join # XXX -- look at encoding and ei
end

#unpack_chunk(c, s) ⇒ Object



450
451
452
453
454
455
456
457
458
459
# File 'lib/parser/edngrammar.rb', line 450

def unpack_chunk(c, s)
  if c == String
    join1(s)
  else
    unless c == CBOR::Tagged && s.first.tag == 888 && s.first.value == nil # XXX check all values?
      raise "*** unjoinable chunks #{c.inspect} #{s.inspect}" if s.size != 1
    end
    s.first
  end
end