diff options
Diffstat (limited to 'pygments')
-rw-r--r-- | pygments/lexers/_postgres_builtins.py | 39 | ||||
-rw-r--r-- | pygments/lexers/postgres.py | 6 |
2 files changed, 42 insertions, 3 deletions
diff --git a/pygments/lexers/_postgres_builtins.py b/pygments/lexers/_postgres_builtins.py index 2ebff4c4..8e6ca2e8 100644 --- a/pygments/lexers/_postgres_builtins.py +++ b/pygments/lexers/_postgres_builtins.py @@ -17,9 +17,13 @@ KEYWORDS_URL = SOURCE_URL + '/doc/src/sgml/keywords.sgml' 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): @@ -63,6 +67,34 @@ def parse_datatypes(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) @@ -179,6 +211,11 @@ DATATYPES = [ '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() diff --git a/pygments/lexers/postgres.py b/pygments/lexers/postgres.py index 583e118d..b4dc9df0 100644 --- a/pygments/lexers/postgres.py +++ b/pygments/lexers/postgres.py @@ -18,7 +18,8 @@ from pygments.token import Error, Punctuation, Literal, Token, \ 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' ] @@ -86,7 +87,8 @@ class PostgresLexer(RegexLexer): (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), |