diff options
Diffstat (limited to 'Sil/Util')
-rw-r--r-- | Sil/Util/Printer.icl | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/Sil/Util/Printer.icl b/Sil/Util/Printer.icl index 55c2498..979e478 100644 --- a/Sil/Util/Printer.icl +++ b/Sil/Util/Printer.icl @@ -31,6 +31,8 @@ decIndent ps = {ps & indent=dec ps.indent} instance toString PrintState where toString st = {'\t' \\ _ <- [1..st.indent]} +instance PrettyPrinter String where print _ s = s + instance PrettyPrinter [Token] where print st [] = "" @@ -68,12 +70,14 @@ where instance PrettyPrinter Program where - print st prog = p st prog.p_globals <+ "\r\n" <+ p st prog.p_funs - where - p :: PrintState [a] -> String | PrettyPrinter a - p _ [] = "" - p st [f] = print st f - p st [f:fs] = print st f <+ "\r\n\r\n" <+ p st fs + print st prog=:{p_globals=gs=:[_:_]} + = stprintersperse st "\r\n" gs <+ "\r\n\r\n" <+ print st {prog & p_globals=[]} + print st prog = stprintersperse st "\r\n\r\n" prog.p_funs + +stprintersperse :: PrintState a [b] -> String | PrettyPrinter a & PrettyPrinter b +stprintersperse st _ [] = "" +stprintersperse st _ [x] = print st x +stprintersperse st g [x:xs] = print st x +++ print st g +++ stprintersperse st g xs instance PrettyPrinter Function where |