aboutsummaryrefslogtreecommitdiff
path: root/lua/lexers/taskpaper.lua
blob: 643280b269db076d9ac9d6cd511c497b84c5c4f0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
-- Copyright (c) 2016-2025 Larry Hynes. See LICENSE.
-- Taskpaper LPeg lexer

local lexer = lexer
local P, S = lpeg.P, lpeg.S

local lex = lexer.new(..., {lex_by_line = true})

-- Notes.
local delimiter = lpeg.B('    ') + lpeg.B('\t')
lex:add_rule('note', delimiter * lex:tag('note', lexer.to_eol(lexer.alnum)))

-- Tasks.
lex:add_rule('task', delimiter * lex:tag(lexer.LIST, '-'))

-- Projects.
lex:add_rule('project', lex:tag(lexer.HEADING,
	lexer.range(lexer.starts_line(lexer.alnum), ':') * lexer.newline))

-- Tags.
lex:add_rule('extended_tag', lex:tag(lexer.TAG .. '.extended', '@' * lexer.word * '(' *
	(lexer.word + lexer.digit + '-')^1 * ')'))
lex:add_rule('day_tag', lex:tag(lexer.TAG .. '.day', (P('@today') + '@tomorrow')))
lex:add_rule('overdue_tag', lex:tag(lexer.TAG .. '.overdue', '@overdue'))
lex:add_rule('plain_tag', lex:tag(lexer.TAG .. '.plain', '@' * lexer.word))

return lex