summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pygments/lexers/_mapping.py2
-rw-r--r--pygments/lexers/other.py47
2 files changed, 20 insertions, 29 deletions
diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py
index 1581c74e..ac6819ee 100644
--- a/pygments/lexers/_mapping.py
+++ b/pygments/lexers/_mapping.py
@@ -225,7 +225,7 @@ LEXERS = {
'RebolLexer': ('pygments.lexers.other', 'REBOL', ('rebol',), ('*.r', '*.r3'), ('text/x-rebol',)),
'RedcodeLexer': ('pygments.lexers.other', 'Redcode', ('redcode',), ('*.cw',), ()),
'RhtmlLexer': ('pygments.lexers.templates', 'RHTML', ('rhtml', 'html+erb', 'html+ruby'), ('*.rhtml',), ('text/html+ruby',)),
- 'RPMSpecLexer': ('pygments.lexers.other', 'RPMSpec', ('spec'), ('*.spec',), ('text/x-rpm-spec',)),
+ 'RPMSpecLexer': ('pygments.lexers.other', 'RPMSpec', ('spec',), ('*.spec',), ('text/x-rpm-spec',)),
'RstLexer': ('pygments.lexers.text', 'reStructuredText', ('rst', 'rest', 'restructuredtext'), ('*.rst', '*.rest'), ('text/x-rst', 'text/prs.fallenstein.rst')),
'RubyConsoleLexer': ('pygments.lexers.agile', 'Ruby irb session', ('rbcon', 'irb'), (), ('text/x-ruby-shellsession',)),
'RubyLexer': ('pygments.lexers.agile', 'Ruby', ('rb', 'ruby', 'duby'), ('*.rb', '*.rbw', 'Rakefile', '*.rake', '*.gemspec', '*.rbx', '*.duby'), ('text/x-ruby', 'application/x-ruby')),
diff --git a/pygments/lexers/other.py b/pygments/lexers/other.py
index df5570e1..7c8bf7e2 100644
--- a/pygments/lexers/other.py
+++ b/pygments/lexers/other.py
@@ -3172,62 +3172,53 @@ class RPMSpecLexer(RegexLexer):
filenames = ['*.spec']
mimetypes = ['text/x-rpm-spec']
+ _directives = '(?:package|prep|build|install|clean|check|pre[a-z]*|post[a-z]*|trigger[a-z]*|files)'
+
tokens = {
'root': [
(r'#.*\n', Comment),
- include('rpm'),
- ],
- 'header': [
- include('rpm'),
- (r'\n', Text, '#pop'),
- (r'.', Text),
+ include('basic'),
],
'description': [
- (r'^%(?:package|prep|build|install|clean|'
- r'check|pre[a-z]*|post[a-z]*|trigger[a-z]*|files)',
- Name.Decorator, '#pop', 'header'),
+ (r'^(%' + _directives + ')(.*)$', bygroups(Name.Decorator, Text), '#pop'),
(r'\n', Text),
(r'.', Text),
],
'changelog': [
(r'\*.*\n', Generic.Subheading),
- (r'^%(?:package|prep|build|install|clean|'
- r'check|pre[a-z]*|post[a-z]*|trigger[a-z]*|files)',
- Name.Decorator, '#pop', 'header'),
+ (r'^(%' + _directives + ')(.*)$', bygroups(Name.Decorator, Text), '#pop'),
(r'\n', Text),
(r'.', Text),
],
- 'str_double': [
+ 'string': [
(r'"', String.Double, '#pop'),
(r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape),
- include('resolvable'),
+ include('interpol'),
(r'.', String.Double),
],
- 'rpm': [
- include('preproc'),
- (r'(?i)^(?:Name|Version|Release|Epoch|Summary|Group|License|Packager|Vendor|Icon|URL|'
+ 'basic': [
+ include('macro'),
+ (r'(?i)^(Name|Version|Release|Epoch|Summary|Group|License|Packager|Vendor|Icon|URL|'
r'Distribution|Prefix|Patch[0-9]*|Source[0-9]*|Requires\(?[a-z]*\)?|[A-Za-z]+Req|'
- r'Obsoletes|Provides|Conflicts|Build[A-Za-z]+|[A-Za-z]+Arch|Auto[A-Za-z]+):\s*',
- Generic.Heading, 'header'),
+ r'Obsoletes|Provides|Conflicts|Build[A-Za-z]+|[A-Za-z]+Arch|Auto[A-Za-z]+)(:)(.*)$',
+ bygroups(Generic.Heading, Punctuation, using(this))),
(r'^%description', Name.Decorator, 'description'),
(r'^%changelog', Name.Decorator, 'changelog'),
- (r'^%(package|prep|build|install|clean|'
- r'check|pre[a-z]*|post[a-z]*|trigger[a-z]*|files)',
- Name.Decorator, 'header'),
- (r'%(?:attr|defattr|dir|doc(?:dir)?|setup|config(?:ure)?|'
+ (r'^(%' + _directives + ')(.*)$', bygroups(Name.Decorator, Text)),
+ (r'%(attr|defattr|dir|doc(?:dir)?|setup|config(?:ure)?|'
r'make(?:install)|ghost|patch[0-9]+|find_lang|exclude|verify)',
Keyword),
- include('resolvable'),
+ include('interpol'),
(r"'.*'", String.Single),
- (r'"', String.Double, 'str_double'),
+ (r'"', String.Double, 'string'),
(r'.', Text),
],
- 'preproc': [
+ 'macro': [
(r'%define.*\n', Comment.Preproc),
(r'%\{\!\?.*%define.*\}', Comment.Preproc),
- (r'%(if(?:n?arch)?|else(?:if)?|endif)', Comment.Preproc, 'header'),
+ (r'(%(?:if(?:n?arch)?|else(?:if)?|endif))(.*)$', bygroups(Comment.Preproc, Text)),
],
- 'resolvable': [
+ 'interpol': [
(r'%\{?__[a-z_]+\}?', Name.Function),
(r'%\{?_([a-z_]+dir|[a-z_]+path|prefix)\}?', Keyword.Pseudo),
(r'%\{\?[A-Za-z0-9_]+\}', Name.Variable),