parent
6bf75e4200
commit
8eeb7b6b3e
110
mode/sql.py
110
mode/sql.py
|
@ -9,82 +9,56 @@ class BitStringGrammar(Grammar):
|
||||||
class HexStringGrammar(Grammar):
|
class HexStringGrammar(Grammar):
|
||||||
rules = [NocasePatternRule(r'data', r'[0-9a-f]+')]
|
rules = [NocasePatternRule(r'data', r'[0-9a-f]+')]
|
||||||
|
|
||||||
class PlPgSqlGrammar(Grammar):
|
base_rules = [
|
||||||
rules = [
|
PatternRule(r'spaces', r' +'),
|
||||||
PatternRule(r'spaces', r' +'),
|
PatternRule(r'comment', r'--.*\n$'),
|
||||||
|
RegionRule(r'comment', '/\*', Grammar, '\*/'),
|
||||||
|
PatternRule(r'delimiter', r':=|[():;,\.\$\[\]~]'),
|
||||||
|
]
|
||||||
|
|
||||||
PatternRule(r'comment', r'--.*\n$'),
|
function_rules = [
|
||||||
RegionRule(r'comment', '/\*', Grammar, '\*/'),
|
NocaseRegionRule(r'function', r'create function', FunctionGrammar, r';'),
|
||||||
PatternRule(r'delimiter', r':=|[():;,\.\[\]~]'),
|
NocaseRegionRule(r'function', r'create or replace function', FunctionGrammar, r';'),
|
||||||
|
]
|
||||||
NocasePatternRule(r'attribute', r'(?:check|exists|unique|not null|default|primary key|minvalue|foreign key|references)(?![A-Za-z0-9_])'),
|
|
||||||
NocasePatternRule(r'sql_keyword', r'(?:declare|begin|end if|end loop|end|raise notice|return|if|while|for|else)(?![A-Za-z0-9_])'),
|
sql_type_rule = NocasePatternRule(r'sql_type', r'(?:void|row|serial|varchar|float|integer|int|text|timestamptz|timestamp|datetz|date|timetz|time|boolean|bool)(?![A-Za-z0-9_])')
|
||||||
NocasePatternRule(r'sql_operator', r'(?:case|when|then|else|end|not in|not|and|or|is not|is|in|between|overlaps|like|ilike|similar)(?![A-Za-z0-9_])'),
|
|
||||||
NocasePatternRule(r'sql_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_])'),
|
sql_rules = [
|
||||||
NocasePatternRule(r'pseudokeyword', r'(?:returns|language|right join|left join|inner join|outer join|join|where|unknown|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'attribute', r'(?:check|exists|unique|not null|default|primary key|minvalue|foreign key|references)(?![A-Za-z0-9_])'),
|
||||||
NocasePatternRule(r'sql_type', r'(?:void|row|serial|varchar|float|integer|int|text|timestamptz|timestamp|datetz|date|timetz|time|boolean|bool|record|row)(?![A-Za-z0-9_])'),
|
NocasePatternRule(r'sql_operator', r'(?:case|when|then|else|end|not in|not|and|or|is not|is|in|between|overlaps|like|ilike|similar)(?![A-Za-z0-9_])'),
|
||||||
PatternRule(r'sql_builtin', r'(?:nextval|current_timestamp|current_time|current_date)(?![A-Za-z0-9_])'),
|
NocasePatternRule(r'sql_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_])'),
|
||||||
PatternRule(r'number', r'[0-9]+(?:e[+-]?[0-9]+)?'),
|
NocasePatternRule(r'pseudokeyword', r'(?:returns|language|right join|left join|inner join|outer join|join|where|unknown|null|true|false|into|values|as|from|order by|asc|desc|limit|distinct|cascade|using|on)(?![A-Za-z0-9_])'),
|
||||||
PatternRule(r'number', r'[0-9]+\.(?:[0-9]+)?(?:e[+-]?[0-9]+)?'),
|
sql_type_rule,
|
||||||
PatternRule(r'number', r'\.[0-9]+(?:e[+-]?[0-9]+)'),
|
PatternRule(r'sql_builtin', r'(?:nextval|current_timestamp|current_time|current_date)(?![A-Za-z0-9_])'),
|
||||||
RegionRule(r'string', "''", StringGrammar1, "''"),
|
PatternRule(r'number', r'[0-9]+(?:e[+-]?[0-9]+)?'),
|
||||||
RegionRule(r'string', "B'", BitStringGrammar, "'"),
|
PatternRule(r'number', r'[0-9]+\.(?:[0-9]+)?(?:e[+-]?[0-9]+)?'),
|
||||||
RegionRule(r'string', "X'", HexStringGrammar, "'"),
|
PatternRule(r'number', r'\.[0-9]+(?:e[+-]?[0-9]+)'),
|
||||||
RegionRule(r'sql_quoted', '"', StringGrammar2, '"'),
|
RegionRule(r'string', "B'", BitStringGrammar, "'"),
|
||||||
PatternRule(r'sql_variable', r'\$[1-9][0-9]*'),
|
RegionRule(r'string', "X'", HexStringGrammar, "'"),
|
||||||
PatternRule(r'sql_bareword', r'[A-Za-z0-9_]+'),
|
RegionRule(r'string', "'", StringGrammar1, "'"),
|
||||||
PatternRule(r'empty', r'^ *\n$'),
|
RegionRule(r'sql_quoted', '"', StringGrammar2, '"'),
|
||||||
PatternRule(r'eol', r'\n'),
|
]
|
||||||
]
|
|
||||||
|
end_rules = [
|
||||||
|
NocasePatternRule(r'sql_bareword', r'[a-z_][a-z0-9_]*'),
|
||||||
|
PatternRule(r'empty', r'^ *\n$'),
|
||||||
|
PatternRule(r'eol', r'\n'),
|
||||||
|
]
|
||||||
|
|
||||||
|
class PlPgSqlGrammar(Grammar):
|
||||||
|
rules = base_rules + sql_rules + end_rules
|
||||||
|
|
||||||
class FunctionGrammar(Grammar):
|
class FunctionGrammar(Grammar):
|
||||||
rules = [
|
rules = base_rules + [
|
||||||
PatternRule(r'spaces', r' +'),
|
|
||||||
|
|
||||||
PatternRule(r'comment', r'--.*\n$'),
|
|
||||||
RegionRule(r'comment', '/\*', Grammar, '\*/'),
|
|
||||||
PatternRule(r'delimiter', r':=|[():;,\.\$\[\]~]'),
|
|
||||||
|
|
||||||
PatternRule(r'name', r'[a-zA-Z_][a-zA-Z0-9_]*(?=\()'),
|
PatternRule(r'name', r'[a-zA-Z_][a-zA-Z0-9_]*(?=\()'),
|
||||||
NocasePatternRule(r'sql_keyword', r'(?:as|returns|language)'),
|
NocasePatternRule(r'sql_keyword', r'(?:as|returns|language)'),
|
||||||
NocasePatternRule(r'sql_type', r'(?:void|row|serial|varchar|float|integer|int|text|timestamptz|timestamp|datetz|date|timetz|time|boolean|bool)(?![A-Za-z0-9_])'),
|
sql_type_rule,
|
||||||
|
|
||||||
NocasePatternRule(r'language', r'(?<=language ) *[a-zA-Z_][a-zA-Z0-9_]+'),
|
NocasePatternRule(r'language', r'(?<=language ) *[a-zA-Z_][a-zA-Z0-9_]+'),
|
||||||
|
|
||||||
RegionRule(r'definition', "'", PlPgSqlGrammar, "'(?!')"),
|
RegionRule(r'definition', "'", PlPgSqlGrammar, "'(?!')"),
|
||||||
PatternRule(r'sql_bareword', r'[A-Za-z0-9_]+'),
|
] + end_rules
|
||||||
PatternRule(r'empty', r'^ *\n$'),
|
|
||||||
PatternRule(r'eol', r'\n'),
|
|
||||||
]
|
|
||||||
|
|
||||||
class SqlGrammar(Grammar):
|
class SqlGrammar(Grammar):
|
||||||
rules = [
|
rules = base_rules + function_rules + sql_rules + end_rules
|
||||||
PatternRule(r'spaces', r' +'),
|
|
||||||
|
|
||||||
PatternRule(r'comment', r'--.*\n$'),
|
|
||||||
RegionRule(r'comment', '/\*', Grammar, '\*/'),
|
|
||||||
PatternRule(r'delimiter', r':=|[():;,\.\$\[\]~]'),
|
|
||||||
|
|
||||||
NocaseRegionRule(r'function', r'create function', FunctionGrammar, r';'),
|
|
||||||
NocaseRegionRule(r'function', r'create or replace function', FunctionGrammar, r';'),
|
|
||||||
|
|
||||||
NocasePatternRule(r'attribute', r'(?:check|exists|unique|not null|default|primary key|minvalue|foreign key|references)(?![A-Za-z0-9_])'),
|
|
||||||
NocasePatternRule(r'sql_operator', r'(?:case|when|then|else|end|not in|not|and|or|is not|is|in|between|overlaps|like|ilike|similar)(?![A-Za-z0-9_])'),
|
|
||||||
NocasePatternRule(r'sql_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|unknown|null|true|false|into|values|as|from|order by|asc|desc|limit|distinct|cascade|using|on)(?![A-Za-z0-9_])'),
|
|
||||||
NocasePatternRule(r'sql_type', r'(?:void|row|serial|varchar|float|integer|int|text|timestamptz|timestamp|datetz|date|timetz|time|boolean|bool)(?![A-Za-z0-9_])'),
|
|
||||||
PatternRule(r'sql_builtin', r'(?:nextval|current_timestamp|current_time|current_date)(?![A-Za-z0-9_])'),
|
|
||||||
PatternRule(r'number', r'[0-9]+(?:e[+-]?[0-9]+)?'),
|
|
||||||
PatternRule(r'number', r'[0-9]+\.(?:[0-9]+)?(?:e[+-]?[0-9]+)?'),
|
|
||||||
PatternRule(r'number', r'\.[0-9]+(?:e[+-]?[0-9]+)'),
|
|
||||||
RegionRule(r'string', "B'", BitStringGrammar, "'"),
|
|
||||||
RegionRule(r'string', "X'", HexStringGrammar, "'"),
|
|
||||||
RegionRule(r'string', "'", StringGrammar1, "'"),
|
|
||||||
RegionRule(r'sql_quoted', '"', StringGrammar2, '"'),
|
|
||||||
NocasePatternRule(r'sql_bareword', r'[a-z_][a-z0-9_]*'),
|
|
||||||
PatternRule(r'empty', r'^ *\n$'),
|
|
||||||
PatternRule(r'eol', r'\n'),
|
|
||||||
]
|
|
||||||
|
|
||||||
class SqlCommentRegion(CommentRegion):
|
class SqlCommentRegion(CommentRegion):
|
||||||
commentc = '--'
|
commentc = '--'
|
||||||
|
@ -146,7 +120,7 @@ class Sql(mode.Fundamental):
|
||||||
closetags = {')': '(', ']': '[', '}': '{'}
|
closetags = {')': '(', ']': '[', '}': '{'}
|
||||||
actions = [SqlCommentRegion, SqlUncommentRegion]
|
actions = [SqlCommentRegion, SqlUncommentRegion]
|
||||||
|
|
||||||
colors = {
|
colors = {
|
||||||
'sql_operator': ('yellow', 'default', 'bold'),
|
'sql_operator': ('yellow', 'default', 'bold'),
|
||||||
'attribute': ('magenta', 'default', 'bold'),
|
'attribute': ('magenta', 'default', 'bold'),
|
||||||
'sql_keyword': ('cyan', 'default', 'bold'),
|
'sql_keyword': ('cyan', 'default', 'bold'),
|
||||||
|
|
Loading…
Reference in New Issue