diff options
author | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2011-04-04 12:39:06 +0100 |
---|---|---|
committer | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2011-04-04 12:39:06 +0100 |
commit | 98829589e3f9d4895c71ac1172a385278f61cdfa (patch) | |
tree | 1ed33e8ceb00a914177d3b91a18146e6a2c08ea9 /pygments/lexers/postgres.py | |
parent | 36aae230c886fb0b2e5b8c79aec03cee0c40256a (diff) | |
download | pygments-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.py | 17 |
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), ] } |