Class: Bade::AST::Document

Inherits:
Object show all
Defined in:
lib/bade/ast/document.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root: Node.new(:root, nil), file_path: nil) ⇒ Document

Returns a new instance of Document.

Parameters:

  • root (Bade::Node) (defaults to: Node.new(:root, nil))


27
28
29
30
31
32
# File 'lib/bade/ast/document.rb', line 27

def initialize(root: Node.new(:root, nil), file_path: nil)
  @root = root

  @file_path = file_path.dup.freeze unless file_path.nil?
  @sub_documents = []
end

Instance Attribute Details

#file_pathString? (readonly)

Path to this document, but only if it is defined from file

Returns:



19
20
21
# File 'lib/bade/ast/document.rb', line 19

def file_path
  @file_path
end

#rootBade::Node (readonly)

Root node of this document

Returns:

  • (Bade::Node)


13
14
15
# File 'lib/bade/ast/document.rb', line 13

def root
  @root
end

#sub_documentsArray<Bade::Document> (readonly)

Returns:

  • (Array<Bade::Document>)


23
24
25
# File 'lib/bade/ast/document.rb', line 23

def sub_documents
  @sub_documents
end

Instance Method Details

#==(other) ⇒ Bool

Parameters:

  • other (Bade::Document)

Returns:

  • (Bool)


46
47
48
49
50
# File 'lib/bade/ast/document.rb', line 46

def ==(other)
  return false unless other.is_a?(Document)

  root == other.root && sub_documents == other.sub_documents
end

#freezeObject



34
35
36
37
38
39
40
# File 'lib/bade/ast/document.rb', line 34

def freeze
  super

  root.freeze
  sub_documents.freeze
  sub_documents.each(&:freeze)
end