Class: Strling::Core::Alt

Inherits:
Node
  • Object
show all
Defined in:
lib/strling/core/nodes.rb

Overview

Represents an alternation (OR) operation in the AST.

Matches any one of the provided branches. Equivalent to the | operator in traditional regex syntax.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(branches) ⇒ Alt

Returns a new instance of Alt.

Parameters:

  • branches (Array<Node>)

    The alternative branches



111
112
113
# File 'lib/strling/core/nodes.rb', line 111

def initialize(branches)
  @branches = branches
end

Instance Attribute Details

#branchesArray<Node>

Returns The alternative branches.

Returns:

  • (Array<Node>)

    The alternative branches



108
109
110
# File 'lib/strling/core/nodes.rb', line 108

def branches
  @branches
end

Instance Method Details

#to_dictObject



115
116
117
# File 'lib/strling/core/nodes.rb', line 115

def to_dict
  { 'kind' => 'Alt', 'branches' => branches.map(&:to_dict) }
end