123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621 |
- # -*- coding: utf-8 -*-
- """
- pygments.lexers._postgres_builtins
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- Self-updating data files for PostgreSQL lexer.
- :copyright: Copyright 2006-2019 by the Pygments team, see AUTHORS.
- :license: BSD, see LICENSE for details.
- """
- # Autogenerated: please edit them if you like wasting your time.
- KEYWORDS = (
- 'ABORT',
- 'ABSOLUTE',
- 'ACCESS',
- 'ACTION',
- 'ADD',
- 'ADMIN',
- 'AFTER',
- 'AGGREGATE',
- 'ALL',
- 'ALSO',
- 'ALTER',
- 'ALWAYS',
- 'ANALYSE',
- 'ANALYZE',
- 'AND',
- 'ANY',
- 'ARRAY',
- 'AS',
- 'ASC',
- 'ASSERTION',
- 'ASSIGNMENT',
- 'ASYMMETRIC',
- 'AT',
- 'ATTRIBUTE',
- 'AUTHORIZATION',
- 'BACKWARD',
- 'BEFORE',
- 'BEGIN',
- 'BETWEEN',
- 'BIGINT',
- 'BINARY',
- 'BIT',
- 'BOOLEAN',
- 'BOTH',
- 'BY',
- 'CACHE',
- 'CALLED',
- 'CASCADE',
- 'CASCADED',
- 'CASE',
- 'CAST',
- 'CATALOG',
- 'CHAIN',
- 'CHAR',
- 'CHARACTER',
- 'CHARACTERISTICS',
- 'CHECK',
- 'CHECKPOINT',
- 'CLASS',
- 'CLOSE',
- 'CLUSTER',
- 'COALESCE',
- 'COLLATE',
- 'COLLATION',
- 'COLUMN',
- 'COMMENT',
- 'COMMENTS',
- 'COMMIT',
- 'COMMITTED',
- 'CONCURRENTLY',
- 'CONFIGURATION',
- 'CONNECTION',
- 'CONSTRAINT',
- 'CONSTRAINTS',
- 'CONTENT',
- 'CONTINUE',
- 'CONVERSION',
- 'COPY',
- 'COST',
- 'CREATE',
- 'CROSS',
- 'CSV',
- 'CURRENT',
- 'CURRENT_CATALOG',
- 'CURRENT_DATE',
- 'CURRENT_ROLE',
- 'CURRENT_SCHEMA',
- 'CURRENT_TIME',
- 'CURRENT_TIMESTAMP',
- 'CURRENT_USER',
- 'CURSOR',
- 'CYCLE',
- 'DATA',
- 'DATABASE',
- 'DAY',
- 'DEALLOCATE',
- 'DEC',
- 'DECIMAL',
- 'DECLARE',
- 'DEFAULT',
- 'DEFAULTS',
- 'DEFERRABLE',
- 'DEFERRED',
- 'DEFINER',
- 'DELETE',
- 'DELIMITER',
- 'DELIMITERS',
- 'DESC',
- 'DICTIONARY',
- 'DISABLE',
- 'DISCARD',
- 'DISTINCT',
- 'DO',
- 'DOCUMENT',
- 'DOMAIN',
- 'DOUBLE',
- 'DROP',
- 'EACH',
- 'ELSE',
- 'ENABLE',
- 'ENCODING',
- 'ENCRYPTED',
- 'END',
- 'ENUM',
- 'ESCAPE',
- 'EVENT',
- 'EXCEPT',
- 'EXCLUDE',
- 'EXCLUDING',
- 'EXCLUSIVE',
- 'EXECUTE',
- 'EXISTS',
- 'EXPLAIN',
- 'EXTENSION',
- 'EXTERNAL',
- 'EXTRACT',
- 'FALSE',
- 'FAMILY',
- 'FETCH',
- 'FILTER',
- 'FIRST',
- 'FLOAT',
- 'FOLLOWING',
- 'FOR',
- 'FORCE',
- 'FOREIGN',
- 'FORWARD',
- 'FREEZE',
- 'FROM',
- 'FULL',
- 'FUNCTION',
- 'FUNCTIONS',
- 'GLOBAL',
- 'GRANT',
- 'GRANTED',
- 'GREATEST',
- 'GROUP',
- 'HANDLER',
- 'HAVING',
- 'HEADER',
- 'HOLD',
- 'HOUR',
- 'IDENTITY',
- 'IF',
- 'ILIKE',
- 'IMMEDIATE',
- 'IMMUTABLE',
- 'IMPLICIT',
- 'IN',
- 'INCLUDING',
- 'INCREMENT',
- 'INDEX',
- 'INDEXES',
- 'INHERIT',
- 'INHERITS',
- 'INITIALLY',
- 'INLINE',
- 'INNER',
- 'INOUT',
- 'INPUT',
- 'INSENSITIVE',
- 'INSERT',
- 'INSTEAD',
- 'INT',
- 'INTEGER',
- 'INTERSECT',
- 'INTERVAL',
- 'INTO',
- 'INVOKER',
- 'IS',
- 'ISNULL',
- 'ISOLATION',
- 'JOIN',
- 'KEY',
- 'LABEL',
- 'LANGUAGE',
- 'LARGE',
- 'LAST',
- 'LATERAL',
- 'LC_COLLATE',
- 'LC_CTYPE',
- 'LEADING',
- 'LEAKPROOF',
- 'LEAST',
- 'LEFT',
- 'LEVEL',
- 'LIKE',
- 'LIMIT',
- 'LISTEN',
- 'LOAD',
- 'LOCAL',
- 'LOCALTIME',
- 'LOCALTIMESTAMP',
- 'LOCATION',
- 'LOCK',
- 'MAPPING',
- 'MATCH',
- 'MATERIALIZED',
- 'MAXVALUE',
- 'MINUTE',
- 'MINVALUE',
- 'MODE',
- 'MONTH',
- 'MOVE',
- 'NAME',
- 'NAMES',
- 'NATIONAL',
- 'NATURAL',
- 'NCHAR',
- 'NEXT',
- 'NO',
- 'NONE',
- 'NOT',
- 'NOTHING',
- 'NOTIFY',
- 'NOTNULL',
- 'NOWAIT',
- 'NULL',
- 'NULLIF',
- 'NULLS',
- 'NUMERIC',
- 'OBJECT',
- 'OF',
- 'OFF',
- 'OFFSET',
- 'OIDS',
- 'ON',
- 'ONLY',
- 'OPERATOR',
- 'OPTION',
- 'OPTIONS',
- 'OR',
- 'ORDER',
- 'ORDINALITY',
- 'OUT',
- 'OUTER',
- 'OVER',
- 'OVERLAPS',
- 'OVERLAY',
- 'OWNED',
- 'OWNER',
- 'PARSER',
- 'PARTIAL',
- 'PARTITION',
- 'PASSING',
- 'PASSWORD',
- 'PLACING',
- 'PLANS',
- 'POLICY',
- 'POSITION',
- 'PRECEDING',
- 'PRECISION',
- 'PREPARE',
- 'PREPARED',
- 'PRESERVE',
- 'PRIMARY',
- 'PRIOR',
- 'PRIVILEGES',
- 'PROCEDURAL',
- 'PROCEDURE',
- 'PROGRAM',
- 'QUOTE',
- 'RANGE',
- 'READ',
- 'REAL',
- 'REASSIGN',
- 'RECHECK',
- 'RECURSIVE',
- 'REF',
- 'REFERENCES',
- 'REFRESH',
- 'REINDEX',
- 'RELATIVE',
- 'RELEASE',
- 'RENAME',
- 'REPEATABLE',
- 'REPLACE',
- 'REPLICA',
- 'RESET',
- 'RESTART',
- 'RESTRICT',
- 'RETURNING',
- 'RETURNS',
- 'REVOKE',
- 'RIGHT',
- 'ROLE',
- 'ROLLBACK',
- 'ROW',
- 'ROWS',
- 'RULE',
- 'SAVEPOINT',
- 'SCHEMA',
- 'SCROLL',
- 'SEARCH',
- 'SECOND',
- 'SECURITY',
- 'SELECT',
- 'SEQUENCE',
- 'SEQUENCES',
- 'SERIALIZABLE',
- 'SERVER',
- 'SESSION',
- 'SESSION_USER',
- 'SET',
- 'SETOF',
- 'SHARE',
- 'SHOW',
- 'SIMILAR',
- 'SIMPLE',
- 'SMALLINT',
- 'SNAPSHOT',
- 'SOME',
- 'STABLE',
- 'STANDALONE',
- 'START',
- 'STATEMENT',
- 'STATISTICS',
- 'STDIN',
- 'STDOUT',
- 'STORAGE',
- 'STRICT',
- 'STRIP',
- 'SUBSTRING',
- 'SYMMETRIC',
- 'SYSID',
- 'SYSTEM',
- 'TABLE',
- 'TABLES',
- 'TABLESPACE',
- 'TEMP',
- 'TEMPLATE',
- 'TEMPORARY',
- 'TEXT',
- 'THEN',
- 'TIME',
- 'TIMESTAMP',
- 'TO',
- 'TRAILING',
- 'TRANSACTION',
- 'TREAT',
- 'TRIGGER',
- 'TRIM',
- 'TRUE',
- 'TRUNCATE',
- 'TRUSTED',
- 'TYPE',
- 'TYPES',
- 'UNBOUNDED',
- 'UNCOMMITTED',
- 'UNENCRYPTED',
- 'UNION',
- 'UNIQUE',
- 'UNKNOWN',
- 'UNLISTEN',
- 'UNLOGGED',
- 'UNTIL',
- 'UPDATE',
- 'USER',
- 'USING',
- 'VACUUM',
- 'VALID',
- 'VALIDATE',
- 'VALIDATOR',
- 'VALUE',
- 'VALUES',
- 'VARCHAR',
- 'VARIADIC',
- 'VARYING',
- 'VERBOSE',
- 'VERSION',
- 'VIEW',
- 'VIEWS',
- 'VOLATILE',
- 'WHEN',
- 'WHERE',
- 'WHITESPACE',
- 'WINDOW',
- 'WITH',
- 'WITHIN',
- 'WITHOUT',
- 'WORK',
- 'WRAPPER',
- 'WRITE',
- 'XML',
- 'XMLATTRIBUTES',
- 'XMLCONCAT',
- 'XMLELEMENT',
- 'XMLEXISTS',
- 'XMLFOREST',
- 'XMLPARSE',
- 'XMLPI',
- 'XMLROOT',
- 'XMLSERIALIZE',
- 'YEAR',
- 'YES',
- 'ZONE',
- )
- DATATYPES = (
- 'bigint',
- 'bigserial',
- 'bit',
- 'bit varying',
- 'bool',
- 'boolean',
- 'box',
- 'bytea',
- 'char',
- 'character',
- 'character varying',
- 'cidr',
- 'circle',
- 'date',
- 'decimal',
- 'double precision',
- 'float4',
- 'float8',
- 'inet',
- 'int',
- 'int2',
- 'int4',
- 'int8',
- 'integer',
- 'interval',
- 'json',
- 'jsonb',
- 'line',
- 'lseg',
- 'macaddr',
- 'money',
- 'numeric',
- 'path',
- 'pg_lsn',
- 'point',
- 'polygon',
- 'real',
- 'serial',
- 'serial2',
- 'serial4',
- 'serial8',
- 'smallint',
- 'smallserial',
- 'text',
- 'time',
- 'timestamp',
- 'timestamptz',
- 'timetz',
- 'tsquery',
- 'tsvector',
- 'txid_snapshot',
- 'uuid',
- 'varbit',
- 'varchar',
- 'with time zone',
- 'without time zone',
- 'xml',
- )
- PSEUDO_TYPES = (
- 'any',
- 'anyelement',
- 'anyarray',
- 'anynonarray',
- 'anyenum',
- 'anyrange',
- 'cstring',
- 'internal',
- 'language_handler',
- 'fdw_handler',
- 'record',
- 'trigger',
- 'void',
- 'opaque',
- )
- # Remove 'trigger' from types
- PSEUDO_TYPES = tuple(sorted(set(PSEUDO_TYPES) - set(map(str.lower, KEYWORDS))))
- PLPGSQL_KEYWORDS = (
- 'ALIAS', 'CONSTANT', 'DIAGNOSTICS', 'ELSIF', 'EXCEPTION', 'EXIT',
- 'FOREACH', 'GET', 'LOOP', 'NOTICE', 'OPEN', 'PERFORM', 'QUERY', 'RAISE',
- 'RETURN', 'REVERSE', 'SQLSTATE', 'WHILE',
- )
- if __name__ == '__main__': # pragma: no cover
- import re
- try:
- from urllib import urlopen
- except ImportError:
- from urllib.request import urlopen
- from pygments.util import format_lines
- # One man's constant is another man's variable.
- SOURCE_URL = 'https://github.com/postgres/postgres/raw/master'
- KEYWORDS_URL = SOURCE_URL + '/doc/src/sgml/keywords.sgml'
- DATATYPES_URL = SOURCE_URL + '/doc/src/sgml/datatype.sgml'
- def update_myself():
- data_file = list(urlopen(DATATYPES_URL))
- datatypes = parse_datatypes(data_file)
- pseudos = parse_pseudos(data_file)
- keywords = parse_keywords(urlopen(KEYWORDS_URL))
- update_consts(__file__, 'DATATYPES', datatypes)
- update_consts(__file__, 'PSEUDO_TYPES', pseudos)
- update_consts(__file__, 'KEYWORDS', keywords)
- def parse_keywords(f):
- kw = []
- for m in re.finditer(
- r'\s*<entry><token>([^<]+)</token></entry>\s*'
- r'<entry>([^<]+)</entry>', f.read()):
- kw.append(m.group(1))
- if not kw:
- raise ValueError('no keyword found')
- kw.sort()
- return kw
- def parse_datatypes(f):
- dt = set()
- for line in f:
- if '<sect1' in line:
- break
- if '<entry><type>' not in line:
- continue
- # Parse a string such as
- # time [ (<replaceable>p</replaceable>) ] [ without time zone ]
- # into types "time" and "without time zone"
- # remove all the tags
- line = re.sub("<replaceable>[^<]+</replaceable>", "", line)
- line = re.sub("<[^>]+>", "", line)
- # Drop the parts containing braces
- for tmp in [t for tmp in line.split('[')
- for t in tmp.split(']') if "(" not in t]:
- for t in tmp.split(','):
- t = t.strip()
- if not t: continue
- dt.add(" ".join(t.split()))
- dt = list(dt)
- 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 update_consts(filename, constname, content):
- with open(filename) as f:
- data = f.read()
- # Line to start/end inserting
- re_match = re.compile(r'^%s\s*=\s*\($.*?^\s*\)$' % constname, re.M | re.S)
- m = re_match.search(data)
- if not m:
- raise ValueError('Could not find existing definition for %s' %
- (constname,))
- new_block = format_lines(constname, content)
- data = data[:m.start()] + new_block + data[m.end():]
- with open(filename, 'w') as f:
- f.write(data)
- update_myself()
|