lang-exp.lua /size: 8025 b    last modification: 2021-10-28 13:50
1if not modules then modules = { } end modules ['lang-exp'] = {
2    version   = 1.001,
3    comment   = "companion to lang-ini.mkiv",
4    author    = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
5    copyright = "PRAGMA ADE / ConTeXt Development Team",
6    license   = "see context related readme files"
7}
8
9-- This module contains snippets that were used before we expanded
10-- discretionaries in the engine which makes way more sense. This
11-- code is nod used any more.
12
13if true then
14    return
15end
16
17-- lang-dis.lua:
18
19local expanders -- this will go away
20
21-- the penalty has been determined by the mode (currently we force 1):
22--
23-- 0 : exhyphenpenalty
24-- 1 : hyphenpenalty
25-- 2 : automatichyphenpenalty
26--
27-- following a - : the pre and post chars are already appended and set
28-- so we have pre=preex and post=postex .. however, the previous
29-- hyphen is already injected ... downside: the font handler sees this
30-- so this is another argument for doing a hyphenation pass in context
31
32if LUATEXVERSION < 1.005 then -- not loaded any more
33
34    -- some shortcuts go here
35
36    expanders = {
37        [discretionary_code] = function(d,template)
38            -- \discretionary
39            return template
40        end,
41        [explicit_code] = function(d,template)
42            -- \-
43            local pre, post, replace = getdisc(d)
44            local done = false
45            if pre then
46                local char = isglyph(pre)
47                if char and char <= 0 then
48                    done = true
49                    flushlist(pre)
50                    pre = nil
51                end
52            end
53            if post then
54                local char = isglyph(post)
55                if char and char <= 0 then
56                    done = true
57                    flushlist(post)
58                    post = nil
59                end
60            end
61            if done then
62                -- todo: take existing penalty
63                setdisc(d,pre,post,replace,explicit_code,tex.exhyphenpenalty)
64            else
65                setsubtype(d,explicit_code)
66            end
67            return template
68        end,
69        [automatic_code] = function(d,template)
70            local pre, post, replace = getdisc(d)
71            if pre then
72                -- we have a preex characters and want that one to replace the
73                -- character in front which is the trigger
74                if not template then
75                    -- can there be font kerns already?
76                    template = getprev(d)
77                    if template and getid(template) ~= glyph_code then
78                        template = getnext(d)
79                        if template and getid(template) ~= glyph_code then
80                            template = nil
81                        end
82                    end
83                end
84                if template then
85                    local pseudohead = getprev(template)
86                    if pseudohead then
87                        while template ~= d do
88                            pseudohead, template, removed = remove_node(pseudohead,template)
89                            -- free old replace ?
90                            replace = removed
91                            -- break ?
92                        end
93                    else
94                        -- can't happen
95                    end
96                    setdisc(d,pre,post,replace,automatic_code,tex.hyphenpenalty)
97                else
98                 -- print("lone regular discretionary ignored")
99                end
100            else
101                setdisc(d,pre,post,replace,automatic_code,tex.hyphenpenalty)
102            end
103            return template
104        end,
105        [regular_code] = function(d,template)
106            if check_regular then
107                -- simple
108                if not template then
109                    -- can there be font kerns already?
110                    template = getprev(d)
111                    if template and getid(template) ~= glyph_code then
112                        template = getnext(d)
113                        if template and getid(template) ~= glyph_code then
114                            template = nil
115                        end
116                    end
117                end
118                if template then
119                    local language = template and getlanguage(template)
120                    local data     = getlanguagedata(language)
121                    local prechar  = data.prehyphenchar
122                    local postchar = data.posthyphenchar
123                    local pre, post, replace = getdisc(d) -- pre can be set
124                    local done     = false
125                    if prechar and prechar > 0 then
126                        done = true
127                        pre  = copy_node(template)
128                        setchar(pre,prechar)
129                    end
130                    if postchar and postchar > 0 then
131                        done = true
132                        post = copy_node(template)
133                        setchar(post,postchar)
134                    end
135                    if done then
136                        setdisc(d,pre,post,replace,regular_code,tex.hyphenpenalty)
137                    end
138                else
139                 -- print("lone regular discretionary ignored")
140                end
141                return template
142            end
143        end,
144        [disccodes.first] = function()
145            -- forget about them
146        end,
147        [disccodes.second] = function()
148            -- forget about them
149        end,
150    }
151
152    function languages.expand(d,template,subtype)
153        if not subtype then
154            subtype = getsubtype(d)
155        end
156        if subtype ~= discretionary_code then
157            return expanders[subtype](d,template)
158        end
159    end
160
161else
162
163    function languages.expand()
164        -- nothing to be fixed
165    end
166
167end
168
169languages.expanders = expanders
170
171-- lang-hyp.lua:
172
173----- expanders          = languages.expanders -- gone in 1.005
174----- expand_explicit    = expanders and expanders[explicit_code]
175----- expand_automatic   = expanders and expanders[automatic_code]
176
177-- if LUATEXVERSION < 1.005 then -- not loaded any more
178--
179--     expanded = function(head)
180--         local done = hyphenate(head)
181--         if done then
182--             for d in traverseid(disc_code,head) do
183--                 local s = getsubtype(d)
184--                 if s ~= discretionary_code then
185--                     expanders[s](d,template)
186--                     done = true
187--                 end
188--             end
189--         end
190--         return head, done
191--     end
192--
193-- end
194
195--                 if id == disc_code then
196--                     if expanded then
197--                         -- pre 1.005
198--                         local subtype = getsubtype(current)
199--                         if subtype == discretionary_code then -- \discretionary
200--                             size = 0
201--                         elseif subtype == explicit_code then -- \- => only here
202--                             -- automatic (-) : the old parser makes negative char entries
203--                             size = 0
204--                             expand_explicit(current)
205--                         elseif subtype == automatic_code then -- - => only here
206--                             -- automatic (-) : the old hyphenator turns an exhyphen into glyph+disc
207--                             size = 0
208--                             expand_automatic(current)
209--                         else
210--                             -- first         : done by the hyphenator
211--                             -- second        : done by the hyphenator
212--                             -- regular       : done by the hyphenator
213--                             size = 0
214--                         end
215--                     else
216--                         size = 0
217--                     end
218--                     current = getnext(current)
219--                     if hyphenonly then
220--                         skipping = true
221--                     end
222