lib/rouge/lexer.rb in rouge-1.1.0 vs lib/rouge/lexer.rb in rouge-1.2.0
- old
+ new
@@ -320,10 +320,12 @@
# on the lexer in question. In regex lexers, this will log the
# state stack at the beginning of each step, along with each regex
# tried and each stream consumed. Try it, it's pretty useful.
def initialize(opts={})
options(opts)
+
+ @debug = option(:debug)
end
# get and/or specify the options for this lexer.
def options(o={})
(@options ||= {}).merge!(o)
@@ -338,28 +340,24 @@
else
options({ k => v })
end
end
+ # @deprecated
+ # Instead of `debug { "foo" }`, simply `puts "foo" if @debug`.
+ #
# Leave a debug message if the `:debug` option is set. The message
# is given as a block because some debug messages contain calculated
# information that is unnecessary for lexing in the real world.
#
+ # Calls to this method should be guarded with "if @debug" for best
+ # performance when debugging is turned off.
+ #
# @example
- # debug { "hello, world!" }
- def debug(&b)
- # This method is a hotspot, unfortunately.
- #
- # For performance reasons, the "debug" option of a lexer cannot
- # be changed once it has begun lexing. This method will redefine
- # itself on the first call to a noop if "debug" is not set.
- if option(:debug)
- def self.debug; puts yield; end
- else
- def self.debug; end
- end
-
- debug(&b)
+ # debug { "hello, world!" } if @debug
+ def debug
+ warn "Lexer#debug is deprecated. Simply puts if @debug instead."
+ puts yield if @debug
end
# @abstract
#
# Called after each lex is finished. The default implementation