summaryrefslogtreecommitdiff
path: root/pygments/lexers/postgres.py
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2011-04-12 01:42:46 +0100
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2011-04-12 01:42:46 +0100
commit7843ef26e20b368eac1c12f9c6f6aadd59acab75 (patch)
treea2fbe540b3c29856d29452d0aa782d3c9f72573d /pygments/lexers/postgres.py
parentd4302474b65cd18f865a981ccd9483fed311ab5c (diff)
downloadpygments-7843ef26e20b368eac1c12f9c6f6aadd59acab75.tar.gz
Regex part of the psql lexer split from the Postgres SQL lexer
Diffstat (limited to 'pygments/lexers/postgres.py')
-rw-r--r--pygments/lexers/postgres.py38
1 files changed, 26 insertions, 12 deletions
diff --git a/pygments/lexers/postgres.py b/pygments/lexers/postgres.py
index 8aeab3b8..43d036ad 100644
--- a/pygments/lexers/postgres.py
+++ b/pygments/lexers/postgres.py
@@ -10,6 +10,7 @@
import re
import sys
+from copy import deepcopy
from pygments.lexer import Lexer, RegexLexer, include, bygroups, using, \
this, do_insertions
@@ -99,8 +100,6 @@ class PostgresLexer(RegexLexer):
(r'(?ms)(\$[^\$]*\$)(.*?)(\1)', language_callback),
(r'[a-zA-Z_][a-zA-Z0-9_]*', Name),
- # TODO: consider splitting the psql parser
- (r'\\[^\s]+', Keyword.Pseudo, 'psql-command'),
# psql variable in SQL
(r""":(['"]?)[a-z][a-z0-9_]*\b\1""", Name.Variable),
@@ -112,17 +111,32 @@ class PostgresLexer(RegexLexer):
(r'[^/\*]+', Comment.Multiline),
(r'[/*]', Comment.Multiline)
],
- 'psql-command': [
- (r'\n', Text, 'root'),
- (r'\s+', Text),
- (r'\\[^\s]+', Keyword.Pseudo),
- (r""":(['"]?)[a-z][a-z0-9_]*\b\1""", Name.Variable),
- (r"'(''|[^'])*'", String.Single),
- (r"`([^`])*`", String.Backtick),
- (r"[^\s]+", String.Symbol),
- ]
}
+
+class PsqlRegexLexer(PostgresLexer):
+ """
+ Extend the PostgresLexer adding support specific for psql commands.
+
+ This is not a complete psql lexer yet as it lacks prompt support
+ and output rendering.
+ """
+ name = 'PostgreSQL console - regexp based lexer'
+ aliases = [] # not public
+ tokens = deepcopy(PostgresLexer.tokens)
+ tokens['root'].append(
+ (r'\\[^\s]+', Keyword.Pseudo, 'psql-command'))
+ tokens['psql-command'] = [
+ (r'\n', Text, 'root'),
+ (r'\s+', Text),
+ (r'\\[^\s]+', Keyword.Pseudo),
+ (r""":(['"]?)[a-z][a-z0-9_]*\b\1""", Name.Variable),
+ (r"'(''|[^'])*'", String.Single),
+ (r"`([^`])*`", String.Backtick),
+ (r"[^\s]+", String.Symbol),
+ ]
+
+
re_prompt = re.compile(r'^.*?[=\-\(][#>]')
re_psql_command = re.compile(r'(\s*)(\\.+?)(\s+)$')
@@ -144,7 +158,7 @@ class PostgresConsoleLexer(Lexer):
mimetypes = ['text/x-postgresql-psql']
def get_tokens_unprocessed(self, data):
- sql = PostgresLexer(**self.options)
+ sql = PsqlRegexLexer(**self.options)
curcode = ''
insertions = []