summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorthatch <devnull@localhost>2008-07-23 21:44:57 -0700
committerthatch <devnull@localhost>2008-07-23 21:44:57 -0700
commit0f3311731906be441b7c149a91a5cfe42eb0cc03 (patch)
tree47a4d5151db56091ce8632fe4519aa49505cc1b8
parent3f89e1fde065a554307f89cf185d602cf8fd12fb (diff)
downloadpygments-0f3311731906be441b7c149a91a5cfe42eb0cc03.tar.gz
Add lexer for Nginx config files.
-rw-r--r--pygments/lexers/_mapping.py1
-rw-r--r--pygments/lexers/text.py46
-rw-r--r--tests/examplefiles/nginx_nginx.conf118
3 files changed, 164 insertions, 1 deletions
diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py
index 9d5a1024..adb4f626 100644
--- a/pygments/lexers/_mapping.py
+++ b/pygments/lexers/_mapping.py
@@ -93,6 +93,7 @@ LEXERS = {
'MyghtyLexer': ('pygments.lexers.templates', 'Myghty', ('myghty',), ('*.myt', 'autodelegate'), ('application/x-myghty',)),
'MyghtyXmlLexer': ('pygments.lexers.templates', 'XML+Myghty', ('xml+myghty',), (), ('application/xml+myghty',)),
'NasmLexer': ('pygments.lexers.asm', 'NASM', ('nasm',), ('*.asm',), ('text/x-nasm',)),
+ 'NginxConfLexer': ('pygments.lexers.text', 'Nginx configuration file', ('nginx',), (), ('text/x-nginx-conf',)),
'NumPyLexer': ('pygments.lexers.math', 'NumPy', ('numpy',), ('*.py', '*.pyw', '*.sc', 'SConstruct', 'SConscript'), ()),
'ObjdumpLexer': ('pygments.lexers.asm', 'objdump', ('objdump',), ('*.objdump',), ('text/x-objdump',)),
'ObjectiveCLexer': ('pygments.lexers.compiled', 'Objective-C', ('objective-c', 'objectivec', 'obj-c', 'objc'), ('*.m',), ('text/x-objective-c',)),
diff --git a/pygments/lexers/text.py b/pygments/lexers/text.py
index e8e31b3b..4c27161f 100644
--- a/pygments/lexers/text.py
+++ b/pygments/lexers/text.py
@@ -36,7 +36,7 @@ __all__ = ['IniLexer', 'SourcesListLexer', 'BaseMakefileLexer',
'GroffLexer', 'ApacheConfLexer', 'BBCodeLexer', 'MoinWikiLexer',
'RstLexer', 'VimLexer', 'GettextLexer', 'SquidConfLexer',
'DebianControlLexer', 'DarcsPatchLexer', 'YamlLexer',
- 'LighttpdConfLexer']
+ 'LighttpdConfLexer', 'NginxConfLexer']
class IniLexer(RegexLexer):
@@ -1418,3 +1418,47 @@ class LighttpdConfLexer(RegexLexer):
],
}
+
+class NginxConfLexer(RegexLexer):
+ """
+ Lexer for `Nginx <http://nginx.net/>`_ configuration files.
+
+ *New in Pygments 0.11*
+ """
+ name = 'Nginx configuration file'
+ aliases = ['nginx']
+ filenames = []
+ mimetypes = ['text/x-nginx-conf']
+
+ tokens = {
+ 'root': [
+ (r'(include)(\s+)([^\s;]+)', bygroups(Keyword, Text, Name)),
+ (r'[^\s;#]+', Keyword, 'stmt'),
+ include('base'),
+ ],
+ 'block': [
+ (r'}', Punctuation, '#pop:2'),
+ (r'[^\s;#]+', Keyword.Namespace, 'stmt'),
+ include('base'),
+ ],
+ 'stmt': [
+ (r'{', Punctuation, 'block'),
+ (r';', Punctuation, '#pop'),
+ include('base'),
+ ],
+ 'base': [
+ (r'#.*\n', Comment.Single),
+ (r'on|off', Name.Constant),
+ (r'\$[^\s;#]+', Name.Variable),
+ (r'([a-z0-9.-]+)(:)([0-9]+)',
+ bygroups(Name, Punctuation, Number.Integer)),
+ (r'[a-z-]+/[a-z-]+', Name), # mimetype
+ #(r'[a-zA-Z._-]+', Keyword),
+ (r'[0-9]+[km]?\b', Number.Integer),
+ (r'(~)(\s*)([^\s{]+)', bygroups(Punctuation, Text, String.Regex)),
+ (r'[:=~]', Punctuation),
+ (r'[^\s;#{}$]+', String), # catch all
+ (r'/[^\s;#]*', Name), # pathname
+ (r'\s+', Text),
+ ],
+ }
diff --git a/tests/examplefiles/nginx_nginx.conf b/tests/examplefiles/nginx_nginx.conf
new file mode 100644
index 00000000..9dcdc8ab
--- /dev/null
+++ b/tests/examplefiles/nginx_nginx.conf
@@ -0,0 +1,118 @@
+
+#user nobody;
+worker_processes 1;
+
+#error_log logs/error.log;
+#error_log logs/error.log notice;
+#error_log logs/error.log info;
+
+#pid logs/nginx.pid;
+
+
+events {
+ worker_connections 1024;
+}
+
+
+http {
+ include mime.types;
+ default_type application/octet-stream;
+
+ log_format main '$remote_addr - $remote_user [$time_local] $request '
+ '"$status" $body_bytes_sent "$http_referer" '
+ '"$http_user_agent" "$http_x_forwarded_for"';
+
+ #access_log logs/access.log main;
+
+ sendfile on;
+ #tcp_nopush on;
+
+ #keepalive_timeout 0;
+ keepalive_timeout 65;
+
+ #gzip on;
+
+ server {
+ listen 80;
+ server_name localhost;
+
+ charset koi8-r;
+
+ #access_log logs/host.access.log main;
+
+ location / {
+ root html;
+ index index.html index.htm;
+ }
+
+ #error_page 404 /404.html;
+
+ # redirect server error pages to the static page /50x.html
+ #
+ error_page 500 502 503 504 /50x.html;
+ location = /50x.html {
+ root html;
+ }
+
+ # proxy the PHP scripts to Apache listening on 127.0.0.1:80
+ #
+ location ~ \.php$ {
+ proxy_pass http://127.0.0.1;
+ }
+
+ # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
+ #
+ location ~ \.php$ {
+ root html;
+ fastcgi_pass 127.0.0.1:9000;
+ fastcgi_index index.php;
+ fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
+ include fastcgi_params;
+ }
+
+ # deny access to .htaccess files, if Apache's document root
+ # concurs with nginx's one
+ #
+ location ~ /\.ht {
+ deny all;
+ }
+ }
+
+
+ # another virtual host using mix of IP-, name-, and port-based configuration
+ #
+ server {
+ listen 8000;
+ listen somename:8080;
+ server_name somename alias another.alias;
+
+ location / {
+ root html;
+ index index.html index.htm;
+ }
+ }
+
+
+ # HTTPS server
+ #
+ server {
+ listen 443;
+ server_name localhost;
+
+ ssl on;
+ ssl_certificate cert.pem;
+ ssl_certificate_key cert.key;
+
+ ssl_session_timeout 5m;
+
+ ssl_protocols SSLv2 SSLv3 TLSv1;
+ ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
+ ssl_prefer_server_ciphers on;
+
+ location / {
+ root html;
+ index index.html index.htm;
+ }
+ }
+
+}