Class: MrbParser::Section

Inherits:
Object
  • Object
show all
Defined in:
lib/mrb_parser/section.rb

Direct Known Subclasses

DebugSection, EndSection, IrepSection, LinenoSection

Constant Summary collapse

BINARY_EOF =
"END\0"
IREP_IDENTIFIER =
"IREP"
LINENO_IDENTIFIER =
"LINE"
DEBUG_IDENTIFIER =
"DBG\0"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(signature = nil, size = nil) ⇒ Section

Returns a new instance of Section.



16
17
18
19
# File 'lib/mrb_parser/section.rb', line 16

def initialize(signature = nil, size = nil)
  @signature = signature
  @size = size
end

Instance Attribute Details

#signatureObject (readonly)

Returns the value of attribute signature.



14
15
16
# File 'lib/mrb_parser/section.rb', line 14

def signature
  @signature
end

#sizeObject (readonly)

Returns the value of attribute size.



14
15
16
# File 'lib/mrb_parser/section.rb', line 14

def size
  @size
end

Class Method Details

.parse(parser) ⇒ Object



21
22
23
24
# File 'lib/mrb_parser/section.rb', line 21

def self.parse(parser)
  section = MrbParser::Section.new
  section.parse(parser)
end

Instance Method Details

#end?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/mrb_parser/section.rb', line 46

def end?
  false
end

#parse(parser) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/mrb_parser/section.rb', line 26

def parse(parser)
  signature = parser.read_chars(4)
  size = parser.read_uint32
  case signature
  when IREP_IDENTIFIER
    section = MrbParser::IrepSection
  when LINENO_IDENTIFIER
    section = MrbParser::LinenoSection
  when DEBUG_IDENTIFIER
    section = MrbParser::DebugSection
  when BINARY_EOF
    section = MrbParser::EndSection
  else
    raise MrbParser::Error, "cannot parse; invalid section signature: '#{signature}'"
  end
  sec = section.new(signature, size)
  sec.parse_body(parser)
  sec
end