Class: RBlade::CompilesStatements::CompilesOnce
- Inherits:
-
Object
- Object
- RBlade::CompilesStatements::CompilesOnce
- Defined in:
- lib/rblade/compiler/statements/compiles_once.rb
Instance Method Summary collapse
- #compileEndPrependOnce(args) ⇒ Object
- #compileEndPushOnce(args) ⇒ Object
- #compileOnce(args) ⇒ Object
- #compilePrependOnce(args) ⇒ Object
- #compilePushOnce(args) ⇒ Object
-
#initialize ⇒ CompilesOnce
constructor
A new instance of CompilesOnce.
Constructor Details
#initialize ⇒ CompilesOnce
Returns a new instance of CompilesOnce.
4 5 6 |
# File 'lib/rblade/compiler/statements/compiles_once.rb', line 4 def initialize @once_counter = 0 end |
Instance Method Details
#compileEndPrependOnce(args) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/rblade/compiler/statements/compiles_once.rb', line 48 def compileEndPrependOnce args unless args.nil? raise StandardError.new "End prepend once statement: wrong number of arguments (given #{args.count}, expecting 0)" end "RBlade::StackManager.prepend(_p1_#{@once_counter}, _out);_out=_p1_#{@once_counter}_b;end;" end |
#compileEndPushOnce(args) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/rblade/compiler/statements/compiles_once.rb', line 29 def compileEndPushOnce args unless args.nil? raise StandardError.new "End push once statement: wrong number of arguments (given #{args.count}, expecting 0)" end "RBlade::StackManager.push(_p1_#{@once_counter}, _out);_out=_p1_#{@once_counter}_b;end;" end |
#compileOnce(args) ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/rblade/compiler/statements/compiles_once.rb', line 8 def compileOnce args if args&.count&.> 1 raise StandardError.new "Once statement: wrong number of arguments (given #{args.count}, expecting 0 or 1)" end once_id = args.nil? ? ":_#{@once_counter += 1}" : args[0] "unless $_once_tokens.include? #{once_id};$_once_tokens<<#{once_id};" end |
#compilePrependOnce(args) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rblade/compiler/statements/compiles_once.rb', line 37 def compilePrependOnce args if args&.count != 1 && args&.count != 2 raise StandardError.new "Prepend once statement: wrong number of arguments (given #{args&.count || 0}, expecting 1 or 2)" end @once_counter += 1 once_id = args[1].nil? ? ":_#{@once_counter}" : args[1] "unless $_once_tokens.include? #{once_id};$_once_tokens<<#{once_id};" \ << "_p1_#{@once_counter}=#{args[0]};_p1_#{@once_counter}_b=_out;_out='';" end |
#compilePushOnce(args) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rblade/compiler/statements/compiles_once.rb', line 18 def compilePushOnce args if args&.count != 1 && args&.count != 2 raise StandardError.new "Push once statement: wrong number of arguments (given #{args&.count || 0}, expecting 1 or 2)" end @once_counter += 1 once_id = args[1].nil? ? ":_#{@once_counter}" : args[1] "unless $_once_tokens.include? #{once_id};$_once_tokens<<#{once_id};" \ << "_p1_#{@once_counter}=#{args[0]};_p1_#{@once_counter}_b=_out;_out='';" end |