경고 : 최신판이 아닙니다. 이 문서의 오래된 판을 편집하고 있습니다. 이것을 저장하면, 이 판 이후로 바뀐 모든 편집이 사라집니다. 로그인하고 있지 않습니다. 편집하면 당신의 IP 주소가 공개적으로 기록됩니다. 계정을 만들고 로그인하면 편집 시 사용자 이름만 보이며, 위키 이용에 여러 가지 편의가 주어집니다.스팸 방지 검사입니다. 이것을 입력하지 마세요!--[[ -- token 변수는 실제 사용자로부터 입력받는 글자, 또는 화면에 출력되는 글자를 -- 정의합니다. 만약 이 모듈을 포크해서 다른 위키로 가져가는 경우 이 부분을 필 -- 요에 따라 다르게 수정하면 됩니다. --]] local token = { -- mw 파일 표기 prefix-- file_header = '파일:마작-', img_side = '-누움', -- 수패 -- man = '만', pin = '통', sou = '삭', -- 자패 -- E = '동', S = '남', W = '서', N = '북', white = '백', green = '발', red = '중', -- 꽃패 -- --[[ 꽃패 사용 시 여기와 하단의 주석들을 지워 주세요 f1 = '춘', f2 = '하', f3 = '추', f4 = '동', f5 = '매', f6 = '난', f7 = '국', f8 = '죽', --]] -- 펑, 치, 깡 -- pon = '펑', chi = '치', kan = '깡', left = '상가', face = '대가', right = '하가', -- 뒷면 -- back = '뒤', -- 특수표기 -- dora = '적', side = '-', double = '/', -- 쯔모, 론, 도라, 게임 등의 옵션들 -- tsumo_ = '쯔모', ron_ = '론', dora_ = '도라', wind_ = '자리', side_ = '가', game_ = '게임', -- 에러메시지 -- error = { default = "에러가 발생했습니다. 구문을 확인해주세요", body = "패가 잘못되었습니다. 구문을 확인해주세요", braket = "괄호가 없거나 잘못되었습니다. 구문을 확인해주세요" }, -- 공백 -- space = ' ' } -- 이미지 기본값 -- local image_default_size = 33 local image_real_width = 66 local image_real_height = 90 --[[ 헬퍼 함수들 ]]-- local ustring = mw.ustring local image_ratio = function (x) return math.floor(x * image_real_height / image_real_width) end -- switch-case 문을 위한 함수 -- -- from http://lua-users.org/wiki/SwitchStatement -- local function switch (t) t.case = function (self, x) local f = self[x] or self.default if f then if type(f) == "function" then f(x, self) else error("case "..tostring(x).." not a function") end end end return t end -- mw용 이미지 문법을 생성해주는 함수 -- local function toImg ( data, width, height, wrapper, left ) width = '|' .. width .. 'px' local result = '[[' .. token.file_header .. data .. '.png'..width..'|link=|bottom]]' if (wrapper) then result = '<div style="margin-bottom: -15px;bottom:'..height..'px;left:'..left..'px;display: inline-block;"><div style="display: block;">'..result..'</div>' end return result end -- 에러 출력용 함수 -- local function err ( message, pos, func ) func = (func ~= nil) and '['..func..'] ' or '' pos = (pos ~= nil) and 'p'..pos..': ' or '' error(func..pos..message) end -- 펑/깡을 위한 방향 체크 -- local pon_dir = { [token.left] = 1, [token.face] = 2, [token.right] = 3 } local kan_dir = { [token.left] = 1, [token.face] = 2, [token.right] = 4 } --[[ 입력받은 값을 분석하는 메인 함수 ]]-- local function single_parse ( data, options ) if (data == nil) then err(token.error.default) end local index = 0 local stack = {} local result = "" local post = "" local pos = 0 local leftpx = 0 local wrapper = false local global_wrapper = false local size = options.size or image_default_size local token_parse = { -- 특수표기 -- [token.dora] = function (x) stack[index+1] = {pre = x} end, [token.side] = function (x) post = token.img_side end, [token.double] = function (x) wrapper = true ; post = token.img_side end, default = function (x) return true end } -- 수패 -- local function numbers (x) for i = 1, index do local width = (stack[i].post ~= '') and image_ratio(size) or size local caption = (stack[i].pre or '') .. stack[i].main .. x .. (stack[i].post or '') result = result .. toImg( caption, width, size, stack[i].wrapper, leftpx ) if (stack[i].wrapper) then -- 이중 처리 result = result .. toImg( caption, width, size, false, leftpx ) .. '</div>' end leftpx = leftpx + width end index = 0 ; stack = {} ; post = "" end token_parse[token.man], token_parse[token.pin], token_parse[token.sou] = numbers, numbers, numbers -- 자패, 뒷면 -- local function strings (x) local width = (post ~= '') and image_ratio(size) or size result = result .. toImg( x..post, width, size, wrapper, leftpx ) if (wrapper) then -- 이중 처리 result = result .. toImg( x..post, width, size, false, leftpx ) .. '</div>' end leftpx = leftpx + width index = 0 ; stack = {} ; post = "" end token_parse[token.E] = strings token_parse[token.S] = strings token_parse[token.W] = strings token_parse[token.N] = strings token_parse[token.white] = strings token_parse[token.green] = strings token_parse[token.red] = strings token_parse[token.back] = strings -- 꽃패 -- --[[ 꽃패 사용 시 이 주석을 지워 주세요 token_parse[token.f1] = strings token_parse[token.f2] = strings token_parse[token.f3] = strings token_parse[token.f4] = strings token_parse[token.f5] = strings token_parse[token.f6] = strings token_parse[token.f7] = strings token_parse[token.f8] = strings --]] -- 치 -- token_parse[token.chi] = function (x) local body = ustring.match(data, "%d?.") or '' if (#body == 0) then err(token.error.body, pos, token.chi) end local tail = ustring.match(data, "%d?.%((.-)%)") or '' -- 괄호 부분 체크 if (#tail == 0) then err(token.error.braket, pos, token.chi) end data = data:sub(#body+#tail+3) -- 괄호 기호 (2개) 포함 pos = pos + ustring.len(body..tail) + 2 result = result .. single_parse( token.side..body..tail, options ) -- 치는 반드시 상가에게만 받게됨 end -- 펑 -- token_parse[token.pon] = function (x) local body = ustring.match(data, "/?%d?.") or '' if (#body == 0) then err(token.error.body, pos, token.pon) end local tail = ustring.match(data, "%d?.%((.-)%)") or '' -- 괄호 부분 체크 if (#tail == 0) then err(token.error.braket, pos, token.pon) end data = data:sub(#body+#tail+3) -- 괄호 기호 (2개) 포함 pos = pos + ustring.len(body..tail) + 2 local dir = pon_dir[tail] or -1 local selector = token.side local caption = '' local wrapper = false -- 가깡 처리 -- if (body:sub(1, 1) == '/') then body = body:sub(2) selector = token.double wrapper = true end -- 방향에 맞게 캡션 처리 -- for i = 1, 3 do if (i == dir) then caption = caption .. selector end caption = caption .. body end result = result .. single_parse( caption, options ) end -- 깡 -- token_parse[token.kan] = function (x) local body = ustring.match(data, "%d?.") or '' if (#body == 0) then err(token.error.body, pos, token.kan) end local tail = ustring.match(data, "%d?.%((.-)%)") or '' -- 괄호 부분 체크 data = data:sub(#body+1) if (#tail > 0) then data:sub(#tail+3); pos = pos + 2 end -- 괄호 기호 (2개) 포함 pos = pos + ustring.len(body..tail) local caption = '' if (#tail == 0) then -- 안깡 -- caption = token.back .. body .. body .. token.back else -- 대명깡 -- local dir = kan_dir[tail] or -1 for i = 1, 4 do if (i == dir) then caption = caption .. token.side end caption = caption .. body end end result = result .. single_parse( caption, options ) end -- switch 문 구성 -- token_parse = switch(token_parse) -- utf8 문자별로 루프 진행 while #data > 0 do local c = ustring.match(data, ".") -- data:match("[%z\1-\127\194-\244][\128-\191]*") data = data:sub(#c+1) ; pos = pos + 1 local may_int = tonumber(c) or -1 if (may_int >= 1 and may_int <= 9) then -- 수패에 적용되는 숫자 입력이 들어온 경우 index = index + 1 stack[index] = stack[index] or {} -- 스택에 이미 들어있던 값은 유지한다 -- 필요한 값들을 스택에 넣는다 stack[index].main = c ; stack[index].post = post ; stack[index].wrapper = wrapper post = "" ; wrapper = false else token_parse:case(c) -- 문자가 들어오는 경우는 위 select-case 문에 따라 처리 end global_wrapper = global_wrapper or wrapper end if (global_wrapper) then result = '<div class="majong" style="display:inline-block;margin-top:'..(size * 2 - image_ratio(size))..'px;">'..result..'</div>' end return result end local function parse ( frame ) -- '파싱' 함수 entry point return single_parse( frame.args[1]:match("^%s*(.-)%s*$"), frame.args ) -- trim end local function print ( frame ) -- '출력' 함수 entry point local result = '' local data = {} for k, line in pairs(frame.args) do -- 옵션값을 제외한 나머지 입력값들을 data에 모음 if (type(k) == "number") then data[k] = line end end for i = 1, #data do result = result .. single_parse( data[i]:match("^%s*(.-)%s*$"), frame.args ) -- trim if (i ~= #data) then result = result .. token.space end end -- 게임 옵션 출력 -- local game = '' if (frame.args[token.game_] ~= nil) then game = frame.args[token.game_] end -- 자리 출력 -- if (frame.args[token.wind_] ~= nil) then if (game ~= '') then game = game .. token.space end game = game .. frame.args[token.wind_] .. token.side_ end if (game ~= '') then result = '(' .. game .. ')' .. token.space .. result end -- 쯔모패 출력 -- if (frame.args[token.tsumo_] ~= nil) then result = result .. token.space .. token.tsumo_ .. single_parse(frame.args[token.tsumo_], frame.args) elseif (frame.args[token.ron_] ~= nil) then result = result .. token.space .. token.ron_ .. single_parse(frame.args[token.ron_], frame.args) end -- 도라패 출력 -- if (frame.args[token.dora_] ~= nil) then result = result .. token.space .. token.dora_ .. single_parse(frame.args[token.dora_], frame.args) end return result end return { ['파싱'] = parse, ['출력'] = print, -- 자주 쓰이는 함수들 -- ['만수패'] = function (f) return single_parse( "123456789만", f ) end, ['통수패'] = function (f) return single_parse( "123456789통", f ) end, ['삭수패'] = function (f) return single_parse( "123456789삭", f ) end, ['자패'] = function (f) return single_parse( "동남서북백발중", f ) end, ['바람패'] = function (f) return single_parse( "동남서북", f ) end, -- ['꽃패'] = function (f) return single_parse( "춘하추동매난국죽", f ) end, ['삼원패'] = function (f) return single_parse( "백발중", f ) end } 요약: 리브레 위키에서의 모든 기여는 크리에이티브 커먼즈 저작자표시-동일조건변경허락 3.0 라이선스로 배포됩니다(자세한 내용에 대해서는 리브레 위키:저작권 문서를 읽어주세요). 만약 여기에 동의하지 않는다면 문서를 저장하지 말아 주세요. 글이 직접 작성되었거나 호환되는 라이선스인지 확인해주세요. 리그베다 위키, 나무위키, 오리위키, 구스위키, 디시위키 및 CCL 미적용 사이트 등에서 글을 가져오실 때는 본인이 문서의 유일한 기여자여야 하고, 만약 본인이 문서의 유일한 기여자라는 증거가 없다면 그 문서는 불시에 삭제될 수 있습니다. 취소 편집 도움말 (새 창에서 열림) | () [] [[]] {{}} {{{}}} · <!-- --> · [[분류:]] · [[파일:]] · [[미디어:]] · #넘겨주기 [[]] · {{ㅊ|}} · <onlyinclude></onlyinclude> · <includeonly></includeonly> · <noinclude></noinclude> · <br /> · <ref></ref> · {{각주}} · {|class="wikitable" · |- · rowspan=""| · colspan=""| · |} {{lang|}} · {{llang||}} · {{인용문|}} · {{인용문2|}} · {{유튜브|}} · {{다음팟|}} · {{니코|}} · {{토막글}} {{삭제|}} · {{특정판삭제|}}(이유를 적지 않을 경우 기각될 가능성이 높습니다. 반드시 이유를 적어주세요.) {{#expr:}} · {{#if:}} · {{#ifeq:}} · {{#iferror:}} · {{#ifexist:}} · {{#switch:}} · {{#time:}} · {{#timel:}} · {{#titleparts:}} __NOTOC__ · __FORCETOC__ · __TOC__ · {{PAGENAME}} · {{SITENAME}} · {{localurl:}} · {{fullurl:}} · {{ns:}} –(대시) ‘’(작은따옴표) “”(큰따옴표) ·(가운뎃점) …(말줄임표) ‽(물음느낌표) 〈〉(홑화살괄호) 《》(겹화살괄호) ± − × ÷ ≈ ≠ ∓ ≤ ≥ ∞ ¬ ¹ ² ³ ⁿ ¼ ½ ¾ § € £ ₩ ¥ ¢ † ‡ • ← → ↔ ‰ °C µ(마이크로) Å °(도) ′(분) ″(초) Α α Β β Γ γ Δ δ Ε ε Ζ ζ Η η Θ θ Ι ι Κ κ Λ λ Μ μ(뮤) Ν ν Ξ ξ Ο ο Π π Ρ ρ Σ σ ς Τ τ Υ υ Φ φ Χ χ Ψ ψ Ω ω · Ά ά Έ έ Ή ή Ί ί Ό ό Ύ ύ Ώ ώ · Ϊ ϊ Ϋ ϋ · ΐ ΰ Æ æ Đ(D with stroke) đ Ð(eth) ð ı Ł ł Ø ø Œ œ ß Þ þ · Á á Ć ć É é Í í Ĺ ĺ Ḿ ḿ Ń ń Ó ó Ŕ ŕ Ś ś Ú ú Ý ý Ź ź · À à È è Ì ì Ǹ ǹ Ò ò Ù ù · İ Ż ż ·  â Ĉ ĉ Ê ê Ĝ ĝ Ĥ ĥ Î î Ĵ ĵ Ô ô Ŝ ŝ Û û · Ä ä Ë ë Ï ï Ö ö Ü ü Ÿ ÿ · ǘ ǜ ǚ ǖ · caron/háček: Ǎ ǎ Č č Ď ď Ě ě Ǐ ǐ Ľ ľ Ň ň Ǒ ǒ Ř ř Š š Ť ť Ǔ ǔ Ž ž · breve: Ă ă Ğ ğ Ŏ ŏ Ŭ ŭ · Ā ā Ē ē Ī ī Ō ō Ū ū · à ã Ñ ñ Õ õ · Å å Ů ů · Ą ą Ę ę · Ç ç Ş ş Ţ ţ · Ő ő Ű ű · Ș ș Ț ț 이 문서에서 사용한 틀: 틀:새로고침 (원본 보기) (준보호됨)틀:설명문서 (원본 보기) (준보호됨)모듈:마작패 (편집) 모듈:마작패/설명문서 (편집)