-
Notifications
You must be signed in to change notification settings - Fork 0
/
klog.sublime-syntax
122 lines (103 loc) · 3.4 KB
/
klog.sublime-syntax
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
%YAML 1.2
# See http://www.sublimetext.com/docs/syntax.html
---
name: klog
file_extensions: [klg]
scope: source.klog
variables:
date: '\d{4}[-/]\d{2}[-/]\d{2}'
blankline: '^\s*$'
duration_value: '(\d+h\d+m|\d+h|\d+m)'
duration_positive: '\+?{{duration_value}}'
duration_negative: '-{{duration_value}}'
should_total: '\([+-]?{{duration_value}}!\)'
time: '\d{1,2}:\d{2}([ap]m)?'
shifted_time: '({{time}}>|{{time}}|\<{{time}})'
range: '{{shifted_time}} ?- ?{{shifted_time}}'
open_range: '{{shifted_time}} ?- ?\?+'
indentation: '(\t| | | )'
contexts:
# For every scope, there must be two values assigned:
# - One klog-specific scope, that’s unused by this
# package, but that allows the user to setup overrides
# conveniently.
# - One generic fallback scope, that will likely work
# out of the box for most color schemes.
main:
- include: record
record:
# A record must start with a date.
- match: '^({{date}})'
scope: markup.underline.klog markup.other.date.klog
push:
# Then, there may follow a should total on the same line.
- match: '(\s+({{should_total}}))?\s*'
captures:
2: constant.numeric.klog markup.other.should_total.klog
# End of headline.
- match: '$'
push: record_summary
record_summary:
# Exit on blank line.
- match: '{{blankline}}'
pop: 99999
# A record summary line cannot start with whitespace.
- match: '^(?=[^\s])'
push:
- meta_scope: comment.klog markup.other.summary.klog
- include: tag
- match: '^(?=\s)'
pop: 1
# The first indented line begins the entries section.
# It must be indented exactly once.
- match: '^(?={{indentation}}[^\s])'
push: entries
# Anything else would be illegal.
- match: '^.*'
scope: invalid.klog
pop: 1 # Continue parsing, though.
entries:
# Exit on blank line.
- match: '{{blankline}}'
pop: 99999
# When the line is indented, it’s an entry.
- match: '^{{indentation}}({{duration_positive}})(?=\s|$)'
captures:
2: markup.inserted.klog markup.other.duration_positive.klog
push: entry_summary
- match: '^{{indentation}}({{duration_negative}})(?=\s|$)'
captures:
2: markup.deleted.klog markup.other.duration_negative.klog
push: entry_summary
- match: '^{{indentation}}({{range}})(?=\s|$)'
captures:
2: variable.function.klog markup.other.range.klog
push: entry_summary
- match: '^{{indentation}}({{open_range}})(?=\s|$)'
captures:
2: variable.function.klog markup.other.open_range.klog
push: entry_summary
# Error if next line doesn’t start with whitespace.
- match: '^[^\s].*'
scope: invalid.klog
pop: 99999
entry_summary:
# Parse the remainder of the first line, and continue on the next.
- meta_scope: comment.klog markup.other.summary.klog
- include: tag
# Exit on blank line.
- match: '{{blankline}}'
pop: 99999
# Exit if next line is indented just once.
# It’s important to work with the `\1` matcher, otherwise
# it wouldn’t handle the indendation style correctly.
# `\1` can only be used in conjunction with `pop`, not `push`.
- match: '^(?=\1[^\s])'
pop: 1
# Error if next line doesn’t start with whitespace.
- match: '^[^\s].*'
scope: invalid.klog
pop: 99999
tag:
- match: (((?<=[\s\p{P}])|(?<=^))\#[\p{L}\d_-]+)(=((\'.*?\')|(".*?")|([\p{L}\d_-]+)))?
scope: markup.raw.inline markup.other.summary.tag.klog