Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Treat wildcard as ? instead of * #298

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions sample/lua/expand_translator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,27 @@ local function init(env)
end


local function translate(inp,seg,env)
if string.match(inp,env.wildcard) then
local function translate(inp, seg, env)
if string.match(inp, env.wildcard) then
local inp_len = string.len(inp)
local tail = string.match(inp, '[^'.. env.wildcard .. ']+$') or ''
inp = string.match(inp, '^[^' ..env.wildcard .. ']+')
env.mem:dict_lookup(inp,true, 100) -- expand_search
for dictentry in env.mem:iter_dict()
do
local codetail = string.match(dictentry.comment,tail .. '$') or ''
if tail ~= nil and codetail == tail then
local code = env.mem:decode(dictentry.code)
codeComment = table.concat(code, ",")
local ph = Phrase(env.mem,"expand_translator", seg.start, seg._end, dictentry)
ph.comment = codeComment
yield(ph:toCandidate())
-- you can also use Candidate Simply, but it cannot be recognized by memorize, memorize callback won't be called
-- yield(Candidate("type",seg.start,seg.end,dictentry.text, codeComment ))
env.mem:dict_lookup(inp, true, 100) -- expand_search
for dictentry in env.mem:iter_dict() do
if string.len(dictentry.comment) == inp_len then
local codetail = string.match(dictentry.comment, tail .. '$') or ''
if tail ~= nil and codetail == tail then
local code = env.mem:decode(dictentry.code)
codeComment = table.concat(code, ",")
local ph = Phrase(env.mem, "expand_translator", seg.start, seg._end, dictentry)
ph.comment = codeComment
yield(ph:toCandidate())
-- you can also use Candidate Simply, but it cannot be recognized by memorize, memorize callback won't be called
-- yield(Candidate("type",seg.start,seg.end,dictentry.text, codeComment ))
end
end
end
end
end
end

return {init = init, func = translate}