summaryrefslogtreecommitdiff
path: root/pygments/lexers/postgres.py
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2011-04-04 12:39:06 +0100
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2011-04-04 12:39:06 +0100
commit98829589e3f9d4895c71ac1172a385278f61cdfa (patch)
tree1ed33e8ceb00a914177d3b91a18146e6a2c08ea9 /pygments/lexers/postgres.py
parent36aae230c886fb0b2e5b8c79aec03cee0c40256a (diff)
downloadpygments-98829589e3f9d4895c71ac1172a385278f61cdfa.tar.gz
Better psql commands parser
Recognize strings and quoted variables. Handled as a separate state.
Diffstat (limited to 'pygments/lexers/postgres.py')
-rw-r--r--pygments/lexers/postgres.py17
1 files changed, 12 insertions, 5 deletions
diff --git a/pygments/lexers/postgres.py b/pygments/lexers/postgres.py
index 8b584811..ab797f2b 100644
--- a/pygments/lexers/postgres.py
+++ b/pygments/lexers/postgres.py
@@ -51,11 +51,10 @@ class PostgresLexer(RegexLexer):
(r'"(""|[^"])*"', String.Name), # quoted identifier
(r'[a-zA-Z_][a-zA-Z0-9_]*', Name),
- # psql backslash command and variable
- # These actually belongs to the console lexer,
- # but putting it here makes things easier.
- (r'\\.*?\n', Name), # TODO: what is a good token?
- (r':[a-z][a-z0-9_]*\b', Name.Variable),
+ # TODO: consider splitting the regex parser
+ (r'\\[^\s]+', Keyword.Pseudo, 'psql-command'),
+ # psql variable in SQL
+ (r""":(['"]?)[a-z][a-z0-9_]*\b\1""", Name.Variable),
(r'[;:()\[\],\.]', Punctuation),
],
@@ -64,6 +63,14 @@ class PostgresLexer(RegexLexer):
(r'\*/', Comment.Multiline, '#pop'),
(r'[^/\*]+', Comment.Multiline),
(r'[/*]', Comment.Multiline)
+ ],
+ 'psql-command': [
+ (r'\n', Text, 'root'),
+ (r'\s+', Text),
+ (r""":(['"]?)[a-z][a-z0-9_]*\b\1""", Name.Variable),
+ (r"'(''|[^'])*'", String.Single),
+ (r"`([^`])*`", String.Backtick),
+ (r"[^\s]+", String.Symbol),
]
}