Class: Puppet::Pops::Parser::Lexer::Token
- Includes:
- Util::MethodHelper
- Defined in:
- lib/puppet/pops/parser/lexer.rb
Constant Summary collapse
- ALWAYS_ACCEPTABLE =
Proc.new { |context| true }
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#acceptable?(context = {}) ⇒ Boolean
If the token is acceptable in the given context or not.
-
#acceptable_when(block) ⇒ Object
Defines when the token is able to match.
-
#initialize(string_or_regex, name, options = {}) ⇒ Token
constructor
A new instance of Token.
-
#to_s ⇒ String
Human readable token reference; the String if literal, else the token name.
Methods included from Util::MethodHelper
#requiredopts, #set_options, #symbolize_options
Constructor Details
#initialize(string) ⇒ Token #initialize(regex) ⇒ Token
Returns a new instance of Token.
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/puppet/pops/parser/lexer.rb', line 43 def initialize(string_or_regex, name, = {}) 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 () @acceptable_when = ALWAYS_ACCEPTABLE end |
Instance Attribute Details
#skip ⇒ Object Also known as: skip?
31 32 33 |
# File 'lib/puppet/pops/parser/lexer.rb', line 31 def skip @skip end |
#skip_text ⇒ Object
31 32 33 |
# File 'lib/puppet/pops/parser/lexer.rb', line 31 def skip_text @skip_text end |
Instance Method Details
#acceptable?(context = {}) ⇒ Boolean
Returns if the token is acceptable in the given context or not.
63 64 65 |
# File 'lib/puppet/pops/parser/lexer.rb', line 63 def acceptable?(context={}) @acceptable_when.call(context) end |
#acceptable_when(block) ⇒ Object
Defines when the token is able to match. This provides context that cannot be expressed otherwise, such as feature flags.
72 73 74 |
# File 'lib/puppet/pops/parser/lexer.rb', line 72 def acceptable_when(block) @acceptable_when = block end |
#to_s ⇒ String
Returns human readable token reference; the String if literal, else the token name.
56 57 58 |
# File 'lib/puppet/pops/parser/lexer.rb', line 56 def to_s string or @name.to_s end |