1 -- filename : type-lam.lua
2 -- comment : Pretty printing of (extended) lambda calculus
3 -- author : Matthijs Kooijman, Universiteit Twente, NL
4 -- copyright: Matthijs Kooijman
7 local utf = unicode.utf8
9 if not buffers then buffers = { } end
10 if not buffers.visualizers then buffers.visualizers = { } end
11 if not buffers.visualizers.lam then buffers.visualizers.lam = { } end
13 buffers.visualizers.lam.colors = {
20 buffers.visualizers.lam.tokens = {
21 [' '] = {repr = '\\obs '},
22 ['_'] = {repr = '\\_'},
23 ['->'] = {repr = '\\rightarrow'},
24 ['case'] = {style = 'bold'},
25 ['of'] = {style = 'bold'},
26 ['let'] = {style = 'bold'},
29 function buffers.visualizers.lam.flush_line(str,nested)
30 local result, state = { }, 0
31 local finish, change = buffers.finish_state, buffers.change_state
32 -- Set the colorscheme, which is used by finish_state and change_state
33 buffers.currentcolors = buffers.visualizers.lam.colors
37 for tok,props in pairs(buffers.visualizers.lam.tokens) do
38 -- Try to remove tok from the start of str
39 str, count = utf.gsub(str, "^" .. tok, "")
41 -- Replace the token with the repr, or just itself
42 result[#result+1] = props.repr or tok
43 -- Enclose the token in {\style .. }
45 result[#result] = "{\\" .. props.style ..
46 " " .. result[#result] ..
49 -- We found a token, now start over
55 result[#result+1] = utf.sub(str, 1, 1)
59 state = finish(state, result)
60 buffers.flush_result(result,nested)
63 -- vim: set sw=4 sts=4 expandtab ai: