lexers/git-rebase: also highlight break command
[vis.git] / lua / lexers / git-rebase.lua
blob42c0e6c96bafe2858d6d50d4e1a9e5746e6fa5cf
1 -- Copyright 2017-2021 Marc André Tanner
2 -- git-rebase(1) LPeg lexer.
4 local l = require('lexer')
5 local token, word_match = l.token, l.word_match
6 local P, R = lpeg.P, lpeg.R
8 local M = {_NAME = 'git-rebase'}
10 -- Whitespace.
11 local ws = token(l.WHITESPACE, l.space^1)
13 -- Comments.
14 local comment = token(l.COMMENT, l.starts_line('#') * l.nonnewline^0)
16 -- Keywords.
17 local keywords = l.starts_line(word_match{
18 'p', 'pick',
19 'r', 'reword',
20 'e', 'edit',
21 's', 'squash',
22 'f', 'fixup',
23 'x', 'exec',
24 'd', 'drop',
25 'b', 'break',
26 'l', 'label',
27 't', 'reset',
28 'm', 'merge',
30 local keyword = token(l.KEYWORD, keywords)
32 -- Commit SHA1.
33 local function patn(pat, min, max)
34 return -pat^(max + 1) * pat^min
35 end
37 local commit = token(l.NUMBER, patn(R('09', 'af'), 7, 40))
39 local message = token(l.STRING, l.nonnewline^1)
41 M._rules = {
42 {'whitespace', ws},
43 {'comment', comment},
44 {'keyword', keyword},
45 {'commit', commit},
46 {'message', message},
49 M._LEXBYLINE = true
51 return M