Class: Puppet::Parser::Lexer::Token
Constant Summary
collapse
- ALWAYS_ACCEPTABLE =
Proc.new { |context| true }
Instance Attribute Summary collapse
Instance Method Summary
collapse
#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
#accumulate ⇒ Object
Also known as:
accumulate?
41
42
43
|
# File 'lib/puppet/parser/lexer.rb', line 41
def accumulate
@accumulate
end
|
#incr_line ⇒ Object
41
42
43
|
# File 'lib/puppet/parser/lexer.rb', line 41
def incr_line
@incr_line
end
|
41
42
43
|
# File 'lib/puppet/parser/lexer.rb', line 41
def name
@name
end
|
41
42
43
|
# File 'lib/puppet/parser/lexer.rb', line 41
def regex
@regex
end
|
#skip ⇒ Object
Also known as:
skip?
41
42
43
|
# File 'lib/puppet/parser/lexer.rb', line 41
def skip
@skip
end
|
#skip_text ⇒ Object
41
42
43
|
# File 'lib/puppet/parser/lexer.rb', line 41
def skip_text
@skip_text
end
|
41
42
43
|
# File 'lib/puppet/parser/lexer.rb', line 41
def string
@string
end
|
Instance Method Details
#acceptable?(context = {}) ⇒ 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.
69
70
71
|
# File 'lib/puppet/parser/lexer.rb', line 69
def acceptable_when(block)
@acceptable_when = block
end
|
57
58
59
|
# File 'lib/puppet/parser/lexer.rb', line 57
def to_s
string or @name.to_s
end
|