Package org.spoofax.interpreter.terms

Examples of org.spoofax.interpreter.terms.IStrategoTerm


    String modelPath = ATermCommands.getString(context.current());
    try {
      Path p = ModuleSystemCommands.importModel(modelPath, env, driverResult);
      if (p == null)
        return false;
      IStrategoTerm model = ATermCommands.atermFromFile(p.getAbsolutePath());
      if (model == null)
        return false;
      context.setCurrent(model);
      return true;
    } catch (IOException e) {
View Full Code Here


   * @param asModel If true, looks for models. If false, looks for transformations.
   * @return
   */
  private RelativePath resolveModule(IStrategoTerm term, IStrategoTerm toplevelDecl, boolean asModel) throws TokenExpectedException, IOException, ParseException, InvalidParseTableException, SGLRException, InterruptedException {
    if (ATermCommands.isApplication(term, "TransApp")) {
      IStrategoTerm model = ATermCommands.getApplicationSubterm(term, "TransApp", 1);
      IStrategoTerm transformation = ATermCommands.getApplicationSubterm(term, "TransApp", 0);
      Pair<String, Boolean> transformedModel = transformModel(model, transformation, toplevelDecl);
      if (transformedModel != null) {
        if (asModel)
          return ModuleSystemCommands.importModel(transformedModel.a, environment, driverResult);
        else
View Full Code Here

        driverResult.addDependency(transformedModelResult);
        return Pair.create(transformedModelPath, false);
      }
      else {
        // transform the model, prepare the import of the resulting code.
        IStrategoTerm transformedModel = executeTransformation(modelPath, transformationPath, toplevelDecl, environment, str, driver);
        String transformedModelText = ATermCommands.atermToString(transformedModel);
        driverResult.generateFile(transformedModelSourceFile, transformedModelText);
       
        boolean isCircularImport = driver.prepareImport(toplevelDecl, transformedModelPath);
        return Pair.create(transformedModelPath, isCircularImport);
View Full Code Here

   *
   * @param model Path to the *.model file that contains the Aterm model.
   * @param transformationPath Path to the *.str transformation.
   */
  private static IStrategoTerm executeTransformation(RelativePath model, RelativePath transformationPath, IStrategoTerm toplevelDecl, Environment environment, STRCommands str, Driver driver) throws IOException, TokenExpectedException, BadTokenException, InvalidParseTableException, SGLRException {
    IStrategoTerm modelTerm = ATermCommands.atermFromFile(model.getAbsolutePath());
    String strat = "main-" + FileCommands.dropExtension(transformationPath.getRelativePath()).replace('/', '_');
    Result transformationResult = ModuleSystemCommands.locateResult(FileCommands.dropExtension(transformationPath.getRelativePath()), environment);
   
    Path trans = str.compile(transformationPath, strat, transformationResult.getTransitiveFileDependencies());
   
    IStrategoTerm transformationInput =
        ATermCommands.makeTuple(
            modelTerm,
            ATermCommands.makeString(FileCommands.dropExtension(model.getRelativePath()), null),
            ATermCommands.makeString(FileCommands.dropExtension(transformationPath.getRelativePath()), null));

    try {
      IStrategoTerm transformedTerm = str.assimilate(strat, trans, transformationInput);
      return transformedTerm;
    } catch (StrategoException e) {
      String msg = "Failed to apply transformation " + transformationPath.getRelativePath() + " to model " + model.getRelativePath() + ": " + e.getMessage();
      driver.setErrorMessage(toplevelDecl, msg);
      throw new StrategoException(msg);
View Full Code Here

  private List<IStrategoTerm> terms;
  int index;
  private final int hash;
 
  public TermToplevelDeclarationProvider(IStrategoTerm source) {
    IStrategoTerm packageDecOption = ATermCommands.getApplicationSubterm(source, "CompilationUnit", 0);
    IStrategoTerm importDecs = ATermCommands.getApplicationSubterm(source, "CompilationUnit", 1);
    IStrategoTerm bodyDecs = ATermCommands.getApplicationSubterm(source, "CompilationUnit", 2);
   
    index = 0;
    terms = new ArrayList<IStrategoTerm>();
   
    if (ATermCommands.isApplication(packageDecOption, "Some"))
View Full Code Here

  // TODO use origin factory
  public static ITermFactory factory = new ParentTermFactory(new TermFactory().getFactoryWithStorageType(IStrategoTerm.MUTABLE));
  public static ParseTableManager parseTableManager = new ParseTableManager(factory, false);

  public static IStrategoTerm atermFromFile(String filename) throws IOException {
    IStrategoTerm term = Environment.terms.get(filename);
   
    if (term != null)
      return term;
   
    return new TAFTermReader(factory).parseFromFile(filename);
View Full Code Here

  public static IStrategoTerm makeTuple(IStrategoTerm... ts) {
    return makeTuple(null, ts);
  }
 
  public static IStrategoTerm makeTuple(IToken tok, IStrategoTerm... ts) {
    IStrategoTerm t = factory.makeTuple(ts);
    setAttachment(t, "Tuple", tok, ts);
    return t;
  }
View Full Code Here

   
    return makeAppl("None", "Some", 0, noneToken);
  }

  public static IStrategoTerm makeString(String s) {
    IStrategoTerm t = factory.makeString(s);
    setAttachment(t, "String", null);
    return t;
  }
View Full Code Here

    setAttachment(t, "String", null);
    return t;
  }

  public static IStrategoTerm makeString(String s, IToken token) {
    IStrategoTerm t = factory.makeString(s);
    setAttachment(t, "String", token);
    return t;
  }
View Full Code Here

  }
 
  public static IStrategoTerm makeAppl(String cons, String sort, int arity, IToken emptyArgsToken, IStrategoTerm... args) {
    assert emptyArgsToken != null || args.length > 0;
   
    IStrategoTerm appl =
      factory.makeAppl(
             factory.makeConstructor(cons, arity),
             args);
   
    setAttachment(appl, sort, emptyArgsToken, args);
View Full Code Here

TOP

Related Classes of org.spoofax.interpreter.terms.IStrategoTerm

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.