diff options
| author | Marius <mariausol@gmail.com> | 2010-07-04 15:32:09 +0300 | 
|---|---|---|
| committer | Marius <mariausol@gmail.com> | 2010-07-04 15:32:09 +0300 | 
| commit | 85b7bc695629926641c7cb752fd478adfdf374f3 (patch) | |
| tree | 80293f5aaa7b95a500a78392c39688d8ee7a32fc /tex/context/base/pret-tex.lua | |
| download | context-85b7bc695629926641c7cb752fd478adfdf374f3.tar.gz | |
stable 2010-05-24 13:10
Diffstat (limited to 'tex/context/base/pret-tex.lua')
| -rw-r--r-- | tex/context/base/pret-tex.lua | 87 | 
1 files changed, 87 insertions, 0 deletions
| diff --git a/tex/context/base/pret-tex.lua b/tex/context/base/pret-tex.lua new file mode 100644 index 000000000..5d128fa3b --- /dev/null +++ b/tex/context/base/pret-tex.lua @@ -0,0 +1,87 @@ +if not modules then modules = { } end modules ['pret-tex'] = { +    version   = 1.001, +    comment   = "companion to buff-ver.mkiv", +    author    = "Hans Hagen, PRAGMA-ADE, Hasselt NL", +    copyright = "PRAGMA ADE / ConTeXt Development Team", +    license   = "see context related readme files" +} + +local utf = unicode.utf8 + +local utfcharacters, utfvalues = string.utfcharacters, string.utfvalues +local utfbyte, utffind = utf.byte, utf.find +local rep = string.rep +local texsprint, texwrite = tex.sprint, tex.write +local ctxcatcodes, vrbcatcodes = tex.ctxcatcodes, tex.vrbcatcodes + +local visualizer = buffers.newvisualizer("tex") + +local colors = { +    "prettytwo", +    "prettyone", +    "prettythree", +    "prettyfour" +} + +local states = { +    ['$']=2, ['{']=2, ['}']=2, +    ['[']=3, [']']=3, ['(']=3, [')']=3, ['<']=3, ['>']=3, ['#']=3, ['=']=3, ['"']=3, +    ['/']=4, ['^']=4, ['_']=4, ['-']=4, ['&']=4, ['+']=4, ["'"]=4, ['`']=4, ['|']=4, ['%']=4 +} + +-- some day I'll make an lpeg + +local change_state, finish_state = buffers.change_state, buffers.finish_state + +local chardata = characters.data +local is_letter = characters.is_letter + +function visualizer.flush_line(str,nested) +    local state, first, i = 0, false, 0 +    buffers.currentcolors = colors +    for c in utfcharacters(str) do +        i = i + 1 +        if c == " " then +            state = finish_state(state) +            texsprint(ctxcatcodes,"\\obs") +            first = false +        elseif c == "\t" then +            state = finish_state(state) +            texsprint(ctxcatcodes,"\\obs") +            if buffers.visualizers.enabletab then +                texsprint(ctxcatcodes,rep("\\obs ",i%buffers.visualizers.tablength)) +                i = 0 +            end +            first = false +        elseif first then +            state = 1 +            texwrite(c) +            if not utffind(c,"^[%a%!%?%@]$") then +                state = finish_state(state) +            end +            first = false +        elseif state == 1 then +            if utffind(c,"^[%a%!%?%@]$") then +                texwrite(c) +                first = false +            elseif c == "\\" then +                state = change_state(1, state) +                texwrite(c) +                first = true +            else +                state = change_state(states[c], state) +                texwrite(c) +                first = false +            end +        elseif c == "\\" then +            first = true +            state = change_state(1, state) +            texwrite(c) +        else +            state = change_state(states[c], state) +            texwrite(c) +            first = false +        end +    end +    state = finish_state(state) +end | 
