Exemple #1
0
  public static IStrategoTerm assimilate(
      String strategy, Path ctree, IStrategoTerm in, HybridInterpreter interp) throws IOException {
    try {
      interp.load(ctree.getAbsolutePath());
      interp.setCurrent(in);

      if (interp.invoke(strategy)) {
        IStrategoTerm term = interp.current();

        // XXX performance improvement?
        //        interp.reset();

        //        IToken left = ImploderAttachment.getLeftToken(in);
        //        IToken right = ImploderAttachment.getRightToken(in);
        //        String sort = ImploderAttachment.getSort(in);
        //
        //        try {
        //          term = ATermCommands.makeMutable(term);
        //          ImploderAttachment.putImploderAttachment(term, false, sort, left, right);
        //        } catch (Exception e) {
        //          log.log("origin annotation failed");
        //        }
        return term;
      } else throw new RuntimeException("hybrid interpreter failed");
    } catch (InterpreterException e) {
      throw new StrategoException(
          "desugaring failed: " + (e.getCause() == null ? e : e.getCause()).getMessage(), e);
    } catch (Exception e) {
      throw new StrategoException("desugaring failed", e);
    }
  }
 public static @Nullable IStrategoTerm invoke(
     HybridInterpreter interpreter, IStrategoTerm input, String function) throws SpoofaxException {
   try {
     interpreter.setCurrent(input);
     final boolean success = interpreter.invoke(function);
     if (!success) {
       return null;
     }
     return interpreter.current();
   } catch (InterpreterException e) {
     throw new SpoofaxException("Invoking Stratego function failed", e);
   }
 }