parent
d2fad574cd
commit
47a35eb0c7
35
mode/sql.py
35
mode/sql.py
|
@ -6,17 +6,18 @@ class PlPgSqlGrammar(Grammar):
|
||||||
rules = [
|
rules = [
|
||||||
PatternRule(r'comment', r'--.*\n$'),
|
PatternRule(r'comment', r'--.*\n$'),
|
||||||
RegionRule(r'comment', '/\*', Grammar, '\*/'),
|
RegionRule(r'comment', '/\*', Grammar, '\*/'),
|
||||||
PatternRule(r'delimiter', r':=|[():;,\.\$\[\]]'),
|
PatternRule(r'delimiter', r':=|[():;,\.\[\]]'),
|
||||||
|
|
||||||
NocasePatternRule(r'attribute', r'(?:check|exists|unique|not null|default|primary key|minvalue|foreign key|references)(?![A-Za-z0-9_])'),
|
NocasePatternRule(r'attribute', r'(?:check|exists|unique|not null|default|primary key|minvalue|foreign key|references)(?![A-Za-z0-9_])'),
|
||||||
NocasePatternRule(r'keyword', r'(?:declare|begin|end|raise notice|return)'),
|
NocasePatternRule(r'keyword', r'(?:declare|begin|end if|end loop|end|raise notice|return|if|while|for|else)(?![A-Za-z0-9_])'),
|
||||||
NocasePatternRule(r'operator', r'(?:case|when|then|else|end|not|and|or|is not|is|in|not in)(?![A-Za-z0-9_])'),
|
NocasePatternRule(r'operator', r'(?:case|when|then|else|end|not|and|or|is not|is|in|not in)(?![A-Za-z0-9_])'),
|
||||||
NocasePatternRule(r'keyword', r'(?:create database|create index|create sequence|create table|create trigger|create view|select|insert|update|delete|drop database|drop index|drop sequence|drop table|drop trigger|drop view|create user|alter user|drop user|drop function|grant|revoke|create function|create or replace function|create or replace view|create language|create operator|create type)(?![A-Za-z0-9_])'),
|
NocasePatternRule(r'keyword', r'(?:create database|create index|create sequence|create table|create trigger|create view|select|insert|update|delete|drop database|drop index|drop sequence|drop table|drop trigger|drop view|create user|alter user|drop user|drop function|grant|revoke|create function|create or replace function|create or replace view|create language|create operator|create type)(?![A-Za-z0-9_])'),
|
||||||
NocasePatternRule(r'pseudokeyword', r'(?:returns|language|right join|left join|inner join|outer join|join|where|null|true|false|into|values|as|from|order by|asc|desc|limit|distinct|cascade|using|on)(?![A-Za-z0-9_])'),
|
NocasePatternRule(r'pseudokeyword', r'(?:returns|language|right join|left join|inner join|outer join|join|where|null|true|false|into|values|as|from|order by|next|asc|desc|limit|distinct|cascade|alias for|using|on)(?![A-Za-z0-9_])'),
|
||||||
NocasePatternRule(r'type', r'(?:void|row|serial|varchar|float|integer|int|text|timestamptz|timestamp|datetz|date|timetz|time|boolean|bool)(?![A-Za-z0-9_])'),
|
NocasePatternRule(r'type', r'(?:void|row|serial|varchar|float|integer|int|text|timestamptz|timestamp|datetz|date|timetz|time|boolean|bool|record|row)(?![A-Za-z0-9_])'),
|
||||||
PatternRule(r'builtin', r'(?:nextval|current_timestamp|current_time|current_date)(?![A-Za-z0-9_])'),
|
PatternRule(r'builtin', r'(?:nextval|current_timestamp|current_time|current_date)(?![A-Za-z0-9_])'),
|
||||||
RegionRule(r'string', "''", StringGrammar, "''"),
|
RegionRule(r'string', "''", StringGrammar, "''"),
|
||||||
RegionRule(r'quoted', '"', StringGrammar, '"'),
|
RegionRule(r'quoted', '"', StringGrammar, '"'),
|
||||||
|
PatternRule(r'variable', r'\$[1-9][0-9]*'),
|
||||||
PatternRule(r'bareword', r'[A-Za-z0-9_]+'),
|
PatternRule(r'bareword', r'[A-Za-z0-9_]+'),
|
||||||
PatternRule(r'empty', r'^ *\n$'),
|
PatternRule(r'empty', r'^ *\n$'),
|
||||||
PatternRule(r'eol', r'\n'),
|
PatternRule(r'eol', r'\n'),
|
||||||
|
@ -74,20 +75,33 @@ class SqlTabber(tab.StackTabber):
|
||||||
return t.name == 'function'
|
return t.name == 'function'
|
||||||
def _handle_other_token(self, currlvl, y, i):
|
def _handle_other_token(self, currlvl, y, i):
|
||||||
token = self.get_token(y, i)
|
token = self.get_token(y, i)
|
||||||
if token.name == 'delimiter' and token.string == ';':
|
s = token.string.lower()
|
||||||
|
if token.name == 'delimiter' and s == ';':
|
||||||
self._opt_pop('cont')
|
self._opt_pop('cont')
|
||||||
elif token.name == 'keyword':
|
elif token.name == 'keyword':
|
||||||
if token.string == 'declare':
|
if s == 'declare':
|
||||||
self._opt_append('declare', currlvl + 4)
|
self._append('declare', currlvl + 4)
|
||||||
elif token.string == 'begin':
|
elif s == 'begin':
|
||||||
currlvl -= 4
|
currlvl -= 4
|
||||||
elif token.string == 'end':
|
elif s == 'end':
|
||||||
self._opt_pop('declare')
|
self._opt_pop('declare')
|
||||||
currlvl = self.get_curr_level()
|
currlvl = self.get_curr_level()
|
||||||
|
elif s == 'end if':
|
||||||
|
self._opt_pop('if')
|
||||||
|
currlvl = self.get_curr_level()
|
||||||
|
elif s == 'end loop':
|
||||||
|
self._opt_pop('loop')
|
||||||
|
currlvl = self.get_curr_level()
|
||||||
|
elif s == 'else':
|
||||||
|
currlvl -= 4
|
||||||
|
elif s == 'if':
|
||||||
|
self._append('if', currlvl + 4)
|
||||||
|
elif s in ('while', 'for'):
|
||||||
|
self._append('loop', currlvl + 4)
|
||||||
|
|
||||||
if self.is_rightmost_token(y, i):
|
if self.is_rightmost_token(y, i):
|
||||||
if not self._empty() and token.name == 'continuation':
|
if not self._empty() and token.name == 'continuation':
|
||||||
self._opt_append('cont', currlvl + 4)
|
self._append('cont', currlvl + 4)
|
||||||
elif token.name == 'eol' and not self.markers:
|
elif token.name == 'eol' and not self.markers:
|
||||||
self._opt_pop("cont")
|
self._opt_pop("cont")
|
||||||
return currlvl
|
return currlvl
|
||||||
|
@ -115,6 +129,7 @@ class Sql(mode.Fundamental):
|
||||||
'string.escaped': ('magenta', 'default'),
|
'string.escaped': ('magenta', 'default'),
|
||||||
'string.octal': ('magenta', 'default'),
|
'string.octal': ('magenta', 'default'),
|
||||||
'string.end': ('green', 'default'),
|
'string.end': ('green', 'default'),
|
||||||
|
'variable': ('yellow', 'default'),
|
||||||
'bareword': ('default', 'default'),
|
'bareword': ('default', 'default'),
|
||||||
|
|
||||||
'function.start': ('cyan', 'default'),
|
'function.start': ('cyan', 'default'),
|
||||||
|
|
Loading…
Reference in New Issue