summaryrefslogtreecommitdiff
path: root/pygments/lexers/postgres.py
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2011-04-12 11:13:52 +0100
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2011-04-12 11:13:52 +0100
commitfcba33489b3a1654e76c23d0f4798830788863af (patch)
treec871d66d5b694117d3673f2dca31b61bff2d8fee /pygments/lexers/postgres.py
parent11e7b64a90c769d9d6939b505afab780a2cef5c4 (diff)
downloadpygments-fcba33489b3a1654e76c23d0f4798830788863af.tar.gz
Adding a Pl/pgSQL lexer
Diffstat (limited to 'pygments/lexers/postgres.py')
-rw-r--r--pygments/lexers/postgres.py33
1 files changed, 30 insertions, 3 deletions
diff --git a/pygments/lexers/postgres.py b/pygments/lexers/postgres.py
index b4dc9df0..0e495786 100644
--- a/pygments/lexers/postgres.py
+++ b/pygments/lexers/postgres.py
@@ -19,10 +19,10 @@ from pygments.token import Error, Punctuation, Literal, Token, \
from pygments.lexers import get_lexer_by_name, ClassNotFound
from pygments.lexers._postgres_builtins import (
- KEYWORDS, DATATYPES, PSEUDO_TYPES)
+ KEYWORDS, DATATYPES, PSEUDO_TYPES, PLPGSQL_KEYWORDS)
-__all__ = [ 'PostgresLexer', 'PostgresConsoleLexer' ]
+__all__ = [ 'PostgresLexer', 'PlPgsqlLexer', 'PostgresConsoleLexer' ]
line_re = re.compile('.*?\n')
@@ -116,6 +116,34 @@ class PostgresLexer(RegexLexer):
}
+class PlPgsqlLexer(PostgresLexer):
+ """
+ Handle the extra syntax in Pl/pgSQL language.
+ """
+ name = 'PL/pgSQL'
+ aliases = ['plpgsql']
+ mimetypes = ['text/x-plpgsql']
+ tokens = deepcopy(PostgresLexer.tokens)
+
+ # extend the keywords list
+ for i, pattern in enumerate(tokens['root']):
+ if pattern[1] == Keyword:
+ tokens['root'][i] = (
+ r'(' + '|'.join(KEYWORDS + PLPGSQL_KEYWORDS) + r')\b',
+ Keyword)
+ del i
+ break
+ else:
+ assert 0, "SQL keywords not found"
+
+ tokens['root'][:0] = [
+ (r'\%[a-z][a-z0-9_]*\b', Name.Builtin), # actually, a datatype
+ (r':=', Operator),
+ (r'\<\<[a-z][a-z0-9_]*\>\>', Name.Label),
+ (r'\#[a-z][a-z0-9_]*\b', Keyword.Pseudo), # #variable_conflict
+ ]
+
+
class PsqlRegexLexer(PostgresLexer):
"""
Extend the PostgresLexer adding support specific for psql commands.
@@ -138,7 +166,6 @@ class PsqlRegexLexer(PostgresLexer):
(r"[^\s]+", String.Symbol),
]
-
re_prompt = re.compile(r'^.*?[=\-\(][#>]')
re_psql_command = re.compile(r'\s*\\')
re_end_command = re.compile(r';\s*(--.*?)?$')