Module: EDNGRAMMAR::String2

Defined in:
lib/parser/edngrammar.rb

Instance Method Summary collapse

Instance Method Details

#astObject



393
394
395
396
397
398
399
400
401
# File 'lib/parser/edngrammar.rb', line 393

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



380
381
382
# File 'lib/parser/edngrammar.rb', line 380

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

#unpack_chunk(c, s) ⇒ Object



383
384
385
386
387
388
389
390
391
392
# File 'lib/parser/edngrammar.rb', line 383

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