summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKornelius Kalnbach <murphy@rubychan.de>2016-02-13 00:32:56 +0100
committerKornelius Kalnbach <murphy@rubychan.de>2016-02-13 00:32:56 +0100
commitaa93af4cbc465d90db8f1f27477214ec119223a3 (patch)
tree0c2a3f40ff12ed6c1bc51d27526b59bbd874837e
parent40f1fa7bc46a5fd8addba230afb21f072a7e1215 (diff)
downloadcoderay-aa93af4cbc465d90db8f1f27477214ec119223a3.tar.gz
quick increment/decrement, yay!
-rw-r--r--lib/coderay/rule_based_scanner.rb19
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/coderay/rule_based_scanner.rb b/lib/coderay/rule_based_scanner.rb
index 2154fb7..ba49ccf 100644
--- a/lib/coderay/rule_based_scanner.rb
+++ b/lib/coderay/rule_based_scanner.rb
@@ -13,6 +13,7 @@ module CodeRay
CheckIf = Class.new Check
CheckUnless = Class.new Check
ValueSetter = Struct.new :targets, :value
+ Increment = Struct.new :targets, :operation, :value
Continue = Class.new
class << self
@@ -172,6 +173,16 @@ module CodeRay
@code << " #{action.targets.join(' = ')} = #{action.value.inspect}\n"
end
+ when Increment
+ case action.value
+ when Proc
+ @code << " #{action.targets.join(' = ')} #{action.operation}= #{make_callback(action.value)}\n"
+ when Symbol
+ @code << " #{action.targets.join(' = ')} #{action.operation}= #{action.value}\n"
+ else
+ @code << " #{action.targets.join(' = ')} #{action.operation}= #{action.value.inspect}\n"
+ end
+
when Proc
@code << " #{make_callback(action)}\n"
@@ -240,6 +251,14 @@ module CodeRay
ValueSetter.new Array(flags), nil
end
+ def increment *counters
+ Increment.new Array(counters), :+, 1
+ end
+
+ def decrement *counters
+ Increment.new Array(counters), :-, 1
+ end
+
def continue
Continue.new
end