Debugging a suffix automaton? Try this:
echo science | dawgviz | dot -Tsvg -o science.svg
-
Install Nim.
-
Install LuaJIT.
On a Debian-based distribution, this is as simple as
sudo apt install libluajit-5.1-2
. On Windows, you’ll probably need to copyluajit.dll
tobin\
after buildingdawgviz.exe
. -
Install Graphviz.
Strictly speaking, this is optional, but you won’t be able to generate pictures without it.
-
Clone this repository.
-
Run
nimble build -d=release
. -
Install the built program.
On Windows, you’ll need to add
bin\
directory toPATH
. On Unix, a more idiomatic way is
make PREFIX=~/.local install
orsudo make install
. Do not try to install via Nimble: it won’t work.
Usage:
dawgviz [-T<fmt>] [-e<code>...] [<custom-formatter>...]
Options:
-V, --version Print version.
-T=, --target= Select output format (or `-` for none).
-e=, --eval= Evaluate Lua code after loading everything.
Use -T
option to choose an output format for the graph. dot
(used by default) and json
formatters are provided:
echo zoom | dawgviz -Tjson
{"i":"zoom","g":[{
"s":"",
"p":-1,
"d":{"o":4,"m":5,"z":1}
},{
"s":"z",
"p":0,
"l":0,
"d":{"o":2}
},{
"s":"zo",
"p":1,
"l":4,
"d":{"o":3}
},{
"s":"zoo",
"p":2,
"l":4,
"d":{"m":5}
},{
"s":"o",
"p":1,
"c":true,
"l":0,
"d":{"m":5,"o":3}
},{
"s":"zoom",
"p":3,
"l":0,
"d":{}
}]}
Use -e
option to tweak the behaviour of the selected formatter. Its argument is a piece of Lua
code:
echo zoom | dawgviz -e'graph_attrs.rankdir="LR"'
echo zoom | dawgviz -Tjson -e'substring_key=nil'
echo zoom | dawgviz -Tjson -e'prologue="[{"; epilogue="}]"'
Want to know what exactly is available for configuration? Take a look at dot.lua. Remember, you can redeclare anything.
-e
option works great for small one-time tweaks. If, however, you use the same configuration over
and over again, it may be more convenient to store it in a file.
#!/usr/bin/env dawgviz
require "dawgviz.target.dot"
node_attrs.shape = "hexagon"
function Node:get_id() return self.id + 1 end -- Emit 1-based indices.
echo zoom | dawgviz my.lua
When a custom formatter is passed, dot
will no longer be loaded implicitly.