module pp

imports
  libstratego-lib

imports

  libstratego-gpp
  libspoofax/sdf/pp
  libspoofax/editor/refactoring/-
  pp/IBAF-parenthesize
  pp/IBAF-pp

rules

  editor-format:
    (node, _, ast, path, project-path) -> (filename, result)
    with
      ext      := <get-extension> path
    ; filename := <guarantee-extension(|$[pp.[ext]])> path
    ; result   := <pp-debug> node

rules
  
  pp-IBAF-string =
    parenthesize-IBAF
    ; prettyprint-IBAF-start-symbols
    ; !V([], <id>)
    ; box2text-string(|120)
      
  pp-partial-IBAF-string =
    parenthesize-IBAF
    ; prettyprint-IBAF
    ; !V([], <id>)
    ; box2text-string(|120)
    
  pp-partial-IBAF-string(|sort) =
    parenthesize-IBAF
    ; prettyprint-IBAF(|sort)
    ; !V([], <id>)
    ; box2text-string(|120)  
      
  pp-debug :
    ast -> result
    with
       result := <pp-IBAF-string> ast
    <+ <bottomup(try(not(is-string); not(is-list); not(pp-IBAF-string); debug(!"cannot pp ")))> ast
    ;  result := ""

rules
  
  construct-textual-change = construct-textual-change(pp-partial-IBAF-string, parenthesize, override-reconstruction, resugar)
