public function transpile($sourcePaths, $outputPaths)
 {
     $ASTCollection = new TES4ScriptCollection();
     foreach ($sourcePaths as $k => $sourcePath) {
         $lexer = new \Ormin\OBSLexicalParser\TES4\Lexer\ScriptLexer();
         $tokens = $lexer->lex(file_get_contents($sourcePath));
         $ASTCollection->add($this->parser->parse($tokens), $outputPaths[$k]);
     }
     $TES5ASTCollection = $this->converter->convert($ASTCollection);
     /**
      * @var TES5Target $target
      */
     foreach ($TES5ASTCollection->getIterator() as $target) {
         file_put_contents($target->getOutputPath(), $target->getScript()->output());
         passthru('lua "Utilities/beautifier.lua" "' . $target->getOutputPath() . '"');
     }
 }
 /**
  * @param TES4ScriptCollection $scripts
  * @return TES5ScriptCollection
  * @throws ConversionException
  */
 public function convert(TES4ScriptCollection $scripts)
 {
     $transpiledCollection = new TES5ScriptCollection();
     $scriptHeaders = [];
     $globalScopes = [];
     /**
      * @var TES4Target $scriptTarget
      */
     foreach ($scripts->getIterator() as $k => $scriptTarget) {
         $script = $scriptTarget->getScript();
         //Create the header.
         $scriptHeader = $this->createHeader($script);
         $variableList = $script->getVariableDeclarationList();
         $globalScope = new TES5GlobalScope($scriptHeader);
         foreach ($this->esmAnalyzer->getGlobalVariables() as $globalVariable) {
             $globalScope->addGlobalVariable($globalVariable);
         }
         if ($variableList !== null) {
             $this->propertiesFactory->createProperties($variableList, $globalScope);
         }
         $scriptHeaders[$k] = $scriptHeader;
         $globalScopes[$k] = $globalScope;
     }
     //Add the static global scopes which are added by complimenting scripts..
     $staticGlobalScopes = $this->staticGlobalScopesFactory->createGlobalScopes();
     foreach ($staticGlobalScopes as $staticGlobalScope) {
         $globalScopes[] = $staticGlobalScope;
     }
     $multipleScriptsScope = new TES5MultipleScriptsScope($globalScopes);
     /**
      * @var TES4Target $scriptTarget
      */
     foreach ($scripts->getIterator() as $k => $scriptTarget) {
         $scriptHeader = $scriptHeaders[$k];
         $globalScope = $globalScopes[$k];
         $script = $scriptTarget->getScript();
         $blockList = new TES5BlockList();
         $parsedBlockList = $script->getBlockList();
         $createdBlocks = [];
         if ($parsedBlockList !== null) {
             foreach ($parsedBlockList->getBlocks() as $block) {
                 $newBlockList = $this->blockFactory->createBlock($multipleScriptsScope, $globalScope, $block);
                 foreach ($newBlockList->getBlocks() as $newBlock) {
                     if (!isset($createdBlocks[$newBlock->getBlockType()])) {
                         $createdBlocks[$newBlock->getBlockType()] = [];
                     }
                     $createdBlocks[$newBlock->getBlockType()][] = $newBlock;
                 }
             }
         }
         //todo encapsulate it to a different class.
         foreach ($createdBlocks as $blockType => $blocks) {
             if (count($blocks) > 1) {
                 /**
                  * @var TES5FunctionCodeBlock[] $functions
                  */
                 $functions = [];
                 $i = 1;
                 $localScopeArguments = null;
                 /**
                  * @var TES5EventCodeBlock $block
                  */
                 foreach ($blocks as $block) {
                     $function = new TES5FunctionCodeBlock($blockType . "_" . $i, null, $block->getLocalScope(), $block->getCodeScope());
                     $functions[] = $function;
                     if ($localScopeArguments === null) {
                         $localScopeArguments = new TES5ObjectCallArguments();
                         foreach ($block->getLocalScope()->getLocalVariables() as $localVariable) {
                             $localScopeArguments->add($this->referenceFactory->createReferenceToVariable($localVariable));
                         }
                     }
                     ++$i;
                 }
                 //Create the proxy block.
                 $proxyBlock = $this->blockFactory->createNewBlock($blockType, clone $block->getLocalScope());
                 foreach ($functions as $function) {
                     $blockList->add($function);
                     $functionCall = $this->valueFactory->createObjectCall($this->referenceFactory->createReferenceToSelf($globalScope), $function->getFunctionName(), $multipleScriptsScope, $localScopeArguments, false);
                     $proxyBlock->addChunk($functionCall);
                 }
                 $blockList->add($proxyBlock);
             } else {
                 $block = current($blocks);
                 $blockList->add($block);
             }
         }
         $tesScript = new TES5Script($scriptHeader, $globalScope, $blockList);
         $transpiledCollection->add($tesScript, $scriptTarget->getOutputPath());
     }
     return $transpiledCollection;
 }