Class: Capture::Breadcrumb

Inherits:
Object
  • Object
show all
Defined in:
lib/rpeg/captures.rb

Overview

Used inside the VM when recording capture information.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(size, subject_index, data, kind) ⇒ Breadcrumb

q.v. LPEG’s Capture struct (lpcap.h)

We use size instead of siz, subject_index instead of s, and data instead of idx.



19
20
21
22
23
24
25
26
# File 'lib/rpeg/captures.rb', line 19

def initialize(size, subject_index, data, kind)
  raise "Bad Capture kind #{kind}" unless KINDS.include?(kind)

  @size = size
  @subject_index = subject_index
  @data = data
  @kind = kind
end

Instance Attribute Details

#dataObject

From time to time we need to tweak each of these



14
15
16
# File 'lib/rpeg/captures.rb', line 14

def data
  @data
end

#kindObject

From time to time we need to tweak each of these



14
15
16
# File 'lib/rpeg/captures.rb', line 14

def kind
  @kind
end

#sizeObject

From time to time we need to tweak each of these



14
15
16
# File 'lib/rpeg/captures.rb', line 14

def size
  @size
end

#subject_indexObject

From time to time we need to tweak each of these



14
15
16
# File 'lib/rpeg/captures.rb', line 14

def subject_index
  @subject_index
end

Instance Method Details

#close?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/rpeg/captures.rb', line 33

def close?
  @kind == CLOSE
end

#end_indexObject

The index of the end of the match, q.v. LPEG’s closeaddr (lpcap.h)



38
39
40
# File 'lib/rpeg/captures.rb', line 38

def end_index
  @subject_index + size - 1
end

#full?Boolean

An “open” capture is a “full capture” if it has non-zero size. See isfullcap in lpcap.c

Returns:

  • (Boolean)


29
30
31
# File 'lib/rpeg/captures.rb', line 29

def full?
  @size.positive?
end

#to_sObject

Dynamic because of the setters we sometimes use



43
44
45
# File 'lib/rpeg/captures.rb', line 43

def to_s
  "Breadcrumb size:#{size} sub_idx:#{subject_index} data:#{data.inspect} kind:#{kind}"
end