コード例 #1
0
ファイル: STRCommands.java プロジェクト: seba--/sugarj
  /** Compiles a {@code *.str} file to a single {@code *.java} file. */
  private static void strj(
      boolean normalize,
      Path str,
      Path out,
      String main,
      Collection<Path> paths,
      AbstractBaseProcessor baseProcessor)
      throws IOException {

    /*
     * We can include as many paths as we want here, checking the
     * adequacy of the occurring imports is done elsewhere.
     */
    List<String> cmd =
        new ArrayList<String>(
            Arrays.asList(
                new String[] {
                  "-i",
                  toWindowsPath(str.getAbsolutePath()),
                  "-o",
                  toWindowsPath(out.getAbsolutePath()),
                  "-m",
                  main,
                  "-p",
                  "sugarj",
                  "--library",
                  "-O",
                  "0",
                }));

    if (normalize) cmd.add("-F");

    cmd.add("-I");
    cmd.add(StdLib.stdLibDir.getAbsolutePath());
    cmd.add("-I");
    cmd.add(baseProcessor.getLanguage().getPluginDirectory().getAbsolutePath());

    for (Path path : paths)
      if (path.getFile().isDirectory()) {
        cmd.add("-I");
        cmd.add(path.getAbsolutePath());
      }

    final ByteArrayOutputStream log = new ByteArrayOutputStream();

    // Strj requires a fresh context each time.
    Context ctx = org.strategoxt.strj.strj.init();
    try {
      ctx.setIOAgent(strjIOAgent);
      ctx.invokeStrategyCLI(main_strj_0_0.instance, "strj", cmd.toArray(new String[cmd.size()]));
    } catch (StrategoExit e) {
      if (e.getValue() != 0) throw new StrategoException("STRJ failed", e);
    } finally {
      if (log.size() > 0 && !log.toString().contains("Abstract syntax in"))
        throw new StrategoException(log.toString());
    }
  }
コード例 #2
0
ファイル: STRCommands.java プロジェクト: seba--/sugarj
 public IStrategoTerm assimilate(String strategy, Path ctree, IStrategoTerm in)
     throws IOException {
   return STRCommands.assimilate(strategy, ctree, in, baseProcessor.getInterpreter());
 }