Daniele Varrazzo avatar Daniele Varrazzo committed d15804d

Added list of pseudo-datatypes to PostgreSQL lexer

Comments (0)

Files changed (2)

pygments/lexers/_postgres_builtins.py

 DATATYPES_URL = SOURCE_URL + '/doc/src/sgml/datatype.sgml'
 
 def update_myself():
-    datatypes = parse_datatypes(fetch(DATATYPES_URL))
+    data_file = list(fetch(DATATYPES_URL))
+    datatypes = parse_datatypes(data_file)
+    pseudos = parse_pseudos(data_file)
+
     keywords = parse_keywords(fetch(KEYWORDS_URL))
     update_consts(__file__, 'DATATYPES', datatypes)
+    update_consts(__file__, 'PSEUDO_TYPES', pseudos)
     update_consts(__file__, 'KEYWORDS', keywords)
 
 def parse_keywords(f):
     dt.sort()
     return dt
 
+def parse_pseudos(f):
+    dt = []
+    re_start = re.compile(r'\s*<table id="datatype-pseudotypes-table">')
+    re_entry = re.compile(r'\s*<entry><type>([^<]+)</></entry>')
+    re_end = re.compile(r'\s*</table>')
+
+    f = iter(f)
+    for line in f:
+        if re_start.match(line) is not None:
+            break
+    else:
+        raise ValueError('pseudo datatypes table not found')
+
+    for line in f:
+        m = re_entry.match(line)
+        if m is not None:
+            dt.append(m.group(1))
+
+        if re_end.match(line) is not None:
+            break
+    else:
+        raise ValueError('end of pseudo datatypes table not found')
+
+    if not dt:
+        raise ValueError('pseudo datatypes not found')
+
+    return dt
+
 def fetch(url):
     return urllib2.urlopen(url)
 
     'varbit', 'varchar', 'with time zone', 'without time zone', 'xml',
     ]
 
+PSEUDO_TYPES = [
+    'any', 'anyarray', 'anyelement', 'anyenum', 'anynonarray', 'cstring',
+    'internal', 'language_handler', 'fdw_handler', 'record', 'trigger',
+    'void', 'opaque',
+    ]
 
 if __name__ == '__main__':
     update_myself()

pygments/lexers/postgres.py

      Text, Comment, Operator, Keyword, Name, String, Number, Generic
 from pygments.lexers import get_lexer_by_name, ClassNotFound
 
-from pygments.lexers._postgres_builtins import KEYWORDS, DATATYPES
+from pygments.lexers._postgres_builtins import (
+    KEYWORDS, DATATYPES, PSEUDO_TYPES)
 
 
 __all__ = [ 'PostgresLexer', 'PostgresConsoleLexer' ]
             (r'\s+', Text),
             (r'--.*?\n', Comment.Single),
             (r'/\*', Comment.Multiline, 'multiline-comments'),
-            (r'(' + '|'.join([s.replace(" ", "\s+") for s in DATATYPES])
+            (r'(' + '|'.join([s.replace(" ", "\s+")
+                for s in DATATYPES + PSEUDO_TYPES])
                   + r')\b', Name.Builtin),
             (r'(' + '|'.join(KEYWORDS) + r')\b', Keyword),
             (r'[+*/<>=~!@#%^&|`?^-]+', Operator),
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.