"[chore] migrate lua code to be compatible with 5.5 syntax.
This commit is contained in:
@@ -83,8 +83,8 @@ function AuxFilter.readAuxTxt(txtpath)
|
||||
local auxCodes = {}
|
||||
for line in file:lines() do
|
||||
if line ~= nil and line ~= "" then -- 检查 line 是否为空
|
||||
line = line:match("[^\r\n]+") -- 去掉換行符,不然 value 是帶著 \n 的
|
||||
local key, value = line:match("([^=]+)=(.+)") -- 分割 = 左右的變數
|
||||
local line_ = line:match("[^\r\n]+") -- 去掉換行符,不然 value 是帶著 \n 的
|
||||
local key, value = line_:match("([^=]+)=(.+)") -- 分割 = 左右的變數
|
||||
if key and value then
|
||||
auxCodes[key] = auxCodes[key] or {}
|
||||
table.insert(auxCodes[key], value)
|
||||
@@ -219,6 +219,7 @@ function AuxFilter.func(input, env)
|
||||
|
||||
-- 遍歷每一個待選項
|
||||
for cand in input:iter() do
|
||||
local cand_ = cand
|
||||
local auxCodes = AuxFilter.aux_code[cand.text] -- 僅單字非 nil
|
||||
local fullAuxCodes = AuxFilter.fullAux(env, cand.text)
|
||||
|
||||
@@ -236,7 +237,7 @@ function AuxFilter.func(input, env)
|
||||
local shadowText = cand.text
|
||||
local shadowComment = cand.comment
|
||||
local originalCand = cand:get_genuine()
|
||||
cand = ShadowCandidate(originalCand, originalCand.type, shadowText,
|
||||
cand_ = ShadowCandidate(originalCand, originalCand.type, shadowText,
|
||||
originalCand.comment .. shadowComment .. '(' .. codeComment .. ')')
|
||||
else
|
||||
cand.comment = '(' .. codeComment .. ')'
|
||||
@@ -246,11 +247,11 @@ function AuxFilter.func(input, env)
|
||||
-- 過濾輔助碼
|
||||
if #auxStr == 0 then
|
||||
-- 沒有輔助碼、不需篩選,直接返回待選項
|
||||
yield(cand)
|
||||
yield(cand_)
|
||||
elseif #auxStr > 0 and fullAuxCodes and (cand.type == 'user_phrase' or cand.type == 'phrase') and
|
||||
AuxFilter.match(fullAuxCodes, auxStr) then
|
||||
-- 匹配到辅助码的待选项,直接插入到候选框中( 获得靠前的位置 )
|
||||
yield(cand)
|
||||
yield(cand_)
|
||||
else
|
||||
-- 待选项字词 没有 匹配到当前的辅助码,插入到列表中,最后插入到候选框里( 获得靠后的位置 )
|
||||
-- table.insert(insertLater, cand)
|
||||
|
||||
@@ -21,10 +21,11 @@ end
|
||||
|
||||
local function cn_en_spacer(input, env)
|
||||
for cand in input:iter() do
|
||||
local cand_ = cand
|
||||
if is_mixed_cn_en_num(cand.text) then
|
||||
cand = cand:to_shadow_candidate(cand.type, add_spaces(cand.text), cand.comment)
|
||||
cand_ = cand:to_shadow_candidate(cand.type, add_spaces(cand.text), cand.comment)
|
||||
end
|
||||
yield(cand)
|
||||
yield(cand_)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -7,11 +7,12 @@ local F = {}
|
||||
function F.func( input, env )
|
||||
local latest_text = env.engine.context.commit_history:latest_text()
|
||||
for cand in input:iter() do
|
||||
local cand_ = cand
|
||||
if cand.text:match( '^[%a\']+[%a\']*$' ) and latest_text and #latest_text > 0 and
|
||||
latest_text:find( '^ ?[%a\']+[%a\']*$' ) then
|
||||
cand = cand:to_shadow_candidate( 'en_spacer', cand.text:gsub( '(%a+\'?%a*)', ' %1' ), cand.comment )
|
||||
cand_ = cand:to_shadow_candidate( 'en_spacer', cand.text:gsub( '(%a+\'?%a*)', ' %1' ), cand.comment )
|
||||
end
|
||||
yield( cand )
|
||||
yield( cand_ )
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ local function get_pos( text, char )
|
||||
local first_char = tmp:sub( 1, utf8.offset( tmp, 2 ) - 1 )
|
||||
if first_char == char then pos[i] = true end
|
||||
tmp = tmp:gsub( '^' .. first_char, '' )
|
||||
i = i + 1
|
||||
end
|
||||
end
|
||||
return pos
|
||||
|
||||
Reference in New Issue
Block a user