Class: Furnace::AVM2::Tokens::PackageToken

Inherits:
Code::NonterminalToken
  • Object
show all
Defined in:
lib/furnace-avm2/source/declaration_tokens/package_token.rb

Instance Method Summary collapse

Constructor Details

#initialize(origin, options = {}) ⇒ PackageToken

Returns a new instance of PackageToken.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/furnace-avm2/source/declaration_tokens/package_token.rb', line 3

def initialize(origin, options={})
  options[:ns] = options[:ns].reject { |ns|
    ns.name == "" || ns.name == "*"
  }

  import_ns = options[:ns].reject { |ns|
    ns.name == options[:package_name].ns.name ||
      ns.name == "__AS3__.vec" ||
      ns.name !~ /^[A-Za-z0-9_$.]+$/
  }

  case options[:package_type]
  when :class, :interface
    content = ClassToken.new(origin, options)
  when :script
    content = ScriptToken.new(origin, options)
  end

  scope = nil
  if content.children.any?
    scope = ScopeToken.new(origin, [
      *import_ns.map { |ns|
        ImportToken.new(origin, ns.name, options)
      },
      (Furnace::Code::NewlineToken.new(origin, options) if import_ns.any?),
      content
    ], options)
  end

  super(origin, [
    (PackageNameToken.new(origin, options[:package_name].ns.name, options) if options[:package_name]),
    scope,
  ], options)
end