1
Jianw
9 天以前 70f29da38121b9a467841253e3268feb5df02902
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
-- Copyright (c) 2016-2018 Larry Hynes. See License.txt.
-- Taskpaper LPeg lexer
 
local lexer = require('lexer')
local token = lexer.token
local P, R, S = lpeg.P, lpeg.R, lpeg.S
 
local M = {_NAME = 'taskpaper'}
 
local delimiter = P('    ') + P('\t')
 
-- Whitespace
local ws = token(lexer.WHITESPACE, lexer.space^1)
 
-- Tags
local day_tag = token('day_tag', (P('@today') + P('@tomorrow')))
 
local overdue_tag = token('overdue_tag', P('@overdue'))
 
local plain_tag = token('plain_tag', P('@') * lexer.word)
 
local extended_tag = token('extended_tag',
                           P('@') * lexer.word * P('(') *
                           (lexer.word + R('09') + P('-'))^1 * P(')'))
 
-- Projects
local project = token('project',
                      lexer.nested_pair(lexer.starts_line(lexer.alnum), ':') *
                      lexer.newline)
 
-- Notes
local note = token('note', delimiter^1 * lexer.alnum * lexer.nonnewline^0)
 
-- Tasks
local task = token('task', delimiter^1 * P('-') + lexer.newline)
 
M._rules = {
  {'note', note},
  {'task', task},
  {'project', project},
  {'extended_tag', extended_tag},
  {'day_tag', day_tag},
  {'overdue_tag', overdue_tag},
  {'plain_tag', plain_tag},
  {'whitespace', ws},
}
 
M._tokenstyles = {
  note = lexer.STYLE_CONSTANT,
  task = lexer.STYLE_FUNCTION,
  project = lexer.STYLE_TAG,
  extended_tag = lexer.STYLE_COMMENT,
  day_tag = lexer.STYLE_CLASS,
  overdue_tag = lexer.STYLE_PREPROCESSOR,
  plain_tag = lexer.STYLE_COMMENT,
}
 
M._LEXBYLINE = true
 
return M