模組:沙盒/a2569875/Test4
外观
local p={}
function p._cdd_substr(str)
local str_len = mw.ustring.len(str)
local stack = {}
local buf = {''}
local pre_tokens = {}
local b_map = {
['('] = ')',
['['] = ']',
['{'] = '}',
['-'] = '-',
}
local i=1
while i <= str_len do
local ch = mw.ustring.sub(str,i,i)
if ch == '(' or ch == '[' or ch == '{' or (ch == '-' and #stack == 0) then
if #stack == 0 and buf[#buf]~='' then
pre_tokens[#pre_tokens + 1] = buf[#buf]
buf[#buf] = ''
end
stack[#stack + 1] = ch
buf[#buf + 1] = ch
elseif ch == ')' or ch == ']' or ch == '}' or (ch == '-' and stack[#stack] == '-') then
local pop = stack[#stack]
local pop_buf = buf[#buf]
stack[#stack] = nil
buf[#buf] = nil
if b_map[pop] ~= ch then
i = i-1
ch = b_map[pop]
end
buf[#buf] = buf[#buf] .. pop_buf .. ch
if #stack <= 0 and buf[#buf] ~= '' then
pre_tokens[#pre_tokens + 1] = buf[#buf]
buf[#buf] = ''
end
else
if #stack == 0 then
pre_tokens[#pre_tokens + 1] = ch
else
buf[#buf] = buf[#buf] .. ch
end
end
i=i+1
end
for i=1,#stack do
local pop = stack[#stack]
local pop_buf = buf[#buf]
stack[#stack] = nil
buf[#buf] = nil
local ch = b_map[pop]
buf[#buf] = buf[#buf] .. pop_buf .. ch
end
if buf[#buf] ~= '' then pre_tokens[#pre_tokens + 1] = buf[#buf] end
local tokens = {}
local last_type = ''--lacings
for i=1,#pre_tokens do
local ch = pre_tokens[i]
local fch = mw.ustring.sub(ch,1,1)
local ch_type = ''
if mw.ustring.match(ch, "[oxqfvhkuwFesβm]")then
ch_type = 'node'
elseif mw.ustring.match(ch, "[%d/'∞%siØπλ]")then
ch_type = 'number'
elseif mw.ustring.match(ch, "[&#]")then
ch_type = 'lacing'
elseif mw.ustring.match(fch, "[%-%(%[%{]")then
ch_type = 'group'
elseif mw.ustring.match(fch, "%*")then
ch_type = 'star'
if last_type == 'star' then ch_type = 'ignore' end
end
if last_type == 'star' then
tokens[#tokens+1] = buf[1] .. ch
buf[1] = ''
elseif ch_type == 'group' then
if last_type == 'node' then
tokens[#tokens+1] = buf[1] .. ch
elseif last_type == 'star' then
tokens[#tokens+1] = buf[1] .. ch
else
if buf[1] ~= '' then tokens[#tokens+1] = buf[1]end
tokens[#tokens+1] = ch
end
buf[1] = ''
elseif ch_type == 'number' or ch_type == 'lacing' then
if last_type == ch_type then
buf[1] = buf[1] .. ch
else
if buf[1] ~= '' then tokens[#tokens+1] = buf[1]end
buf[1] = ch
end
else
if buf[1] ~= '' then tokens[#tokens+1] = buf[1]end
buf[1] = ch
end
last_type = ch_type
end
if buf[1] ~= '' then tokens[#tokens+1] = buf[1]end
return tokens
end
function p.scfi(frame)
local args, working_frame
if frame == mw.getCurrentFrame() then
-- We're being called via #invoke. The args are passed through to the module
-- from the template page, so use the args that were passed into the template.
args = frame.args
working_frame = frame
else
-- We're being called from another module or from the debug console, so assume
-- the args are passed in directly.
args = frame
working_frame = mw.getCurrentFrame()
if type(args) ~= type({}) then args = {frame} end
end
local p_p = args[1] or args['1']
local p_q = args[3] or args['3']
local p_r = args[5] or args['5']
local yesno = require('Module:Yesno')
local p_help = yesno(args.help)
p_p = (mw.text.trim(p_p or '')~='') and p_p or nil
p_q = (mw.text.trim(p_q or '')~='') and p_q or nil
p_r = (mw.text.trim(p_r or '')~='') and p_r or nil
local data_p, flag_p = mw.ustring.gsub(args[2] or args['2'] or '','([^\/]+)/([^\/]+)','<sup>%1</sup>/<sub>%2</sub>')
local data_q, flag_q = mw.ustring.gsub(args[4] or args['4'] or '','([^\/]+)/([^\/]+)','<sup>%1</sup>/<sub>%2</sub>')
local data_h, flag_h = mw.ustring.gsub(args[6] or args['6'] or '','([^\/]+)/([^\/]+)','<sup>%1</sup>/<sub>%2</sub>')
local data_pp, flag_pp = mw.ustring.gsub(args[7] or args['7'] or '','([^\/]+)/([^\/]+)','<sup>%1</sup>/<sub>%2</sub>')
local need_show = (tonumber(p_p or 2) ~= 2) or (tonumber(p_q or 2) ~= 2) or (tonumber(p_r or 2) ~= 2)
local p_h = mw.text.trim(data_h or '')~='' and data_h or nil
local p_pp = mw.text.trim(data_pp or '')~='' and data_pp or nil
p_h = (tonumber(p_h or 2) ~= 2)
p_pp = (tonumber(p_pp or 2) ~= 2)
local p_str = p_help and ('<abbr title="構成面的多邊形邊數">'.. data_p .. '</abbr>') or data_p
local q_str = p_help and ('<abbr title="共用相同頂點的多邊形數">'.. data_q .. '</abbr>') or data_q
local h_str = p_help and ('<abbr title="立體結構中孔洞的形狀的邊數">'.. data_h .. '</abbr>') or data_h
local pp_str = p_help and ('<abbr title="赤道面上扭歪多邊形邊數">'.. data_pp .. '</abbr>') or data_pp
pp_str = flag_pp and ('<sub>' .. (need_show and ('<sub>' .. pp_str .. '</sub>') or pp_str) .. '</sub>') or pp_str
local function set_split_str(text, mode, show)
return (mode==1) and (show and ('<sub>' .. text .. '</sub>{') or '{') or (
(mode==2) and (show and ('}<sub>' .. text .. '</sub>{') or ',') or (
(mode==3) and '|' or
(show and ('}<sub>' .. text .. '</sub>') or '}')))
end
return set_split_str(p_p, 1, need_show) .. p_str .. set_split_str(p_q, 2, need_show) .. q_str
..(p_h and (set_split_str(p_p, 3, need_show) .. h_str) or '') .. set_split_str(p_r, 4, need_show)
..(p_pp and ('<sub>' .. pp_str .. '</sub>') or '')
end
function p.cdd(frame)
local args, working_frame
if frame == mw.getCurrentFrame() then
-- We're being called via #invoke. The args are passed through to the module
-- from the template page, so use the args that were passed into the template.
args = frame.args
working_frame = frame
else
-- We're being called from another module or from the debug console, so assume
-- the args are passed in directly.
args = frame
working_frame = mw.getCurrentFrame()
if type(args) ~= type({}) then args = {frame} end
end
local cdd = args[1] or args['1'] or ''
local tail, pos = mw.ustring.find(cdd, "%s+%*", 0)
local old_tail, spilt_result = 0, {}
while(pos ~= nil)do
spilt_result[#spilt_result+1] = mw.ustring.sub(cdd, old_tail, tail-1)
old_tail = pos
tail, pos = mw.ustring.find(cdd, "%s+%*", pos+1)
end
spilt_result[#spilt_result+1] = mw.ustring.sub(cdd, old_tail, -1)
local tokens = {}
for i=1,#spilt_result do
tokens[#tokens+1]=p._cdd_substr(spilt_result[i])
end
mw.logObject(tokens)
end
--{{#invoke:沙盒/a2569875/Test4|navRedirect}}
function p.navRedirect(frame)
local args, working_frame
if frame == mw.getCurrentFrame() then
-- We're being called via #invoke. The args are passed through to the module
-- from the template page, so use the args that were passed into the template.
args = frame.args
working_frame = frame
else
-- We're being called from another module or from the debug console, so assume
-- the args are passed in directly.
args = frame
working_frame = mw.getCurrentFrame()
if type(args) ~= type({}) then args = {frame} end
end
local title = mw.text.trim(args[1] or args['1'] or '')
local display = mw.text.trim(args[2] or args['2'] or '')
local title_obj = mw.title.new(title)
local title_target = title_obj
local section = ''
local title_sp = mw.text.trim(mw.ustring.sub(title, (({mw.ustring.find(title, '#')})[1]or 0)+1, -1) or '')
if title_obj then
if title_obj.isRedirect then
title_target = title_obj.redirectTarget
end
if display == '' then display = ((title_sp == '') and title or title_sp) end
section = mw.text.trim(title_target.fragment or '')
local cur_title = mw.title.getCurrentTitle()
if (cur_title.namespace == title_target.namespace) and (cur_title.text == title_target.text)then
local section_text = ''
local section_name = mw.text.trim(title_target.fragment or '')
if section_name ~= '' then
section_text = "([[#" .. section_name .. "|章節]])"
end
return "'''"..display.."'''"..section_text
end
return "[["..title.."|"..display.."]]"
else return ''
end
end
return p