summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhhsprings <xwhhsprings@gmail.com>2015-11-06 18:20:52 +0900
committerhhsprings <xwhhsprings@gmail.com>2015-11-06 18:20:52 +0900
commit5c7cc2962a7f37f92e5a680769639d983058a009 (patch)
tree95ab5f2d17b5fba2ec28575c2649104800070793
parent39b04c956deca69ff5befcfdcc76c5212f65d972 (diff)
downloadpygments-5c7cc2962a7f37f92e5a680769639d983058a009.tar.gz
* Add lexer for `pkg-config <http://www.freedesktop.org/wiki/Software/pkg-config/>`_
* Add lexer for `pacman.conf <https://www.archlinux.org/pacman/pacman.conf.5.html>`_.
-rw-r--r--pygments/lexers/_mapping.py2
-rw-r--r--pygments/lexers/configs_pkgmng.py129
-rw-r--r--tests/examplefiles/pacman.conf49
-rw-r--r--tests/examplefiles/pkgconfig_example.pc18
4 files changed, 198 insertions, 0 deletions
diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py
index af7eec36..ef0b2b9e 100644
--- a/pygments/lexers/_mapping.py
+++ b/pygments/lexers/_mapping.py
@@ -283,6 +283,7 @@ LEXERS = {
'OocLexer': ('pygments.lexers.ooc', 'Ooc', ('ooc',), ('*.ooc',), ('text/x-ooc',)),
'OpaLexer': ('pygments.lexers.ml', 'Opa', ('opa',), ('*.opa',), ('text/x-opa',)),
'OpenEdgeLexer': ('pygments.lexers.business', 'OpenEdge ABL', ('openedge', 'abl', 'progress'), ('*.p', '*.cls'), ('text/x-openedge', 'application/x-openedge')),
+ 'PacmanConfLexer': ('pygments.lexers.configs_pkgmng', 'PacmanConf', ('pacmanconf',), ('pacman.conf',), ()),
'PanLexer': ('pygments.lexers.dsls', 'Pan', ('pan',), ('*.pan',), ()),
'ParaSailLexer': ('pygments.lexers.parasail', 'ParaSail', ('parasail',), ('*.psi', '*.psl'), ('text/x-parasail',)),
'PawnLexer': ('pygments.lexers.pawn', 'Pawn', ('pawn',), ('*.p', '*.pwn', '*.inc'), ('text/x-pawn',)),
@@ -292,6 +293,7 @@ LEXERS = {
'PigLexer': ('pygments.lexers.jvm', 'Pig', ('pig',), ('*.pig',), ('text/x-pig',)),
'PikeLexer': ('pygments.lexers.c_like', 'Pike', ('pike',), ('*.pike', '*.pmod'), ('text/x-pike',)),
'PlPgsqlLexer': ('pygments.lexers.sql', 'PL/pgSQL', ('plpgsql',), (), ('text/x-plpgsql',)),
+ 'PkgConfigLexer': ('pygments.lexers.configs_pkgmng', 'PkgConfig', ('pkgconfig',), ('*.pc',), ()),
'PostScriptLexer': ('pygments.lexers.graphics', 'PostScript', ('postscript', 'postscr'), ('*.ps', '*.eps'), ('application/postscript',)),
'PostgresConsoleLexer': ('pygments.lexers.sql', 'PostgreSQL console (psql)', ('psql', 'postgresql-console', 'postgres-console'), (), ('text/x-postgresql-psql',)),
'PostgresLexer': ('pygments.lexers.sql', 'PostgreSQL SQL dialect', ('postgresql', 'postgres'), (), ('text/x-postgresql',)),
diff --git a/pygments/lexers/configs_pkgmng.py b/pygments/lexers/configs_pkgmng.py
new file mode 100644
index 00000000..18fdffbe
--- /dev/null
+++ b/pygments/lexers/configs_pkgmng.py
@@ -0,0 +1,129 @@
+# -*- coding: utf-8 -*-
+"""
+ pygments.lexers.configs_pkgmng
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ Lexers for package manager configuration file formats.
+
+ :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS.
+ :license: BSD, see LICENSE for details.
+"""
+
+import re
+
+from pygments.lexer import RegexLexer, bygroups, include, words
+from pygments.token import Text, Comment, Operator, Name, \
+ Punctuation, String, Keyword
+
+__all__ = ['PkgConfigLexer', 'PacmanConfLexer']
+
+
+class PkgConfigLexer(RegexLexer):
+ """
+ Lexer for `pkg-config
+ <http://www.freedesktop.org/wiki/Software/pkg-config/>`_
+ (see also `manual page <http://linux.die.net/man/1/pkg-config>`_).
+
+ .. versionadded:: 2.1
+ """
+
+ name = 'PkgConfig'
+ aliases = ['pkgconfig',]
+ filenames = ['*.pc',]
+ mimetypes = []
+
+ tokens = {
+ 'root': [
+ (r'#.*$', Comment.Single),
+
+ # variable definitions
+ (r'^(\w+)(=)', bygroups(Name.Attribute, Operator)),
+
+ # keyword lines
+ (r'^([\w\.]+)(:)',
+ bygroups(Name.Tag, Punctuation), 'spvalue'),
+
+ # variable references
+ include('interp'),
+
+ # fallback
+ (r'.', Text),
+ ],
+ 'interp': [
+ # you can escape literal "${" as "$${"
+ (r'\$\$\{', Text),
+
+ # variable references
+ (r'\$\{', String.Interpol, 'curly'),
+ ],
+ 'curly': [
+ (r'\}', String.Interpol, '#pop'),
+ (r'\w+', Name.Attribute),
+ ],
+ 'spvalue': [
+ include('interp'),
+
+ (r'#.*$', Comment.Single, '#pop'),
+ (r'\n', Text, '#pop'),
+
+ # fallback
+ (r'.', Text),
+ ],
+ }
+
+
+class PacmanConfLexer(RegexLexer):
+ """
+ Lexer for `pacman.conf
+ <https://www.archlinux.org/pacman/pacman.conf.5.html>`_.
+
+ Actually, IniLexer works almost fine for this format,
+ but it yield error token. It is because pacman.conf has
+ a form without assignment like:
+
+ UseSyslog
+ Color
+ TotalDownload
+ CheckSpace
+ VerbosePkgLists
+
+ These are flags to switch on.
+
+ .. versionadded:: 2.1
+ """
+
+ name = 'PacmanConf'
+ aliases = ['pacmanconf',]
+ filenames = ['pacman.conf',]
+ mimetypes = []
+
+ tokens = {
+ 'root': [
+ # comment
+ (r'#.*$', Comment.Single),
+
+ # section header
+ (r'^\s*\[.*?\]\s*$', Keyword),
+
+ # variable definitions
+ # (Leading space is allowed...)
+ (r'(\w+)(\s*)(=)',
+ bygroups(Name.Attribute, Text, Operator)),
+
+ # flags to on
+ (r'^(\s*)(\w+)(\s*)$',
+ bygroups(Text, Name.Attribute, Text)),
+
+ # built-in special values
+ (words((
+ '$repo', # repository
+ '$arch', # architecture
+ '%o', # outfile
+ '%u', # url
+ ), suffix=r'\b'),
+ Name.Variable),
+
+ # fallback
+ (r'.', Text),
+ ],
+ }
diff --git a/tests/examplefiles/pacman.conf b/tests/examplefiles/pacman.conf
new file mode 100644
index 00000000..78dbf5e1
--- /dev/null
+++ b/tests/examplefiles/pacman.conf
@@ -0,0 +1,49 @@
+#
+# /etc/pacman.conf
+#
+# This example file has no relation to `pacman.ijs`
+# but is of configuration of Arch Linux's package manager `pacman`.
+#
+
+#
+# GENERAL OPTIONS
+#
+[options]
+RootDir = /opt/local/site-private
+#DBPath = /var/lib/pacman/
+#CacheDir = /var/cache/pacman/pkg/
+LogFile = /opt/local/site-private/var/log/pacman.log
+#GPGDir = /etc/pacman.d/gnupg/
+HoldPkg = pacman
+#XferCommand = /usr/bin/curl -C - -f %u > %o
+XferCommand = /usr/local/bin/wget --passive-ftp -c -O %o %u
+#CleanMethod = KeepInstalled
+#UseDelta = 0.7
+Architecture = auto
+
+#IgnorePkg =
+#IgnoreGroup =
+
+NoUpgrade = etc/passwd etc/group etc/shadow
+NoUpgrade = etc/fstab
+#NoExtract =
+
+#UseSyslog
+Color
+#TotalDownload
+CheckSpace
+#VerbosePkgLists
+
+#SigLevel = Never
+SigLevel = Required DatabaseOptional
+LocalFileSigLevel = Optional
+RemoteFileSigLevel = Required
+
+Server = ftp://ftp9.yaphatchpotchgen.net/$repo/os/$arch
+
+[fubar32]
+Include = /etc/pacman.d/mirrorlist.fubar32 # comment is allowed here
+
+#[custom]
+#SigLevel = Optional TrustAll
+#Server = file:///home/custompkgs
diff --git a/tests/examplefiles/pkgconfig_example.pc b/tests/examplefiles/pkgconfig_example.pc
new file mode 100644
index 00000000..b7969bad
--- /dev/null
+++ b/tests/examplefiles/pkgconfig_example.pc
@@ -0,0 +1,18 @@
+# This is for a fictional package `yet another portable hatchpotch generator'.
+prefix=/usr/local/opt/site/private # define variable `prefix`
+exec_prefix=${prefix} # using variable reference
+libdir=${exec_prefix}/lib
+includedir=${prefix}/include
+just_for_test=$${this is not a part of variable reference} # escape with `$${`
+
+Name: YAPHatchPotchGen
+Description: Yet Another Portable HatchPotch GENerator.
+Version: 352.9.3
+URL: http://www9.yaphatchpotchgen.net # Don't access.
+Requires: piyohogelib-9.0 = 9.5.3
+Requires.private: nyorolib-3.0 = 3.0.9
+Conflicts: apiyohoge <= 8.3
+Libs: -L${libdir} -lyaphatchpotchgen-352.9 # using variable reference
+Libs.private: -ll -ly
+Cflags: -I${includedir}/piyohogelib-9.0 -I${libdir}/yaphatchpotchgen/include
+