Skip to content

Commit 1037e26

Browse files
committed
Optimize Syslog date rule using keywords in place of combinations
The previous rule used combinations of Day and Month three letter terms, and was taking up about 30% of the syntax processing time. The new methods using keywords has the side effect of highlighting the three letter identifies in the whole file (they should be reasonably rare outside of dates, however) but is much faster
1 parent 5ce7cb9 commit 1037e26

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

syntax/log.vim

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ syn region logString start=/'\(s \|t \| \w\)\@!/ end=/'/ end=/$/ end=/s / s
4343
syn match logDate '\d\{2,4}[-\/]\(\d\{2}\|Jan\|Feb\|Mar\|Apr\|May\|Jun\|Jul\|Aug\|Sep\|Oct\|Nov\|Dec\)[-\/]\d\{2,4}T\?'
4444
" Matches 8 digit numbers at start of line starting with 20
4545
syn match logDate '^20\d\{6}'
46-
" Matches Fri Jan 09 or Feb 11 or Apr 3
47-
syn match logDate '\(\(Mon\|Tue\|Wed\|Thu\|Fri\|Sat\|Sun\) \)\?\(Jan\|Feb\|Mar\|Apr\|May\|Jun\|Jul\|Aug\|Sep\|Oct\|Nov\|Dec\) [0-9 ]\d'
46+
" Matches Fri Jan 09 or Feb 11 or Apr 3 or Sun 3
47+
syn keyword logDate Mon Tue Wed Thu Fri Sat Sun Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec nextgroup=logDateDay
48+
syn match logDateDay '\s\{1,2}\d\{1,2}' contained
4849

4950
" Matches 12:09:38 or 00:03:38.129Z or 01:32:12.102938 +0700
5051
syn match logTime '\d\{2}:\d\{2}:\d\{2}\(\.\d\{2,6}\)\?\(\s\?[-+]\d\{2,4}\|Z\)\?\>' nextgroup=logTimeZone,logSysColumns skipwhite
@@ -112,6 +113,7 @@ hi def link logNull Constant
112113
hi def link logString String
113114

114115
hi def link logDate Identifier
116+
hi def link logDateDay Identifier
115117
hi def link logTime Function
116118
hi def link logTimeZone Identifier
117119

0 commit comments

Comments
 (0)