Class: Liquid::Tokenizer

Inherits:
Object
  • Object
show all
Defined in:
lib/liquid/tokenizer.rb

Constant Summary collapse

TAG_END =
/%\}/
TAG_OR_VARIABLE_START =
/\{[\{\%]/
NEWLINE =
/\n/
OPEN_CURLEY =
"{".ord
CLOSE_CURLEY =
"}".ord
PERCENTAGE =
"%".ord

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source:, string_scanner:, line_numbers: false, line_number: nil, for_liquid_tag: false) ⇒ Tokenizer

Returns a new instance of Tokenizer.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/liquid/tokenizer.rb', line 17

def initialize(
  source:,
  string_scanner:,
  line_numbers: false,
  line_number: nil,
  for_liquid_tag: false
)
  @line_number = line_number || (line_numbers ? 1 : nil)
  @for_liquid_tag = for_liquid_tag
  @source = source.to_s.to_str
  @offset = 0
  @tokens = []

  if @source
    @ss = string_scanner
    @ss.string = @source
    tokenize
  end
end

Instance Attribute Details

#for_liquid_tagObject (readonly)

Returns the value of attribute for_liquid_tag.



7
8
9
# File 'lib/liquid/tokenizer.rb', line 7

def for_liquid_tag
  @for_liquid_tag
end

#line_numberObject (readonly)

Returns the value of attribute line_number.



7
8
9
# File 'lib/liquid/tokenizer.rb', line 7

def line_number
  @line_number
end

Instance Method Details

#shiftObject



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/liquid/tokenizer.rb', line 37

def shift
  token = @tokens[@offset]

  return unless token

  @offset += 1

  if @line_number
    @line_number += @for_liquid_tag ? 1 : token.count("\n")
  end

  token
end