Class: RedQuilt::Inline::Tokens
- Inherits:
-
Object
- Object
- RedQuilt::Inline::Tokens
- 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
- #clear ⇒ Object
- #each_id ⇒ Object
- #emit(kind, start_byte:, end_byte:, int1: 0, int2: 0, int3: 0, str1: nil) ⇒ Object
- #empty? ⇒ Boolean
- #end_byte(id) ⇒ Object
-
#initialize ⇒ Tokens
constructor
A new instance of Tokens.
- #int1(id) ⇒ Object
- #int2(id) ⇒ Object
- #int3(id) ⇒ Object
- #kind(id) ⇒ Object
- #length ⇒ Object
- #start_byte(id) ⇒ Object
- #str1(id) ⇒ Object
Constructor Details
#initialize ⇒ Tokens
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
#clear ⇒ Object
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_id ⇒ Object
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
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) |
#length ⇒ Object
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) |