Module: EDNGRAMMAR::String2

Defined in:
lib/parser/edngrammar.rb

Instance Method Summary collapse

Instance Method Details

#astObject



364
365
366
367
368
369
370
371
372
# File 'lib/parser/edngrammar.rb', line 364

def ast
  arr = [elements[0].ast] + elements[1].elements.map {|x| x.elements[3].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



351
352
353
# File 'lib/parser/edngrammar.rb', line 351

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

#unpack_chunk(c, s) ⇒ Object



354
355
356
357
358
359
360
361
362
363
# File 'lib/parser/edngrammar.rb', line 354

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