lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi!

Here is new self-sufficient library for pretty printing Lua structures.

Project page: http://github.com/zoon/luapp/

Library files: http://luaforge.net/projects/luapp/

It's rather advanced - it lets adjust width and maximum number of 
non-indentation characters that should appear on a line. Also, it removes 
artificial `[]' in keys, sort keys lexicographically etc.

Motivation example:

-- test.lua
local pp = require'luapp'.pp

local data =
{"Call",{"Id","print"},{"Add",{"Num", 1},
{"Mul",{"Num", 2},{"Div",{"Num",4},{"Num",2}}}},
{"Add",{"Num", 1},{"Mul",{"Num", 2},
{"Div",{"Num",4},{"Num",2}}}}}

print("=== 78 col ribbon=0,6 ==========")
print(pp(data))
print("")
print("==== 120 col ribbon=1.0 ========")
print(pp(data,'TREE',120,1))

-- output
[luapp51]$ lua test.lua
=== 78 col ribbon=0,6 ==========
{"Call",
 {"Id", "print"},
 {"Add",
  {"Num", 1},
  {"Mul",
   {"Num", 2},
   {"Div", {"Num", 4}, {"Num", 2}}}},
 {"Add",
  {"Num", 1},
  {"Mul",
   {"Num", 2},
   {"Div", {"Num", 4}, {"Num", 2}}}}}

==== 120 col ribbon=1.0 ========
{"Call",
 {"Id", "print"},
 {"Add", {"Num", 1}, {"Mul", {"Num", 2}, {"Div", {"Num", 4}, {"Num", 2}}}},
 {"Add", {"Num", 1}, {"Mul", {"Num", 2}, {"Div", {"Num", 4}, {"Num", 2}}}}}
 


PS. Library is a derivative of:
 1. Philip Wadler. (April 1997) A prettier printer. Draft paper.
    http://homepages.inf.ed.ac.uk/wadler/papers/prettier/prettier.pdf
 2. Daan Leijen (Oct 2001) PPrint, a prettier printer.
    http://research.microsoft.com/users/daan/download/pprint/pprint.html
 3. Christian Lindig (March 2000) Strictly Pretty.
    http://www.citeulike.org/group/8/article/828964
    http://www.st.cs.uni-sb.de/~lindig/#quest 

Cheers,
    Andrew