summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgbrandl <devnull@localhost>2006-12-14 16:59:33 +0100
committergbrandl <devnull@localhost>2006-12-14 16:59:33 +0100
commit31a0d1e2adbbb6abb852ebc0ba3d926f8e6709f5 (patch)
treef91de73df0a1d8306468b9008fdd5971a8a615d9
parentc93caf9dec4ccdf4db2bb749bdc41f94a944b46c (diff)
downloadpygments-31a0d1e2adbbb6abb852ebc0ba3d926f8e6709f5.tar.gz
[svn] Add Bash lexer modified from Tim Hatch.
-rw-r--r--CHANGES2
-rw-r--r--TODO2
-rw-r--r--docs/src/lexers.txt11
-rw-r--r--pygments/lexers/_mapping.py1
-rw-r--r--pygments/lexers/other.py60
-rw-r--r--pygments/lexers/text.py2
6 files changed, 70 insertions, 8 deletions
diff --git a/CHANGES b/CHANGES
index 4296246d..3147f04c 100644
--- a/CHANGES
+++ b/CHANGES
@@ -5,7 +5,7 @@ Version 0.6
-----------
(released Dec XX, 2006)
-- Added Apache configuration lexer (thanks to Tim Hatch).
+- Added Bash and Apache configuration lexers (thanks to Tim Hatch).
- Improved guessing methods for various lexers.
diff --git a/TODO b/TODO
index b2dbcb25..d7ccf35e 100644
--- a/TODO
+++ b/TODO
@@ -24,11 +24,9 @@ for 0.6
- dhtml: overlays toggleable by javascript
- lexers:
- * bash
* haskell
* (Q)BASIC
* lisp
- * apacheconf
* python TBs
* ls -alG
* HTML with special formatting?
diff --git a/docs/src/lexers.txt b/docs/src/lexers.txt
index eb2edc4a..ff6754ba 100644
--- a/docs/src/lexers.txt
+++ b/docs/src/lexers.txt
@@ -586,6 +586,15 @@ Other languages
:Filename patterns: ``*.bf``, ``*.b``
+`BashLexer`
+
+ Lexer for (ba)sh shell scripts.
+
+ :Aliases: ``bash``, ``sh``
+ :Filename patterns: ``*.sh``
+ :Mimetypes: ``application/x-sh``, ``application/x-shellscript``
+
+
Text lexers
===========
@@ -644,7 +653,7 @@ Text lexers
format.
:Aliases: ``apacheconf``, ``aconf``
- :Filename patterns: None
+ :Filename patterns: ``.htaccess``, ``apache.conf``
Iterating over all lexers
diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py
index a81ea0c8..8d657fb9 100644
--- a/pygments/lexers/_mapping.py
+++ b/pygments/lexers/_mapping.py
@@ -15,6 +15,7 @@
LEXERS = {
'ApacheConfLexer': ('pygments.lexers.text', 'ApacheConf', ('apacheconf', 'aconf'), (), ()),
+ 'BashLexer': ('pygments.lexers.other', 'Bash', ('bash', 'sh'), ('*.sh',), ('application/x-sh', 'application/x-shellscript')),
'BooLexer': ('pygments.lexers.dotnet', 'Boo', ('boo',), ('*.boo',), ('text/x-boo',)),
'BrainfuckLexer': ('pygments.lexers.other', 'Brainfuck', ('brainfuck', 'bf'), ('*.bf', '*.b'), ()),
'CLexer': ('pygments.lexers.compiled', 'C', ('c',), ('*.c', '*.h'), ('text/x-chdr', 'text/x-csrc')),
diff --git a/pygments/lexers/other.py b/pygments/lexers/other.py
index 4c3b524f..0c54327c 100644
--- a/pygments/lexers/other.py
+++ b/pygments/lexers/other.py
@@ -5,18 +5,19 @@
Lexers for other languages: SQL, BrainFuck.
- :copyright: 2006 by Georg Brandl.
+ :copyright: 2006 by Georg Brandl, Tim Hatch <tim@timhatch.com>.
:license: BSD, see LICENSE for more details.
"""
import re
-from pygments.lexer import RegexLexer, include
+from pygments.lexer import RegexLexer, include, bygroups, using
from pygments.token import Error, \
Text, Comment, Operator, Keyword, Name, String, Number
+from pygments.util import shebang_matches
-__all__ = ['SqlLexer', 'BrainfuckLexer']
+__all__ = ['SqlLexer', 'BrainfuckLexer', 'BashLexer']
class SqlLexer(RegexLexer):
@@ -149,3 +150,56 @@ class BrainfuckLexer(RegexLexer):
include('common'),
]
}
+
+
+class BashLexer(RegexLexer):
+ """
+ Lex (ba)sh source files.
+ """
+ name = 'Bash'
+ aliases = ['bash', 'sh']
+ filenames = ['*.sh']
+ mimetypes = ['application/x-sh', 'application/x-shellscript']
+
+ # TODO: heredocs and perhaps some other niceties
+
+ tokens = {
+ 'root': [
+ (r'\b(if|fi|while|do|done|for|then|return|function|case|'
+ r'select|continue|until)\s*\b',
+ Keyword),
+ (r'\b(alias|bg|bind|break|builtin|caller|cd|command|compgen|'
+ r'complete|declare|dirs|disown|echo|enable|eval|exec|exit|'
+ r'export|false|fc|fg|getopts|hash|help|history|jobs|kill|let|'
+ r'local|logout|popd|printf|pushd|pwd|read|readonly|set|shift|'
+ r'shopt|source|suspend|test|time|times|trap|true|type|typeset|'
+ r'ulimit|umask|unalias|unset|wait)\s*\b',
+ Name.Builtin),
+ (r'#.*\n', Comment),
+ (r'(\b\w+\s*)(=)', bygroups(Name.Variable, Operator)),
+ (r'[\[\]{}\(\)=]+', Operator),
+ (r'\$\(', Keyword, 'paren'),
+ (r'\${', Keyword, 'curly'),
+ (r'`.+`', String),
+ (r'\d+(?= |\Z)', Number),
+ (r'\$#?(\w+|.)', Name.Variable),
+ (r'"(\\\\|\\[0-7]+|\\.|[^"])*"', String.Double),
+ (r"'(\\\\|\\[0-7]+|\\.|[^'])*'", String.Single),
+ (r'\s+', Text),
+ (r'[^=\s\n]+', Text),
+ ],
+ 'curly': [
+ (r'}', Keyword, '#pop'),
+ (r':-', Keyword),
+ (r'[^}:]+', Text),
+ (r':', Text),
+ ],
+ 'paren': [
+ (r'\)', Keyword, '#pop'),
+ (r'[^)]*', Text),
+ ],
+ }
+
+ def analyse_text(text):
+ return shebang_matches(text, r'(ba|z|)sh')
+
diff --git a/pygments/lexers/text.py b/pygments/lexers/text.py
index b67a82fd..e4623662 100644
--- a/pygments/lexers/text.py
+++ b/pygments/lexers/text.py
@@ -264,7 +264,7 @@ class ApacheConfLexer(RegexLexer):
"""
name = 'ApacheConf'
aliases = ['apacheconf', 'aconf']
- filenames = []
+ filenames = ['.htaccess', 'apache.conf']
tokens = {
'root': [