Skip to content

Commit 62fed52

Browse files
committed
add git-commit message lexer & its file extension in detect
1 parent b74011a commit 62fed52

File tree

3 files changed

+61
-3
lines changed

3 files changed

+61
-3
lines changed

lexers/git-commit.lua

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
-- Copyright 2017-2025 Marc André Tanner. See LICENSE.
2+
-- git-rebase(1) LPeg lexer.
3+
4+
local lexer = lexer
5+
local P, R, S, Cp = lpeg.P, lpeg.R, lpeg.S, lpeg.Cp()
6+
7+
local lex = lexer.new(...)
8+
9+
-- Comments.
10+
lex:add_rule('comment', lex:tag(lexer.COMMENT, lexer.to_eol(lexer.starts_line('#'))))
11+
12+
-- Keywords.
13+
lex:add_rule('keyword', lex:tag(lexer.KEYWORD, lexer.starts_line(lex:word_match(lexer.KEYWORD))*':'))
14+
15+
local function zero(_, n)
16+
local fn, i = lexer.line_from_position, -1
17+
i = fn(n+1)
18+
return i <= 1
19+
end
20+
21+
local message = (((lpeg.Cmt(Cp, zero)) * ((((- S"\n")^-72) * S"\n") + ((P(1) - S"\n")^-71 * P(1)))))
22+
lex:add_rule('message', lex:tag(lexer.STRING, lexer.starts_line(message)))
23+
24+
-- Commit SHA1.
25+
local function patn(pat, min, max)
26+
return -pat^(max + 1) * pat^min
27+
end
28+
29+
lex:add_rule('hash', lex:tag(lexer.NUMBER, patn(R('09', 'af'), 7, 40)))
30+
31+
-- Word lists.
32+
lex:set_word_list(lexer.KEYWORD, [[
33+
Acked-by
34+
Co-authored-by
35+
Reported-and-tested-by
36+
Reported-by
37+
Reviewed-by
38+
Signed-off-by
39+
Suggested-by
40+
Tested-by
41+
To
42+
Cc
43+
From
44+
After
45+
Before
46+
Bluetooth
47+
Closes
48+
Code
49+
Documentation
50+
Fixes
51+
Input
52+
Note
53+
Oops
54+
Staging
55+
Summary
56+
Warning
57+
]])
58+
59+
return lex

lexers/git-rebase.lua

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
-- Copyright 2017-2025 Marc André Tanner. See LICENSE.
2-
-- git-rebase(1) LPeg lexer.
1+
-- git-rebase(1)
32

43
local lexer = lexer
54
local P, R = lpeg.P, lpeg.R

lexers/lexer.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -1640,7 +1640,7 @@ function M.detect(filename, line)
16401640
f90 = 'fortran', f95 = 'fortran', f03 = 'fortran', f08 = 'fortran', --
16411641
fstab = 'fstab', --
16421642
gd = 'gap', gi = 'gap', gap = 'gap', --
1643-
['git-rebase-todo'] = 'git-rebase' --
1643+
['git-rebase-todo'] = 'git-rebase', ['COMMIT_EDITMSG'] = 'git-commit', --
16441644
gmi = 'gemini', --
16451645
po = 'gettext', pot = 'gettext', --
16461646
feature = 'gherkin', --

0 commit comments

Comments
 (0)