Skip to content

Commit

Permalink
update rpmspec lexer, to follow modern standard
Browse files Browse the repository at this point in the history
References: orbitalquark#76
  • Loading branch information
mcepl committed Jan 28, 2025
1 parent e5d9b6a commit 61e17fd
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions lexers/rpmspec.lua
Original file line number Diff line number Diff line change
@@ -1,29 +1,47 @@
-- Copyright 2022-2025 Matej Cepl mcepl.att.cepl.eu. See LICENSE.

local lexer = lexer
local token, word_match = lexer.token, lexer.word_match
local P, S = lpeg.P, lpeg.S
local C, P, R, S = lpeg.C, lpeg.P, lpeg.R, lpeg.S

local lex = lexer.new(...)

-- Whitespace.
lex:add_rule('whitespace', lex:tag(lexer.WHITESPACE, lexer.space^1))

-- Comments.
lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('#')))
lex:add_rule('comment', lex:tag(lexer.COMMENT, lexer.to_eol('#')))

-- Numbers (including versions)
lex:add_rule('number', lex:tag(lexer.NUMBER, lpeg.B(lpeg.space) *
(lexer.number * (lexer.number +S('.+~'))^0)))

-- Operators
lex:add_rule('operator', lex:tag(lexer.OPERATOR, S('&<>=|')))

-- Strings.
lex:add_rule('string', token(lexer.STRING, lexer.range('"')))
lex:add_rule('string', lex:tag(lexer.STRING, lexer.range('"')))

-- Keywords.
lex:add_rule('keyword', token(lexer.KEYWORD, word_match{
lex:add_rule('keyword', lex:tag(lexer.KEYWORD, (lex:word_match(lexer.KEYWORD) +
(P('Patch') + P('Source')) * R('09')^0) * ':'))
lex:set_word_list(lexer.KEYWORD, {
'Prereq', 'Summary', 'Name', 'Version', 'Packager', 'Requires', 'Recommends', 'Suggests',
'Supplements', 'Enhances', 'Icon', 'URL', 'Source', 'Patch', 'Prefix', 'Packager', 'Group',
'License', 'Release', 'BuildRoot', 'Distribution', 'Vendor', 'Provides', 'ExclusiveArch',
'ExcludeArch', 'ExclusiveOS', 'Obsoletes', 'BuildArch', 'BuildArchitectures', 'BuildRequires',
'BuildConflicts', 'BuildPreReq', 'Conflicts', 'AutoRequires', 'AutoReq', 'AutoReqProv',
'AutoProv', 'Epoch'
}))
})

-- Macros
lex:add_rule('command', token(lexer.FUNCTION, '%' * lexer.word))
lex:add_rule('command', lex:tag(lexer.FUNCTION,
lexer.range(S('%$')^1 * S('{')^0 * ((lexer.alnum + S('_?'))^0), S('}')^0)))

-- Constants
lex:add_rule('constant', lex:tag(lexer.CONSTANT, lex:word_match(lexer.CONSTANT)))
lex:set_word_list(lexer.CONSTANT, {
'rhel', 'fedora', 'suse_version', 'sle_version', 'x86_64'
})

lexer.property['scintillua.comment'] = '#'

Expand Down

0 comments on commit 61e17fd

Please sign in to comment.