Class: Decode::Comment::Tag

Inherits:
Node
  • Object
show all
Defined in:
lib/decode/comment/tag.rb

Overview

Represents a documentation tag parsed from a comment directive. Subclasses should define a PATTERN constant for matching their specific syntax.

Direct Known Subclasses

Attribute, Constant, Example, Parameter, Pragma, RBS, Yields

Constant Summary collapse

PATTERN =
/(?<never_matches_anything>\A\z)/

Instance Attribute Summary collapse

Attributes inherited from Node

#The children of this node., #children

Class Method Summary collapse

Instance Method Summary collapse

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

#directiveObject (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.

Raises:

  • (NotImplementedError)


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, 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