Class: Lisp::Format::Directives::BeginIteration
- Defined in:
- lib/carat/lisp-format.rb
Overview
Represents the ~{ (Begin iteration) directive. A given set of directives is used iteratively over a set of arguments (depends on the modifiers specified) a given number of times, or until it runs out of arguments.
Instance Attribute Summary
Attributes inherited from Directive
Instance Method Summary collapse
-
#connect(directives) ⇒ Object
Connect a set of directives to this iteration directive.
-
#execute(state) ⇒ Object
Iteratively run the contained directives using sets of arguments depending upon what modifiers where given.
-
#initialize(params, modifiers, top, pos) ⇒ BeginIteration
constructor
Create and set up some private variables.
Methods inherited from Directive
Constructor Details
#initialize(params, modifiers, top, pos) ⇒ BeginIteration
Create and set up some private variables
1617 1618 1619 1620 |
# File 'lib/carat/lisp-format.rb', line 1617 def initialize(params, modifiers, top, pos) super params, modifiers, top, pos @directives = [] end |
Instance Method Details
#connect(directives) ⇒ Object
Connect a set of directives to this iteration directive.
1657 1658 1659 1660 |
# File 'lib/carat/lisp-format.rb', line 1657 def connect(directives) directives.pop @directives = directives end |
#execute(state) ⇒ Object
Iteratively run the contained directives using sets of arguments depending upon what modifiers where given. The full form is
~n:@{...~}
with the following interpretations
- n
-
maximum number of times the iteration should be performed,
- no modifiers
-
the iteration reads an argument, which must be an Array, and uses it as the arguments to the contained directives,
- :
-
the iteration reads an argument, which must be an Array containing sub-arrays, and uses the sub-arrays as the arguments to the contained directives, moving to the next one on each iteration,
- @
-
the iteration uses the rest of the arguments as arguments to the contained directives,
- :@
-
the iteration uses the rest of the arguments, which must be Arrays, using each Array as the set of arguments to the contained directives.
1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 |
# File 'lib/carat/lisp-format.rb', line 1642 def execute(state) n = param(0, state, nil) return if not n.nil? and n == 0 if colon_mod? and at_mod? execute_sets(n, state, false) elsif at_mod? execute_args(n, nil, state, false) elsif colon_mod? execute_sets(n, state, true) else execute_args(n, state.next_arg, state, true) end end |