Class: Parser::Comment

Inherits:
Object
  • Object
show all
Includes:
CodeObject::Converter, MetaContainer
Defined in:
lib/parser/comment.rb

Overview

Comment contains all tokenlines and doclines, which are created by the parser. The tokenlines are stored as Tokenline. Because of this Comment and Tokenline act as Interface for CodeObject::Base.

The tokens will further be processed by Token::Container, which is mixed in to CodeObject::Base).

Examples:

creating an comment

c = Parser::Comment.new "the original string of the comment, with all tokens and doclines"
c.add_tokenline :param "[String] first_parameter this is the description for param1"
c.add_docline "Some documentation of the comment"

access of comment-data

c.tokenlines.first.token #=> :param
c.tokenlines.first.content #=> "[String] first_parameter this is the description for param1"
c.doclines #=> ["Some documentation of the comment"]

Instance Attribute Summary collapse

Attributes included from CodeObject::Converter

#code_object, #path

Attributes included from MetaContainer

#filepath, #line_start, #source

Instance Method Summary collapse

Methods included from CodeObject::Converter

#to_code_object

Methods included from MetaContainer

#add_meta_data, #clone_meta

Constructor Details

#initialize(comment_text = "") ⇒ Comment

Returns a new instance of Comment.



37
38
39
40
41
# File 'lib/parser/comment.rb', line 37

def initialize(comment_text = "")
  @original_comment = comment_text
  
  @tokenlines, @doclines, @children = [], [], []
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



35
36
37
# File 'lib/parser/comment.rb', line 35

def children
  @children
end

#doclinesObject (readonly)

Returns the value of attribute doclines.



35
36
37
# File 'lib/parser/comment.rb', line 35

def doclines
  @doclines
end

#tokenlinesObject (readonly)

Returns the value of attribute tokenlines.



35
36
37
# File 'lib/parser/comment.rb', line 35

def tokenlines
  @tokenlines
end

Instance Method Details

#add_children(comments) ⇒ Object

Parameters:



55
56
57
# File 'lib/parser/comment.rb', line 55

def add_children(comments)
  @children += comments
end

#add_docline(docline) ⇒ Object

Parameters:



50
51
52
# File 'lib/parser/comment.rb', line 50

def add_docline(docline)
  @doclines << docline
end

#add_tokenline(tokenname, content = "") ⇒ Object

Parameters:

  • tokenname (String, Symbol)
  • content (String) (defaults to: "")


45
46
47
# File 'lib/parser/comment.rb', line 45

def add_tokenline(tokenname, content = "")
  @tokenlines << Tokenline.new(tokenname.to_sym, content)
end

#has_tokens?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/parser/comment.rb', line 60

def has_tokens?
  not @tokenlines.empty?
end

#to_sObject



64
65
66
# File 'lib/parser/comment.rb', line 64

def to_s
  "#<Parser::Comment tokenlines=#{@tokenlines.length} doclines=#{@doclines.length}>"
end