parent
8eeb7b6b3e
commit
e81712afc1
48
mode/sql.py
48
mode/sql.py
|
@ -16,13 +16,32 @@ base_rules = [
|
|||
PatternRule(r'delimiter', r':=|[():;,\.\$\[\]~]'),
|
||||
]
|
||||
|
||||
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
|
||||
pass
|
||||
|
||||
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_])')
|
||||
|
||||
class FunctionGrammar(Grammar):
|
||||
rules = base_rules + [
|
||||
PatternRule(r'name', r'[a-zA-Z_][a-zA-Z0-9_]*(?=\()'),
|
||||
NocasePatternRule(r'sql_keyword', r'(?:as|returns|language)'),
|
||||
sql_type_rule,
|
||||
NocasePatternRule(r'language', r'(?<=language ) *[a-zA-Z_][a-zA-Z0-9_]+'),
|
||||
RegionRule(r'definition', "'", PlPgSqlGrammar, "'(?!')"),
|
||||
] + end_rules
|
||||
|
||||
function_rules = [
|
||||
NocaseRegionRule(r'function', r'create function', FunctionGrammar, r';'),
|
||||
NocaseRegionRule(r'function', r'create or replace function', FunctionGrammar, r';'),
|
||||
]
|
||||
|
||||
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_])')
|
||||
|
||||
sql_rules = [
|
||||
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_])'),
|
||||
|
@ -39,23 +58,16 @@ sql_rules = [
|
|||
RegionRule(r'sql_quoted', '"', StringGrammar2, '"'),
|
||||
]
|
||||
|
||||
end_rules = [
|
||||
NocasePatternRule(r'sql_bareword', r'[a-z_][a-z0-9_]*'),
|
||||
PatternRule(r'empty', r'^ *\n$'),
|
||||
PatternRule(r'eol', r'\n'),
|
||||
]
|
||||
PlPgSqlGrammar.rules = base_rules + sql_rules + end_rules
|
||||
|
||||
class PlPgSqlGrammar(Grammar):
|
||||
rules = base_rules + sql_rules + end_rules
|
||||
|
||||
class FunctionGrammar(Grammar):
|
||||
rules = base_rules + [
|
||||
PatternRule(r'name', r'[a-zA-Z_][a-zA-Z0-9_]*(?=\()'),
|
||||
NocasePatternRule(r'sql_keyword', r'(?:as|returns|language)'),
|
||||
sql_type_rule,
|
||||
NocasePatternRule(r'language', r'(?<=language ) *[a-zA-Z_][a-zA-Z0-9_]+'),
|
||||
RegionRule(r'definition', "'", PlPgSqlGrammar, "'(?!')"),
|
||||
] + end_rules
|
||||
#class FunctionGrammar(Grammar):
|
||||
# rules = base_rules + [
|
||||
# PatternRule(r'name', r'[a-zA-Z_][a-zA-Z0-9_]*(?=\()'),
|
||||
# NocasePatternRule(r'sql_keyword', r'(?:as|returns|language)'),
|
||||
# sql_type_rule,
|
||||
# NocasePatternRule(r'language', r'(?<=language ) *[a-zA-Z_][a-zA-Z0-9_]+'),
|
||||
# RegionRule(r'definition', "'", PlPgSqlGrammar, "'(?!')"),
|
||||
# ] + end_rules
|
||||
|
||||
class SqlGrammar(Grammar):
|
||||
rules = base_rules + function_rules + sql_rules + end_rules
|
||||
|
|
Loading…
Reference in New Issue