Class: Kaitai::Struct::Visualizer::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/kaitai/struct/visualizer/parser.rb

Overview

Base class for everything that deals with compiling .ksy and parsing stuff as object tree.

Direct Known Subclasses

Visualizer

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(compiler, bin_fn, formats_fn, opts) ⇒ Parser

Returns a new instance of Parser.



17
18
19
20
21
22
# File 'lib/kaitai/struct/visualizer/parser.rb', line 17

def initialize(compiler, bin_fn, formats_fn, opts)
  @compiler = compiler
  @bin_fn = bin_fn
  @formats_fn = formats_fn
  @opts = opts
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



15
16
17
# File 'lib/kaitai/struct/visualizer/parser.rb', line 15

def data
  @data
end

Instance Method Details

#loadObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/kaitai/struct/visualizer/parser.rb', line 24

def load
  main_class_name = @compiler.compile_formats(@formats_fn)

  main_class = Kernel::const_get(main_class_name)
  @data = main_class.from_file(@bin_fn)

  load_exc = nil
  begin
    @data._read
  rescue EOFError => e
    load_exc = e
  rescue Kaitai::Struct::Stream::UnexpectedDataError => e
    load_exc = e
  end

  return load_exc
end