Class: Musa::GenerativeGrammar::Implementation::Node Private
- Defined in:
- lib/musa-dsl/generative/generative-grammar.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Base node class for grammar elements.
Provides core operations for combining and transforming nodes. All node types (FinalNode, BlockNode, OrNode, etc.) inherit from this.
Direct Known Subclasses
BlockNode, ConditionNode, FinalNode, NextNode, OrNode, ProxyNode, RepeatNode
Instance Method Summary collapse
-
#[](index) ⇒ Node
private
Gets option at index as series node.
-
#_options(parent: nil) {|option| ... } ⇒ Array<Array<OptionElement>>
private
Internal method to generate option arrays.
-
#limit(attribute = nil, after_collect_operation = nil, comparison_method = nil, comparison_value = nil) {|option| ... } ⇒ ConditionNode
private
Limits generated options by condition.
-
#next(other) ⇒ NextNode
(also: #+)
private
Creates sequence of this node followed by another.
-
#options(attribute = nil, after_collect_operation = nil, comparison_method = nil, comparison_value = nil, raw: nil, content: nil) {|option| ... } ⇒ Array
private
Generates all options from this grammar node.
-
#or(other) ⇒ OrNode
(also: #|)
private
Creates alternation between this node and another.
-
#repeat(exactly = nil, min: nil, max: nil) ⇒ Node
private
Repeats this node with optional min/max bounds.
-
#size ⇒ Integer
(also: #length)
private
Counts number of options generated by this node.
-
#to_serie(flatten: true) {|option| ... } ⇒ Musa::Series::Serie
(also: #s)
private
Converts options to series.
Instance Method Details
#[](index) ⇒ Node
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Gets option at index as series node.
370 371 372 |
# File 'lib/musa-dsl/generative/generative-grammar.rb', line 370 def [](index) [index].to_serie.to_node end |
#_options(parent: nil) {|option| ... } ⇒ Array<Array<OptionElement>>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Internal method to generate option arrays.
403 404 405 |
# File 'lib/musa-dsl/generative/generative-grammar.rb', line 403 def (parent: nil, &condition) raise NotImplementedError end |
#limit(attribute = nil, after_collect_operation = nil, comparison_method = nil, comparison_value = nil) {|option| ... } ⇒ ConditionNode
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Limits generated options by condition.
Filters options to only those satisfying the given condition. Can use simplified arguments or custom block.
270 271 272 273 274 275 276 |
# File 'lib/musa-dsl/generative/generative-grammar.rb', line 270 def limit(attribute = nil, after_collect_operation = nil, comparison_method = nil, comparison_value = nil, &block) raise ArgumentError, 'Cannot use simplified arguments and yield block at the same time' if (attribute || after_collect_operation || comparison_method || comparison_value) && @block block ||= generate_simple_condition_block(attribute, after_collect_operation, comparison_method, comparison_value) ConditionNode.new(self, &block) end |
#next(other) ⇒ NextNode Also known as: +
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates sequence of this node followed by another.
Generates options with this node's content followed by the other's.
290 291 292 |
# File 'lib/musa-dsl/generative/generative-grammar.rb', line 290 def next(other) NextNode.new(self, other) end |
#options(attribute = nil, after_collect_operation = nil, comparison_method = nil, comparison_value = nil, raw: nil, content: nil) {|option| ... } ⇒ Array
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Generates all options from this grammar node.
Produces all valid combinations matching the grammar definition. Can filter with condition and control output format.
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 |
# File 'lib/musa-dsl/generative/generative-grammar.rb', line 333 def (attribute = nil, after_collect_operation = nil, comparison_method = nil, comparison_value = nil, raw: nil, content: nil, &condition) raise ArgumentError, 'Cannot use simplified arguments and yield block at the same time' if (attribute || after_collect_operation || comparison_method || comparison_value) && @condition raise ArgumentError, 'Cannot use raw: true and content: option at the same time' if raw && content raw ||= false content ||= :itself condition ||= generate_simple_condition_block(attribute, after_collect_operation, comparison_method, comparison_value) if raw (&condition) else (&condition).collect { |o| o.collect(&:content).send(content) } end end |
#or(other) ⇒ OrNode Also known as: |
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates alternation between this node and another.
Generates options where either this node or the other is chosen.
195 196 197 |
# File 'lib/musa-dsl/generative/generative-grammar.rb', line 195 def or(other) OrNode.new(self, other) end |
#repeat(exactly = nil, min: nil, max: nil) ⇒ Node
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Repeats this node with optional min/max bounds.
Generates options with different repetition counts of this node. Without bounds, generates infinite options (use with limit).
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/musa-dsl/generative/generative-grammar.rb', line 224 def repeat(exactly = nil, min: nil, max: nil) raise ArgumentError, 'Only exactly value or min/max values are allowed' if exactly && (min || max) min = max = exactly if exactly if min && min > 0 pre = self (min - 1).times do pre += self end end if pre && max == min pre elsif pre && max > min pre + RepeatNode.new(self, max - min) else RepeatNode.new(self, max) end end |
#size ⇒ Integer Also known as: length
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Counts number of options generated by this node.
359 360 361 |
# File 'lib/musa-dsl/generative/generative-grammar.rb', line 359 def size .size end |
#to_serie(flatten: true) {|option| ... } ⇒ Musa::Series::Serie Also known as: s
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts options to series.
Generates options and converts them to a Series::Serie.
384 385 386 387 388 389 |
# File 'lib/musa-dsl/generative/generative-grammar.rb', line 384 def to_serie(flatten: true, &condition) serie = (&condition).collect { |o| o.collect(&:content) }.to_serie(of_series: true).merge serie = serie.flatten if flatten serie.prototype end |