Class: DeepAlgo::IL::Parser

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

Constant Summary collapse

BASE_PATH =
__dir__

Instance Method Summary collapse

Constructor Details

#initialize(curr_backend) ⇒ Parser

Returns a new instance of Parser.



12
13
14
15
16
# File 'lib/parser.rb', line 12

def initialize(curr_backend)
  @curr_backend = curr_backend
  Treetop.load(File.join(BASE_PATH, 'il_parser.treetop'))
  @parser = IlParser.new
end

Instance Method Details

#parse(input) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/parser.rb', line 18

def parse(input)
  data = input.gsub(/(?:#.+?#)/, '')
  tree = nil
  begin
    tree = @parser.parse(data)
  rescue StandardError
    DeepAlgo::IL.log.debug('Error when parsing the file')
    DeepAlgo::IL.log.debug(input.to_s)
  end
  DeepAlgo::IL.log.debug(@parser.failure_reason) if tree.nil?
  tree
end