Begin key combo parser

pull/3/head
Iron-E 4 years ago
parent b35e436abc
commit af118200d3
No known key found for this signature in database
GPG Key ID: 19B71B7B7B021D22

@ -0,0 +1,119 @@
--[[
/*
* IMPORTS
*/
--]]
local api = vim.api
--[[
/*
* MODULE
*/
--]]
local ParseTable = {}
local strings = {} -- not to be returned.
--[[
/*
* CONSTANTS
*/
--]]
ParseTable.EXE = 'exe'
--[[
/*
* f(x)
*/
--]]
function strings.split(str, pattern)
local split = {}
for char in string.gmatch(str, pattern) do
table.insert(split, char)
end
return table.concat(split, '')
end
-------------------------
--[[ SUMMARY:
* Create a new parse table from a user-defined table.
]]
--[[ PARAMS:
* `userTable` => the table of combos defined by the user.
]]
-------------------------
function ParseTable:new(userTable)
local userTable = {
-------------------------------
--[[ SUMMARY:
* Put `value` into the parse tree as `key`.
]]
--[[ PARAMS:
* `key` => the key that `value` is reffered to by.
* `value` => the value to store as `key`.
]]
-------------------------------
_put = function(__self, key, value)
-- Iterate to get the next dictionaries.
local function _access(dict, splitKey)
-- Get the next character in the table.
local char = api.nvim_eval('char2nr(' .. table.remove(splitKey) .. ')')
-- If there are still items in the table.
if #splitKey > 0 then
if not dict[char] then
dict[char] = {}
-- If there is a previous command mapping in place
elseif type(dict[char]) == 'string' then
-- Swap the mapping to an s:EX_KEY.
dict[char] = {[ParseTable.EXE] = dict[char]}
end
dict[char] = _access(dict, key)
elseif dict[key] then
dict[key][char] = value
else
dict[key] = value
end
return dict
end
-- Iterate over ther eturn from access.
for k, v in pairs(_access(
__self, strings.split(string.reverse(key), '.')
)) do
table.insert(parsedDict, k, v)
end
end,
-------------------------------
--[[ SUMMARY:
* Create the union of `self` and `tableToUnite`
]]
--[[ PARAMS:
* `tableToUnite` => the table to unite with `self.`
]]
-------------------------------
union = function(__self, tableToUnite)
for k, v in pairs(tableToUnite) do
if not __self[k] then
__self:_put(k, v)
end
end
end
}
return userTable:_union(userTable)
end
--[[
/*
* PUBLICIZE MODULE
*/
--]]
return ParseTable

@ -4,9 +4,12 @@
*/
--]]
local globals = require('libmodal/src/base/globals')
local utils = require('libmodal/src/utils')
local api = utils.api
local globals = require('libmodal/src/base/globals')
local ParseTable = require('libmodal/src/mode/ParseTable')
local utils = require('libmodal/src/utils')
local api = utils.api
local vars = utils.vars
--[[
/*
@ -16,7 +19,7 @@ local api = utils.api
local mode = {}
--------------------------------
------------------------
--[[ SUMMARY:
* Enter a mode.
]]
@ -26,7 +29,7 @@ local mode = {}
* `args[2]` => the mode callback, or mode combo table.
* `args[3]` => optional exit supresion flag.
]]
--------------------------------
------------------------
function mode.enter(...)
local args = {...}
@ -43,14 +46,21 @@ function mode.enter(...)
handleExitEvents = true
end
-- Determine whether a callback was specified, or a combo table.
local doTimeout = nil
if type(args[2]) == 'table' then
if api.nvim_exists('g', utils.vars.timeout.name(modeName)) then
doTimeout = utils.vars.get(vars.timeout, modeName)
-- Placeholder for timeout value.
local doTimeout = nil
-- Read the correct timeout variable.
if api.nvim_exists('g', vars.timeout.name(modeName)) then
doTimeout = vars.nvim_get(vars.timeout, modeName)
else
doTimeout = utils.vars.libmodalTimeout
doTimeout = vars.libmodalTimeout
end
print(doTimeout)
vars.timeout.instances[modeName] = doTimeout
vars.combos.instances[modeName] = ParseTable:new(a[2])
end
end
@ -60,5 +70,6 @@ end
*/
--]]
mode.enter('test', {})
print(tostring(string.gmatch('testing', '.')))
return mode

@ -37,23 +37,33 @@ local vars = {
-------------------------------
local function new(keyName, varName)
vars[keyName] = {
-- Instances of variables pertaining to a certain mode.
instances = {},
-------------------------
--[[ SUMMARY:
* Get the name of `modeName`s global setting.
]]
--[[ PARAMS:
* `modeName` => the name of the mode.
]]
-------------------------
name = function(modeName)
return modeName .. varName
end
end,
}
end
-------------------------------
------------------------------------
--[[ SUMMARY:
* Retrieve a variable value.
]]
--[[ PARAMS:
* `var` => the `vars.*` table to retrieve the value of.
* `modeName` => the mode name this value is being retrieved for.
]]
-------------------------------
function vars.get(var, modeName)
------------------------------------
function vars.nvim_get(var, modeName)
return api.nvim_get_vars(var.name(modeName))
end

Loading…
Cancel
Save