Module: EDNGRAMMAR::String2

Defined in:
lib/parser/edngrammar.rb

Instance Method Summary collapse

Instance Method Details

#astObject



380
381
382
383
384
385
386
387
388
# File 'lib/parser/edngrammar.rb', line 380

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



367
368
369
# File 'lib/parser/edngrammar.rb', line 367

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

#unpack_chunk(c, s) ⇒ Object



370
371
372
373
374
375
376
377
378
379
# File 'lib/parser/edngrammar.rb', line 370

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