diff options
| author | Matěj Cepl <mcepl@cepl.eu> | 2023-08-11 01:27:32 +0200 |
|---|---|---|
| committer | Randy Palamar <randy@rnpnr.xyz> | 2024-03-27 06:04:21 -0600 |
| commit | 4c4392d29df777ff702dfe99b4f3c23142976e05 (patch) | |
| tree | 5355324abe18952f7d19d6cfc5dbeb5d6cb72b84 /lua/lexers/diff.lua | |
| parent | 95bf9f59f8a9a37148bdc0787db378d62c7cd032 (diff) | |
| download | vis-4c4392d29df777ff702dfe99b4f3c23142976e05.tar.gz vis-4c4392d29df777ff702dfe99b4f3c23142976e05.tar.xz | |
update lexers to orbitalquark/scintillua@b789dde
Rather than cherry pick patches from after 6.2 we will just grab
everything as is.
Diffstat (limited to 'lua/lexers/diff.lua')
| -rw-r--r-- | lua/lexers/diff.lua | 30 |
1 files changed, 13 insertions, 17 deletions
diff --git a/lua/lexers/diff.lua b/lua/lexers/diff.lua index 4c87dc2..4f779bf 100644 --- a/lua/lexers/diff.lua +++ b/lua/lexers/diff.lua @@ -1,29 +1,25 @@ --- Copyright 2006-2022 Mitchell. See LICENSE. +-- Copyright 2006-2024 Mitchell. See LICENSE. -- Diff LPeg lexer. -local lexer = require('lexer') -local token, word_match = lexer.token, lexer.word_match +local lexer = lexer +local to_eol, starts_line = lexer.to_eol, lexer.starts_line local P, S = lpeg.P, lpeg.S -local lex = lexer.new('diff', {lex_by_line = true}) +local lex = lexer.new(..., {lex_by_line = true}) --- Text, separators, and file headers. -lex:add_rule('index', token(lexer.COMMENT, 'Index: ' * lexer.any^0 * -1)) -lex:add_rule('separator', token(lexer.COMMENT, ('---' + P('*')^4 + P('=')^1) * lexer.space^0 * -1)) -lex:add_rule('header', token('header', (P('*** ') + '--- ' + '+++ ') * lexer.any^1)) -lex:add_style('header', lexer.styles.comment) +-- Text, file headers, and separators. +lex:add_rule('index', lex:tag(lexer.COMMENT, to_eol(starts_line('Index: ')))) +lex:add_rule('header', lex:tag(lexer.HEADING, to_eol(starts_line(P('*** ') + '--- ' + '+++ ')))) +lex:add_rule('separator', lex:tag(lexer.COMMENT, to_eol(starts_line(P('---') + '****' + '=')))) -- Location. -lex:add_rule('location', token(lexer.NUMBER, ('@@' + lexer.dec_num + '****') * lexer.any^1)) +lex:add_rule('location', lex:tag(lexer.NUMBER, to_eol(starts_line('@@' + lexer.dec_num + '****')))) -- Additions, deletions, and changes. -lex:add_rule('addition', token('addition', S('>+') * lexer.any^0)) -lex:add_style('addition', {fore = lexer.colors.green}) -lex:add_rule('deletion', token('deletion', S('<-') * lexer.any^0)) -lex:add_style('deletion', {fore = lexer.colors.red}) -lex:add_rule('change', token('change', '!' * lexer.any^0)) -lex:add_style('change', {fore = lexer.colors.yellow}) +lex:add_rule('addition', lex:tag('addition', to_eol(starts_line(S('>+'))))) +lex:add_rule('deletion', lex:tag('deletion', to_eol(starts_line(S('<-'))))) +lex:add_rule('change', lex:tag('change', to_eol(starts_line('!')))) -lex:add_rule('any_line', token(lexer.DEFAULT, lexer.any^1)) +lex:add_rule('any_line', lex:tag(lexer.DEFAULT, lexer.to_eol())) return lex |
