module strategoxt-xtc-tools

/**
 * asfix
 */
strategies

  xtc-implode-asfix =
    xtc-transform(!"implode-asfix", pass-verbose)

  xtc-asfix-yield =
    xtc-transform(!"asfix-yield", pass-verbose)

/**
 * gpp/box
 */
strategies

  xtc-abox-format =
    xtc-transform(!"abox-format", pass-verbose)

  xtc-ast2abox(pps) =
    xtc-transform(!"ast2abox",
      <conc> (
        <pass-verbose> ()
      , <pps; map(xtc-find); <add-arg-flags> ("-p", <id>)> ()
      )
    )

  xtc-abox2text =
    xtc-transform(!"abox2text", pass-verbose)

  xtc-abox2text(width) =
    xtc-transform(!"abox2text", <conc> (["--width", <width; int-to-string> ()], <pass-verbose> ()))

  xtc-parse-pp-table =
    xtc-transform(!"parse-pp-table")

/**
 * sglr
 */
strategies

  xtc-sglr(tbl) =
    xtc-transform(!"sglr", !["-2A", "-p", <tbl; xtc-find> () | <pass-v-verbose> ()])

  xtc-sglr(tbl, sort) =
    xtc-transform(!"sglr", !["-2A", "-p", <tbl; xtc-find> (), "-s", <sort> () | <pass-v-verbose> ()])

/**
 * sglri
 */
strategies

  xtc-sglri(|tbl) =
    xtc-transform(!"sglri", !["-p", <xtc-find> tbl | <pass-verbose> ()])

  xtc-sglri(|tbl, sort) =
    xtc-transform(!"sglri", !["-p", <xtc-find> tbl, "--start", sort | <pass-verbose> ()])

/**
 * stratego
 */
strategies

  xtc-pp-astratego =
      xtc-stratego-ensugar
    ; xtc-ast2abox(!["Stratego-pretty.pp"])
    ; xtc-abox2text

  xtc-stratego-ensugar = 
    xtc-transform(!"stratego-ensugar", pass-verbose)

  /* tools */

  pass-v-verbose =
      ![]; if-verbose3(!["-v"])

  // :: String * [String] -> [String]
  add-arg-flags =
       \ (_   , []    ) -> [] \
    <+ \ (flag, values) -> [flag | <<separate-by> (flag, <id>)> values ] \
