Class: Twig::Token

Inherits:
Object
  • Object
show all
Defined in:
lib/twig/token.rb

Constant Summary collapse

EOF_TYPE =
:eof
TEXT_TYPE =
:text
BLOCK_START_TYPE =
:block_start
VAR_START_TYPE =
:var_start
BLOCK_END_TYPE =
:block_end
VAR_END_TYPE =
:var_end
NAME_TYPE =
:name
SYMBOL_TYPE =
:symbol
NUMBER_TYPE =
:number
STRING_TYPE =
:string
OPERATOR_TYPE =
:operator
PUNCTUATION_TYPE =
:punctuation
INTERPOLATION_START_TYPE =
:interpolation_start
INTERPOLATION_END_TYPE =
:interpolation_end
ARROW_TYPE =
:arrow
SPREAD_TYPE =
:spread

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, value, lineno) ⇒ Token

Returns a new instance of Token.



24
25
26
27
28
# File 'lib/twig/token.rb', line 24

def initialize(type, value, lineno)
  @type = type
  @value = value
  @lineno = lineno
end

Instance Attribute Details

#linenoObject (readonly)

Returns the value of attribute lineno.



22
23
24
# File 'lib/twig/token.rb', line 22

def lineno
  @lineno
end

#typeObject (readonly)

Returns the value of attribute type.



22
23
24
# File 'lib/twig/token.rb', line 22

def type
  @type
end

#valueObject (readonly)

Returns the value of attribute value.



22
23
24
# File 'lib/twig/token.rb', line 22

def value
  @value
end

Instance Method Details

#debugObject



44
45
46
# File 'lib/twig/token.rb', line 44

def debug
  [type, value]
end

#test(type, values = nil) ⇒ Object

Parameters:

  • type (Symbol | String)


31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/twig/token.rb', line 31

def test(type, values = nil)
  if values.nil? && !type.is_a?(Symbol)
    values = type
    type = NAME_TYPE
  end

  @type == type && (
    values.nil? ||
      (values.is_a?(Array) && values.include?(@value)) ||
      (@value == values)
  )
end