diff options
author | Kornelius Kalnbach <murphy@rubychan.de> | 2015-04-03 13:02:33 +0200 |
---|---|---|
committer | Kornelius Kalnbach <murphy@rubychan.de> | 2015-04-03 13:02:33 +0200 |
commit | 5e954e2522a0ec46460086c8bce6975183b366b7 (patch) | |
tree | 9a95560edd97c123fad64cc45bb66e876a45ac83 /lib/coderay/scanners/java_script5.rb | |
parent | 6eaa589d054ac515e041c0efeff0cdc6f36bfeea (diff) | |
download | coderay-5e954e2522a0ec46460086c8bce6975183b366b7.tar.gz |
add check_unless
Diffstat (limited to 'lib/coderay/scanners/java_script5.rb')
-rw-r--r-- | lib/coderay/scanners/java_script5.rb | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/lib/coderay/scanners/java_script5.rb b/lib/coderay/scanners/java_script5.rb index bc5ce9a..1b9ae5c 100644 --- a/lib/coderay/scanners/java_script5.rb +++ b/lib/coderay/scanners/java_script5.rb @@ -8,7 +8,9 @@ module Scanners Kind = Struct.new :token_kind Push = Struct.new :state Pop = Class.new - CheckIf = Struct.new :condition + Check = Struct.new :condition + CheckIf = Class.new Check + CheckUnless = Class.new Check ValueSetter = Struct.new :targets, :value class << self @@ -40,7 +42,7 @@ module Scanners end def on *pattern_and_actions - if index = pattern_and_actions.find_index { |item| !item.is_a?(CheckIf) } + if index = pattern_and_actions.find_index { |item| !item.is_a?(Check) } preconditions = pattern_and_actions[0..index - 1] if index > 0 pattern = pattern_and_actions[index] or raise 'I need a pattern!' actions = pattern_and_actions[index + 1..-1] or raise 'I need actions!' @@ -59,6 +61,15 @@ module Scanners else raise "I don't know how to evaluate this check_if precondition: %p" % [precondition.condition] end + when CheckUnless + case precondition.condition + when Proc + precondition_expression << "!#{make_callback(precondition.condition)} && " + when Symbol + precondition_expression << "!#{precondition.condition} && " + else + raise "I don't know how to evaluate this check_unless precondition: %p" % [precondition.condition] + end else raise "I don't know how to evaluate this precondition: %p" % [precondition] end @@ -163,6 +174,10 @@ module Scanners CheckIf.new value || callback end + def check_unless value = nil, &callback + CheckUnless.new value || callback + end + def flag_on *flags ValueSetter.new Array(flags), true end |