Class: Decode::Comment::Tag
Overview
Represents a documentation tag parsed from a comment directive. Subclasses should define a PATTERN constant for matching their specific syntax.
Constant Summary collapse
- PATTERN =
/(?<never_matches_anything>\A\z)/
Instance Attribute Summary collapse
-
#directive ⇒ Object
readonly
Returns the value of attribute directive.
- #The directive that generated the tag.(directivethatgeneratedthetag.) ⇒ Object readonly
Attributes inherited from Node
#The children of this node., #children
Class Method Summary collapse
-
.bracketed_content(name) ⇒ Object
Build a pattern for bracketed content, supporting nested brackets.
-
.build(directive, match) ⇒ Object
Abstract method: Build a tag from directive and match data.
-
.match(text) ⇒ Object
Match text against the tag pattern.
-
.parse(directive, text, lines, tags, level = 0) ⇒ Object
Parse a tag from a directive and text.
Instance Method Summary collapse
-
#initialize(directive) ⇒ Tag
constructor
Initialize a new tag.
Methods inherited from Node
#add, #children?, #each, #filter, #text, #traverse
Constructor Details
#initialize(directive) ⇒ Tag
Initialize a new tag.
61 62 63 |
# File 'lib/decode/comment/tag.rb', line 61 def initialize(directive) @directive = directive end |
Instance Attribute Details
#directive ⇒ Object (readonly)
Returns the value of attribute directive.
66 67 68 |
# File 'lib/decode/comment/tag.rb', line 66 def directive @directive end |
#The directive that generated the tag.(directivethatgeneratedthetag.) ⇒ Object (readonly)
66 |
# File 'lib/decode/comment/tag.rb', line 66 attr :directive |
Class Method Details
.bracketed_content(name) ⇒ Object
Build a pattern for bracketed content, supporting nested brackets.
28 29 30 |
# File 'lib/decode/comment/tag.rb', line 28 def self.bracketed_content(name) "(?<#{name}>(?:[^\\[\\]]+|\\[\\g<#{name}>\\])*)" end |
.build(directive, match) ⇒ Object
Abstract method: Build a tag from directive and match data. Subclasses must implement this method.
21 22 23 |
# File 'lib/decode/comment/tag.rb', line 21 def self.build(directive, match) raise NotImplementedError, "Subclasses must implement build method" end |
.match(text) ⇒ Object
Match text against the tag pattern.
34 35 36 |
# File 'lib/decode/comment/tag.rb', line 34 def self.match(text) self::PATTERN.match(text) end |
.parse(directive, text, lines, tags, level = 0) ⇒ Object
Parse a tag from a directive and text.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/decode/comment/tag.rb', line 44 def self.parse(directive, text, lines, , level = 0) if match = self.match(text) node = self.build(directive, match) .parse(lines, level + 1) do |child| node.add(child) end return node else # Consume all nested nodes: .ignore(lines, level + 1) end end |