Module: SFRP::Input::Parser

Extended by:
Parser
Included in:
Parser
Defined in:
lib/sfrp/input/parser.rb

Defined Under Namespace

Classes: Parser

Instance Method Summary collapse

Instance Method Details

#parse(source_file) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/sfrp/input/parser.rb', line 9

def parse(source_file)
  parser = Parser.new
  transformer = Transformer.new
  defs = transformer.apply(parser.parse(source_file.content))
  imports, others = defs.each_with_object([[], []]) do |a, o|
    case a
    when Raw::Import
      o[0] << a
    else
      o[1] << a
    end
  end
  ns = Raw::Namespace.new(source_file.fmodule_uri, imports)
  others.each do |a|
    a.ns = ns
    a.vconsts.each { |b| b.ns = ns } if a.is_a?(Raw::TConst)
  end
  others
rescue Parslet::ParseFailed => err
  raise ParseError.new(err.cause.ascii_tree)
end