Class: Puppet::Parser::Lexer::Token

Inherits:
Object
  • Object
show all
Includes:
Util::MethodHelper
Defined in:
lib/puppet/parser/lexer.rb

Constant Summary collapse

ALWAYS_ACCEPTABLE =
Proc.new { |context| true }

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util::MethodHelper

#requiredopts, #set_options, #symbolize_options

Constructor Details

#initialize(string_or_regex, name, options = {}) ⇒ Token

Returns a new instance of Token.



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/puppet/parser/lexer.rb', line 45

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

Instance Attribute Details

#accumulateObject Also known as: accumulate?



41
42
43
# File 'lib/puppet/parser/lexer.rb', line 41

def accumulate
  @accumulate
end

#incr_lineObject



41
42
43
# File 'lib/puppet/parser/lexer.rb', line 41

def incr_line
  @incr_line
end

#nameObject



41
42
43
# File 'lib/puppet/parser/lexer.rb', line 41

def name
  @name
end

#regexObject



41
42
43
# File 'lib/puppet/parser/lexer.rb', line 41

def regex
  @regex
end

#skipObject Also known as: skip?



41
42
43
# File 'lib/puppet/parser/lexer.rb', line 41

def skip
  @skip
end

#skip_textObject



41
42
43
# File 'lib/puppet/parser/lexer.rb', line 41

def skip_text
  @skip_text
end

#stringObject



41
42
43
# File 'lib/puppet/parser/lexer.rb', line 41

def string
  @string
end

Instance Method Details

#acceptable?(context = {}) ⇒ Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/puppet/parser/lexer.rb', line 61

def acceptable?(context={})
  @acceptable_when.call(context)
end

#acceptable_when(block) ⇒ Object

Define when the token is able to match. This provides context that cannot be expressed otherwise, such as feature flags.

Parameters:

  • block (Proc)

    a proc that given a context returns a boolean



69
70
71
# File 'lib/puppet/parser/lexer.rb', line 69

def acceptable_when(block)
  @acceptable_when = block
end

#to_sObject



57
58
59
# File 'lib/puppet/parser/lexer.rb', line 57

def to_s
  string or @name.to_s
end