Class: Flor::Parser::Nod
- Inherits:
-
Object
- Object
- Flor::Parser::Nod
- Defined in:
- lib/flor/parser.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#indent ⇒ Object
Returns the value of attribute indent.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #append(node) ⇒ Object
-
#initialize(tree, outdent) ⇒ Nod
constructor
A new instance of Nod.
- #to_a ⇒ Object
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
#children ⇒ Object (readonly)
Returns the value of attribute children.
501 502 503 |
# File 'lib/flor/parser.rb', line 501 def children @children end |
#indent ⇒ Object
Returns the value of attribute indent.
500 501 502 |
# File 'lib/flor/parser.rb', line 500 def indent @indent end |
#parent ⇒ Object
Returns the value of attribute parent.
500 501 502 |
# File 'lib/flor/parser.rb', line 500 def parent @parent end |
#type ⇒ Object (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_a ⇒ Object
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 |