All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.snapscript.compile.assemble.ApplicationLinker Maven / Gradle / Ivy

There is a newer version: 1.4.6
Show newest version
package org.snapscript.compile.assemble;

import static org.snapscript.core.Reserved.GRAMMAR_PACKAGE;

import java.util.concurrent.Executor;

import org.snapscript.common.Cache;
import org.snapscript.common.LeastRecentlyUsedCache;
import org.snapscript.core.Context;
import org.snapscript.core.link.Package;
import org.snapscript.core.link.PackageLinker;
import org.snapscript.core.module.Path;

public class ApplicationLinker implements PackageLinker {
   
   private final Cache cache;
   private final PackageBuilder builder;  
   
   public ApplicationLinker(Context context, Executor executor) {
      this.cache = new LeastRecentlyUsedCache();
      this.builder = new PackageBuilder(context, executor);
   }
   
   @Override
   public Package link(Path path, String source) throws Exception {
      return link(path, source, GRAMMAR_PACKAGE);
   }
   
   @Override
   public Package link(Path path, String source, String grammar) throws Exception {
      Package linked = cache.fetch(path);
      
      if(linked == null) {
         linked = builder.create(path, source, grammar); 
         cache.cache(path, linked);
      }
      return linked; 
   } 
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy