Class: RedQuilt::Inline::Tokens

Inherits:
Object
  • Object
show all
Defined in:
lib/red_quilt/inline/tokens.rb

Overview

Parallel-array storage for the inline token stream.

InlineTokens is intended to be allocated once per document and reused across paragraphs by calling #clear between inline targets. Array#clear resets length to 0 while preserving internal capacity, so subsequent paragraphs avoid reallocating the underlying buffers.

Instance Method Summary collapse

Constructor Details

#initializeTokens

Returns a new instance of Tokens.



12
13
14
15
16
17
18
19
20
# File 'lib/red_quilt/inline/tokens.rb', line 12

def initialize
  @kind = []
  @start_byte = []
  @end_byte = []
  @int1 = []
  @int2 = []
  @int3 = []
  @str1 = []
end

Instance Method Details

#clearObject



34
35
36
37
38
39
40
41
42
43
# File 'lib/red_quilt/inline/tokens.rb', line 34

def clear
  @kind.clear
  @start_byte.clear
  @end_byte.clear
  @int1.clear
  @int2.clear
  @int3.clear
  @str1.clear
  self
end

#each_idObject



61
62
63
64
65
66
67
68
69
70
# File 'lib/red_quilt/inline/tokens.rb', line 61

def each_id
  return enum_for(:each_id) unless block_given?

  id = 0
  last = @kind.length
  while id < last
    yield id
    id += 1
  end
end

#emit(kind, start_byte:, end_byte:, int1: 0, int2: 0, int3: 0, str1: nil) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/red_quilt/inline/tokens.rb', line 22

def emit(kind, start_byte:, end_byte:, int1: 0, int2: 0, int3: 0, str1: nil)
  id = @kind.length
  @kind[id] = kind
  @start_byte[id] = start_byte
  @end_byte[id] = end_byte
  @int1[id] = int1
  @int2[id] = int2
  @int3[id] = int3
  @str1[id] = str1
  id
end

#empty?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/red_quilt/inline/tokens.rb', line 49

def empty?
  @kind.empty?
end

#end_byte(id) ⇒ Object



55
# File 'lib/red_quilt/inline/tokens.rb', line 55

def end_byte(id) = @end_byte.[](id)

#int1(id) ⇒ Object



56
# File 'lib/red_quilt/inline/tokens.rb', line 56

def int1(id) = @int1.[](id)

#int2(id) ⇒ Object



57
# File 'lib/red_quilt/inline/tokens.rb', line 57

def int2(id) = @int2.[](id)

#int3(id) ⇒ Object



58
# File 'lib/red_quilt/inline/tokens.rb', line 58

def int3(id) = @int3.[](id)

#kind(id) ⇒ Object



53
# File 'lib/red_quilt/inline/tokens.rb', line 53

def kind(id) = @kind.[](id)

#lengthObject



45
46
47
# File 'lib/red_quilt/inline/tokens.rb', line 45

def length
  @kind.length
end

#start_byte(id) ⇒ Object



54
# File 'lib/red_quilt/inline/tokens.rb', line 54

def start_byte(id) = @start_byte.[](id)

#str1(id) ⇒ Object



59
# File 'lib/red_quilt/inline/tokens.rb', line 59

def str1(id) = @str1.[](id)