# File lib/puppet/parser/lexer.rb, line 36 def initialize(string_or_regex, name, options = {}) if string_or_regex.is_a?(String) @name, @string = name, string_or_regex @regex = Regexp.new(Regexp.escape(string_or_regex)) else @name, @regex = name, string_or_regex end set_options(options) @acceptable_when = ALWAYS_ACCEPTABLE end
# File lib/puppet/parser/lexer.rb, line 52 def acceptable?(context={}) @acceptable_when.call(context) end
Define when the token is able to match. This provides context that cannot be expressed otherwise, such as feature flags.
@param block [Proc] a proc that given a context returns a boolean
# File lib/puppet/parser/lexer.rb, line 60 def acceptable_when(block) @acceptable_when = block end
# File lib/puppet/parser/lexer.rb, line 48 def to_s string or @name.to_s end