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
directiveString The directive that generated the tag.
-
parameter
matchMatchData 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
nameSymbol 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
textString 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
directiveString The directive name.
-
parameter
textString The directive text.
-
parameter
linesArray(String) The remaining lines.
-
parameter
tagsTags The tags parser.
-
parameter
levelInteger 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
directiveString The directive that generated the tag.
Implementation
def initialize(directive)
@directive = directive
end
attr :directive
Signature
-
attribute
String The directive that generated the tag.