class Tag
Represents a documentation tag parsed from a comment directive. Subclasses should define a PATTERN constant for matching their specific syntax.
Definitions
PATTERN = /(?<never_matches_anything>\A\z)/
Signature
- constant
Abstract pattern constant - subclasses must override this.
def self.build(directive, match)
Abstract method: Build a tag from directive and match data. Subclasses must implement this method.
Signature
-
parameter
directive
String
The directive that generated the tag.
-
parameter
match
MatchData
The regex match data.
-
returns
Tag
A new tag instance.
Implementation
def self.build(directive, match)
raise NotImplementedError, "Subclasses must implement build method"
end
def self.bracketed_content(name)
Build a pattern for bracketed content, supporting nested brackets.
Signature
-
parameter
name
Symbol
The name of the group.
-
returns
String
The pattern.
Implementation
def self.bracketed_content(name)
"(?<#{name}>(?:[^\\[\\]]+|\\[\\g<#{name}>\\])*)"
end
def self.match(text)
Match text against the tag pattern.
Signature
-
parameter
text
String
The text to match.
Implementation
def self.match(text)
self::PATTERN.match(text)
end
def self.parse(directive, text, lines, tags, level = 0)
Parse a tag from a directive and text.
Signature
-
parameter
directive
String
The directive name.
-
parameter
text
String
The directive text.
-
parameter
lines
Array(String)
The remaining lines.
-
parameter
tags
Tags
The tags parser.
-
parameter
level
Integer
The indentation level.
Implementation
def self.parse(directive, text, lines, tags, level = 0)
if match = self.match(text)
node = self.build(directive, match)
tags.parse(lines, level + 1) do |child|
node.add(child)
end
return node
else
# Consume all nested nodes:
tags.ignore(lines, level + 1)
end
end
def initialize(directive)
Initialize a new tag.
Signature
-
parameter
directive
String
The directive that generated the tag.
Implementation
def initialize(directive)
@directive = directive
end
attr :directive
Signature
-
attribute
String
The directive that generated the tag.