Class: Markbridge::AST::Node Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/markbridge/ast/node.rb

Overview

This class is abstract.

Subclass and add specific behavior

Base class for all AST nodes. This is a marker class that serves as the common ancestor for all AST nodes.

The AST hierarchy consists of:

  • Element - nodes that can contain children
  • Text - leaf nodes containing text content

All node types inherit from this base class to enable type checking and polymorphic operations on the AST tree.

Constant Summary collapse

DESCENDANTS =

Registry of every class that inherits from Markbridge::AST::Node, direct or not. This is boot-time state: the built-in classes land here while the gem's requires run, and a consumer subclass is appended when its class body runs. Anything built from this list at freeze time (see TagLibrary#freeze and RuleSet#freeze) covers only the classes defined up to that point; later classes go through the lazy ancestry lookups instead.

[]

Class Method Summary collapse

Class Method Details

.ast_chainArray<Class>

The class chain from this class up to Markbridge::AST::Node, most specific class first. Cached on the class: the chain is pure class structure and can never change once the class is defined, so one array per class serves the whole process. The normalizer and the tag library use it for ancestry matching.

Returns:

  • (Array<Class>)

    frozen, e.g. [Bold, Element, Node]



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/markbridge/ast/node.rb', line 46

def self.ast_chain
  @ast_chain ||=
    begin
      chain = [self]
      sup = superclass
      while sup <= Node
        chain << sup
        sup = sup.superclass
      end
      chain.freeze
    end
end

.descendantsArray<Class>

Returns every known descendant class, in definition order (see DESCENDANTS — boot-time state).

Returns:

  • (Array<Class>)

    every known descendant class, in definition order (see DESCENDANTS — boot-time state)



35
36
37
# File 'lib/markbridge/ast/node.rb', line 35

def self.descendants
  DESCENDANTS
end

.inherited(subclass) ⇒ Object

No super on purpose: Class#inherited is a no-op, so calling it adds nothing observable (verified by mutation testing).

Parameters:

  • subclass (Class)


29
30
31
# File 'lib/markbridge/ast/node.rb', line 29

def self.inherited(subclass)
  DESCENDANTS << subclass
end