feat(parse): add rec: inline token parsing
Problem: the buffer parser does not recognize recurrence tokens, so users cannot set recurrence rules inline. Solution: add recur_key() helper and rec: token parsing in body() and command_add(), with ! prefix handling for completion-based mode and validation via recur.validate().
This commit is contained in:
parent
e69e93f536
commit
e19cfdda18
1 changed files with 28 additions and 3 deletions
|
|
@ -29,6 +29,11 @@ local function date_key()
|
|||
return config.get().date_syntax or 'due'
|
||||
end
|
||||
|
||||
---@return string
|
||||
local function recur_key()
|
||||
return config.get().recur_syntax or 'rec'
|
||||
end
|
||||
|
||||
local weekday_map = {
|
||||
sun = 1,
|
||||
mon = 2,
|
||||
|
|
@ -259,7 +264,7 @@ end
|
|||
|
||||
---@param text string
|
||||
---@return string description
|
||||
---@return { due?: string, cat?: string } metadata
|
||||
---@return { due?: string, cat?: string, rec?: string, rec_mode?: 'scheduled'|'completion' } metadata
|
||||
function M.body(text)
|
||||
local tokens = {}
|
||||
for token in text:gmatch('%S+') do
|
||||
|
|
@ -269,8 +274,10 @@ function M.body(text)
|
|||
local metadata = {}
|
||||
local i = #tokens
|
||||
local dk = date_key()
|
||||
local rk = recur_key()
|
||||
local date_pattern_strict = '^' .. vim.pesc(dk) .. ':(%d%d%d%d%-%d%d%-%d%d)$'
|
||||
local date_pattern_any = '^' .. vim.pesc(dk) .. ':(.+)$'
|
||||
local rec_pattern = '^' .. vim.pesc(rk) .. ':(%S+)$'
|
||||
|
||||
while i >= 1 do
|
||||
local token = tokens[i]
|
||||
|
|
@ -305,7 +312,25 @@ function M.body(text)
|
|||
metadata.cat = cat_val
|
||||
i = i - 1
|
||||
else
|
||||
break
|
||||
local rec_val = token:match(rec_pattern)
|
||||
if rec_val then
|
||||
if metadata.rec then
|
||||
break
|
||||
end
|
||||
local recur = require('pending.recur')
|
||||
local raw_spec = rec_val
|
||||
if raw_spec:sub(1, 1) == '!' then
|
||||
metadata.rec_mode = 'completion'
|
||||
raw_spec = raw_spec:sub(2)
|
||||
end
|
||||
if not recur.validate(raw_spec) then
|
||||
break
|
||||
end
|
||||
metadata.rec = raw_spec
|
||||
i = i - 1
|
||||
else
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -322,7 +347,7 @@ end
|
|||
|
||||
---@param text string
|
||||
---@return string description
|
||||
---@return { due?: string, cat?: string } metadata
|
||||
---@return { due?: string, cat?: string, rec?: string, rec_mode?: 'scheduled'|'completion' } metadata
|
||||
function M.command_add(text)
|
||||
local cat_prefix = text:match('^(%S.-):%s')
|
||||
if cat_prefix then
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue