diff options
author | gentoo90 <gentoo90@gmail.com> | 2012-11-24 23:24:08 +0200 |
---|---|---|
committer | gentoo90 <gentoo90@gmail.com> | 2012-11-24 23:24:08 +0200 |
commit | bd51b3c608b6cd7601fc0227a65185632fb94568 (patch) | |
tree | 64350a8d11a46bbb223629e19d81be9d0506be65 /pygments | |
parent | ac3a4fd843833d232eafab8e846d4540e425663d (diff) | |
download | pygments-bd51b3c608b6cd7601fc0227a65185632fb94568.tar.gz |
Fix RPMSpecLexer to fit Pygments code style
* Change state names to usual in Pygments lexers
* Fix aliases tuple in _mapping
* Use bygroups instead of new state where appropriate
Diffstat (limited to 'pygments')
-rw-r--r-- | pygments/lexers/_mapping.py | 2 | ||||
-rw-r--r-- | pygments/lexers/other.py | 47 |
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), |