ui: fall back to xterm-256color if term initialization fails
[vis.git] / lexers / diff.lua
blob24f7ff20e5dbe39d843542e2c0c01f76683f0352
1 -- Copyright 2006-2015 Mitchell mitchell.att.foicica.com. See LICENSE.
2 -- Diff LPeg lexer.
4 local l = require('lexer')
5 local token, word_match = l.token, l.word_match
6 local P, R, S = lpeg.P, lpeg.R, lpeg.S
8 local M = {_NAME = 'diff'}
10 -- Text, separators, and file headers.
11 local index = token(l.COMMENT, 'Index: ' * l.any^0 * P(-1))
12 local separator = token(l.COMMENT, ('---' + P('*')^4 + P('=')^1) * l.space^0 *
13 -1)
14 local header = token('header', (P('*** ') + '--- ' + '+++ ') * l.any^1)
16 -- Location.
17 local location = token(l.NUMBER, ('@@' + l.digit^1 + '****') * l.any^1)
19 -- Additions, deletions, and changes.
20 local addition = token('addition', S('>+') * l.any^0)
21 local deletion = token('deletion', S('<-') * l.any^0)
22 local change = token('change', '! ' * l.any^0)
24 M._rules = {
25 {'index', index},
26 {'separator', separator},
27 {'header', header},
28 {'location', location},
29 {'addition', addition},
30 {'deletion', deletion},
31 {'change', change},
32 {'any_line', token('default', l.any^1)},
35 M._tokenstyles = {
36 header = l.STYLE_COMMENT,
37 addition = 'fore:green',
38 deletion = 'fore:red',
39 change = 'fore:yellow',
42 M._LEXBYLINE = true
44 return M