X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=src%2Fltj-base.lua;h=1ed8ab88bee3d96a55a537bdad738d75e3d51231;hb=ab23049deb6fb90ca689fdf4924b3783f08f8f2e;hp=f80301a0b5ca9e0e8cd84447ae65361bb5e8ef4c;hpb=c7058402b4897aeb375eac689126792230877344;p=luatex-ja%2Fluatexja.git diff --git a/src/ltj-base.lua b/src/ltj-base.lua index f80301a..1ed8ab8 100644 --- a/src/ltj-base.lua +++ b/src/ltj-base.lua @@ -156,20 +156,6 @@ ltjb.mprint = mprint -------------------- Handling of TeX values do - local glue_spec_id = node.id("glue_spec") - - local function copy_skip(s1, s2) - if not s1 then - s1 = node.new(glue_spec_id) - end - s1.width = s2.width or 0 - s1.stretch = s2.stretch or 0 - s1.stretch_order = s2.stretch_order or 0 - s1.shrink = s2.shrink or 0 - s1.shrink_order = s2.shrink_order or 0 - return s1 - end - --! ixbase.to_dimen() と同じ local function to_dimen(val) if val == nil then @@ -192,44 +178,7 @@ do return tex.sp(val), fil end ---! ixbase.to_skip() と同じ - local function to_skip(val) - if type(val) == "userdata" then - return val - end - local res = node.new(glue_spec_id) - if val == nil then - res.width = 0 - elseif type(val) == "number" then - res.width = val - elseif type(val) == "table" then - copy_skip(res, val) - else - local t = tostring(val):lower():explode() - local w, p, m = t[1], t[3], t[5] - if t[2] == "minus" then - p, m = nil, t[3] - end - res.width = tex.sp(t[1]) - if p then - res.stretch, res.stretch_order = parse_dimen(p) - end - if m then - res.shrink, res.shrink_order = parse_dimen(m) - end - end - return res - end - - local function dump_skip(s) - print(("%s+%s<%s>-%s<%s>"):format( - s.width or 0, s.stretch or 0, s.stretch_order or 0, - s.shrink or 0, s.shrink_order or 0)) - end - ltjb.to_dimen = to_dimen - ltjb.dump_skip = dump_skip - ltjb.to_skip = to_skip end -------------------- Virtual table for LaTeX counters @@ -251,200 +200,6 @@ do --! ixbase.length は tex.skip と全く同じなので不要. end --------------------- Number handling in TeX source -do - - local tok_escape = token.create("ltj@@q@escape") - local tok_num = token.create("ltj@@q@escapenum") - local c_id_assign_int = token.command_id("assign_int") - local c_id_char_given = token.command_id("char_given") - - local function error_scan() - package_error("luatexja", - "Missing number of a permitted form, treated as zero", - "A number should have been here; I inserted '0'.") - end - - local function get_expd_next() - local next = token.get_next() - while token.is_expandable(next) do - token.expand(next) - next = token.get_next() - end - return next - end - - local function grab_decimal(next, res) - table.insert(res, next) - while true do - next = get_expd_next() - if not (next[1] == 12 and 0x30 <= next[2] and next[2] <= 0x39) then - break - end - table.insert(res, next) - end - if next[1] == 10 then next = nil end - return true, next - end - - local function grab_hexa(next, res) - local ok = false - table.insert(res, next) - while true do - next = get_expd_next() - if not ((next[1] == 12 and (0x30 <= next[2] and next[2] <= 0x39)) or - ((next[1] == 12 or next[1] == 11) and - (0x41 <= next[2] and next[2] <= 0x46))) then - break - end - ok = true - table.insert(res, next) - end - if next[1] == 10 then next = nil end - return ok, next - end - - local function grab_octal(next, res) - local ok = false - table.insert(res, next) - while true do - next = get_expd_next() - if not (next[1] == 12 and (0x30 <= next[2] and next[2] <= 0x37)) then - break - end - ok = true - table.insert(res, next) - end - if next[1] == 10 then next = nil end - return ok, next - end - - local function grab_charnum(next, res) - table.insert(res, next) - next = token.get_next() - table.insert(res, next) - next = get_expd_next() - if next[1] == 10 then next = nil end - return true, next - end - - local function scan_with(delay, scanner) - local function proc() - if delay ~= 0 then - if delay > 0 then delay = delay - 1 end - return token.get_next() - else - local cont, back = scanner() - if not cont then - ltb.remove_from_callback("token_filter", "ltj@grab@num") - end - return back - end - end - ltb.add_to_callback("token_filter", proc, "ltj@grab@num", 1) - end - - local function scan_brace() - scan_with(1, function() - local next = token.get_next() - if next[1] == 1 then - return false, { tok_escape, next } - elseif next[1] == 10 then - return true, { next } - else - return false, { next } - end - end) - end - - local function scan_number() - scan_with(1, function() - local next = get_expd_next() - local res, ok = { tok_num }, false - while true do - if next[1] == 12 and (next[2] == 0x2B or next[2] == 0x2D) then - table.insert(res, next) - elseif next[1] ~= 10 then - break - end - next = get_expd_next() - end - if next[1] == 12 and 0x30 <= next[2] and next[2] <= 0x39 then - ok, next = grab_decimal(next, res) - elseif next[1] == 12 and next[2] == 0x22 then - ok, next = grab_hexa(next, res) - elseif next[1] == 12 and next[2] == 0x27 then - ok, next = grab_octal(next, res) - elseif next[1] == 12 and next[2] == 0x60 then - ok, next = grab_charnum(next, res) - elseif next[1] == c_id_assign_int or next[1] == c_id_char_given then - table.insert(res, next) - ok, next = true, nil - end - if ok then - table.insert(res, tok_num) - else - error_scan() - res = { tok_escape } - end - if next then table.insert(res, next) end - return false, res - end) - end - - ltjb.scan_brace = scan_brace - ltjb.scan_number = scan_number -end - --------------------- TeX register allocation --- not used in current LuaTeX-ja - -do - local cmod_base_count = token.create('ltj@@count@zero')[2] - local cmod_base_attr = token.create('ltj@@attr@zero')[2] - local cmod_base_dimen = token.create('ltj@@dimen@zero')[2] - local cmod_base_skip = token.create('ltj@@skip@zero')[2] - - local function const_number(name) - if name:sub(1, 1) == '\\' then name = name:sub(2) end - return token.create(name)[2] - end - - local function count_number(name) - if name:sub(1, 1) == '\\' then name = name:sub(2) end - return token.create(name)[2] - cmod_base_count - end - - local function attribute_number(name) - if name:sub(1, 1) == '\\' then name = name:sub(2) end - return token.create(name)[2] - cmod_base_attr - end - - local function dimen_number(name) - if name:sub(1, 1) == '\\' then name = name:sub(2) end - return token.create(name)[2] - cmod_base_dimen - end - - local function skip_number(name) - if name:sub(1, 1) == '\\' then name = name:sub(2) end - return token.create(name)[2] - cmod_base_skip - end - - ltjb.const_number = const_number - ltjb.count_number = count_number - ltjb.attribute_number = attribute_number - ltjb.dimen_number = dimen_number - ltjb.skip_number = skip_number -end - --------------------- getting next token -local cstemp = nil -local function get_cs(s) - cstemp = token.csname_name(token.get_next()) - tex.sprint(cat_lp,'\\' .. s) -end -ltjb.get_cs = get_cs - -------------------- common error message do local function in_unicode(c, admit_math) @@ -563,7 +318,6 @@ do ltjb.save_cache = save_cache end - ---- do local tex_set_attr, tex_get_attr = tex.setattribute, tex.getattribute @@ -573,7 +327,6 @@ do end end end - ---- ltjb._error_set_break = _error_set_break @@ -596,6 +349,33 @@ ltjb.generic_info_no_line = generic_info_no_line ltjb.ltj_warning_no_line = ltj_warning_no_line ltjb.ltj_error = ltj_error +---- deterministic version of luatexbase.add_to_callback +function ltjb.add_to_callback(name,fun,description,priority) + local priority= priority + if priority==nil then + priority=#luatexbase.callback_descriptions(name)+1 + end + if(luatexbase.callbacktypes[name] == 3 and + priority == 1 and + #luatexbase.callback_descriptions(name)==1) then + luatexbase.module_warning("luatexbase", + "resetting exclusive callback: " .. name) + luatexbase.reset_callback(name) + end + local saved_callback={},ff,dd + for k,v in ipairs(luatexbase.callback_descriptions(name)) do + if k >= priority then + ff,dd= luatexbase.remove_from_callback(name, v) + saved_callback[#saved_callback+1]={ff,dd} + end + end + luatexbase.base_add_to_callback(name,fun,description) + for _,v in ipairs(saved_callback) do + luatexbase.base_add_to_callback(name,v[1],v[2]) + end + return +end + -------------------- mock of debug logger if not ltjb.out_debug then local function no_op() end