Class: Structured::ParserStack

Inherits:
Object
  • Object
show all
Defined in:
lib/structured/parser_stack.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, element:, parent:) ⇒ ParserStack

Returns a new instance of ParserStack.



5
6
7
8
9
# File 'lib/structured/parser_stack.rb', line 5

def initialize(type:, element:, parent:)
  @type = type
  @element = element
  @parent = parent
end

Instance Attribute Details

#elementObject

Returns the value of attribute element.



3
4
5
# File 'lib/structured/parser_stack.rb', line 3

def element
  @element
end

#parentObject

Returns the value of attribute parent.



3
4
5
# File 'lib/structured/parser_stack.rb', line 3

def parent
  @parent
end

#typeObject

Returns the value of attribute type.



3
4
5
# File 'lib/structured/parser_stack.rb', line 3

def type
  @type
end

Class Method Details

.root(type) ⇒ Object



36
37
38
# File 'lib/structured/parser_stack.rb', line 36

def self.root(type)
  new(type: type, element: nil, parent: nil)
end

Instance Method Details

#pathObject Also known as: to_s



15
16
17
18
19
20
21
22
23
24
# File 'lib/structured/parser_stack.rb', line 15

def path
  if root?
    type.type_name
  elsif element.nil?
    # abtract elements like Step use no element, they just forward parsing to a concrete type.
    parent.path
  else
    parent.path + parent.type.format_stack_frame_element(element)
  end
end

#push(element, type) ⇒ Object



11
12
13
# File 'lib/structured/parser_stack.rb', line 11

def push(element, type)
  self.class.new(type: type, element: element, parent: self)
end

#rootObject



32
33
34
# File 'lib/structured/parser_stack.rb', line 32

def root
  root? ? self : parent.root
end

#root?Boolean

Returns:



28
29
30
# File 'lib/structured/parser_stack.rb', line 28

def root?
  parent.nil?
end