Module: Musa::GenerativeGrammar
- Extended by:
- GenerativeGrammar
- Included in:
- GenerativeGrammar
- Defined in:
- lib/musa-dsl/generative/generative-grammar.rb
Overview
Generative grammar system for creating formal grammars with combinatorial generation.
GenerativeGrammar provides a DSL for defining formal grammars that can generate all possible combinations of terminal and non-terminal symbols according to production rules. Similar to context-free grammars in formal language theory.
Core Concepts
- Nodes (N): Terminal or block nodes with content and attributes
- Proxy Nodes (PN): Placeholder nodes for recursive grammar definitions
- Operators: Combine nodes to form production rules
|(or): Alternative/choice between nodes+(next): Concatenation/sequence of nodes
- Modifiers:
repeat(min:, max:): Repeat node multiple timeslimit(&block): Filter options by condition
- Options: Generate all valid combinations matching the grammar
Grammar Definition Process
- Define terminal nodes with N(content, **attributes)
- Combine nodes using operators (|, +)
- Add repetition and limits as needed
- Use PN() for recursive grammars
- Call .options to generate all valid combinations
Musical Applications
- Generate melodic patterns with rhythmic constraints
- Create harmonic progressions with voice leading rules
- Produce variations of musical motifs
- Build algorithmic composition structures
Defined Under Namespace
Classes: OptionElement
Class Method Summary collapse
-
.N(content = nil, **attributes) {|parent, attributes| ... } ⇒ Implementation::FinalNode, Implementation::BlockNode
Creates a terminal or block node.
-
.PN ⇒ Implementation::ProxyNode
Creates a proxy node for recursive grammars.
Instance Method Summary collapse
-
#N(content = nil, **attributes) {|parent, attributes| ... } ⇒ Implementation::FinalNode, Implementation::BlockNode
Creates a terminal or block node.
-
#PN ⇒ Implementation::ProxyNode
Creates a proxy node for recursive grammars.
Class Method Details
.N(content = nil, **attributes) {|parent, attributes| ... } ⇒ Implementation::FinalNode, Implementation::BlockNode
Creates a terminal or block node.
Nodes are the basic building blocks of grammars. They can be:
- Terminal nodes: Fixed content with attributes
- Block nodes: Dynamic content generated by block
124 125 126 127 128 129 130 |
# File 'lib/musa-dsl/generative/generative-grammar.rb', line 124 def N(content = nil, **attributes, &block) if block_given? && content.nil? Implementation::BlockNode.new(attributes, &block) else Implementation::FinalNode.new(content, attributes) end end |
.PN ⇒ Implementation::ProxyNode
Creates a proxy node for recursive grammars.
Proxy nodes act as placeholders that can be assigned later, enabling recursive and self-referential grammar definitions.
151 152 153 |
# File 'lib/musa-dsl/generative/generative-grammar.rb', line 151 def PN Implementation::ProxyNode.new end |
Instance Method Details
#N(content = nil, **attributes) {|parent, attributes| ... } ⇒ Implementation::FinalNode, Implementation::BlockNode
Creates a terminal or block node.
Nodes are the basic building blocks of grammars. They can be:
- Terminal nodes: Fixed content with attributes
- Block nodes: Dynamic content generated by block
124 125 126 127 128 129 130 |
# File 'lib/musa-dsl/generative/generative-grammar.rb', line 124 def N(content = nil, **attributes, &block) if block_given? && content.nil? Implementation::BlockNode.new(attributes, &block) else Implementation::FinalNode.new(content, attributes) end end |
#PN ⇒ Implementation::ProxyNode
Creates a proxy node for recursive grammars.
Proxy nodes act as placeholders that can be assigned later, enabling recursive and self-referential grammar definitions.
151 152 153 |
# File 'lib/musa-dsl/generative/generative-grammar.rb', line 151 def PN Implementation::ProxyNode.new end |