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 of 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.



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

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

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



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

def children
  @children
end

#doclinesObject (readonly)

Returns the value of attribute doclines.



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

def doclines
  @doclines
end

#tokenlinesObject (readonly)

Returns the value of attribute tokenlines.



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

def tokenlines
  @tokenlines
end

Instance Method Details

#add_children(comments) ⇒ Object

Parameters:



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

def add_children(comments)
  @children += comments
end

#add_docline(docline) ⇒ Object

Parameters:



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

def add_docline(docline)
  @doclines << docline
end

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

Parameters:

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


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

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