Class: Flor::Parser::Nod

Inherits:
Object
  • Object
show all
Defined in:
lib/flor/parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tree, outdent) ⇒ Nod

Returns a new instance of Nod.



503
504
505
506
507
508
509
510
511
512
513
514
515
# File 'lib/flor/parser.rb', line 503

def initialize(tree, outdent)

  @parent = nil
  @indent = -1
  @head = 'sequence'
  @children = []
  @line = 0

  @outdent = outdent ? outdent.strip : nil
  @outdent = nil if @outdent && @outdent.size < 1

  read(tree) if tree
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



501
502
503
# File 'lib/flor/parser.rb', line 501

def children
  @children
end

#indentObject

Returns the value of attribute indent.



500
501
502
# File 'lib/flor/parser.rb', line 500

def indent
  @indent
end

#parentObject

Returns the value of attribute parent.



500
501
502
# File 'lib/flor/parser.rb', line 500

def parent
  @parent
end

#typeObject (readonly)

Returns the value of attribute type.



501
502
503
# File 'lib/flor/parser.rb', line 501

def type
  @type
end

Instance Method Details

#append(node) ⇒ Object



517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
# File 'lib/flor/parser.rb', line 517

def append(node)

  if @outdent
    if @outdent.index('\\')
      node.indent = self.indent + 2
    elsif @outdent.index('|') || @outdent.index(';')
      node.indent = self.indent
    end
    @outdent = nil
  end

  if node.indent > self.indent
    @children << node
    node.parent = self
  else
    @parent.append(node)
  end
end

#to_aObject



536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
# File 'lib/flor/parser.rb', line 536

def to_a

  return [ @head, @children, @line ] unless @children.is_a?(Array)
  return @head if @head.is_a?(Array) && @children.empty?

  cn = @children.collect(&:to_a)

  as, non_atts = cn.partition { |c| c[0] == '_att' }
  atts, suff = [], nil

  as.each do |c|

    if %w[ if unless ].include?(c[1])
      suff = []
    elsif suff && c[1].length > 1
      iou = suff.shift; iou[1] = [ [ iou[1], [], iou[2] ] ]
      atts << iou
      atts.concat(suff)
      suff = nil
    end

    (suff || atts) << c
  end

  atts, non_atts = ta_rework_arr_or_obj(atts, non_atts)

  core = [ @head, atts + non_atts, @line ]
  core = core[0] if core[0].is_a?(Array) && core[1].empty?
  core = ta_rework_core(core) if core[0].is_a?(Array)

  return core unless suff

  ta_rework_suff(core, suff)
end