Commits

Daniele Varrazzo committed 37ec7e5

Added support for psql variables

Comments (0)

Files changed (2)

pygments/lexers/postgres.py

             (r"'(''|[^'])*'", String.Single),
             (r'"(""|[^"])*"', String.Name), # quoted identifier
             (r'[a-zA-Z_][a-zA-Z0-9_]*', Name),
-            (r'[;:()\[\],\.]', Punctuation),
-            # psql backslash command.
-            # This actually belongs to the console lexer,
+
+            # 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),
+
+            (r'[;:()\[\],\.]', Punctuation),
         ],
         'multiline-comments': [
             (r'/\*', Comment.Multiline, 'multiline-comments'),

tests/examplefiles/psql_session.txt

  x
 (1 row)
 
+piro=> \set foo 30;
+piro=> select * from test where foo < :foo;
+ foo | bar 
+-----+-----
+  10 | 
+  20 | 
+(2 rows)
+
+
 regression=# select (
 regression(# 1);
  ?column?