sql mode for real

--HG--
branch : pmacs2
This commit is contained in:
moculus 2009-02-14 20:51:01 +00:00
parent 8eeb7b6b3e
commit e81712afc1
1 changed files with 30 additions and 18 deletions

View File

@ -16,13 +16,32 @@ base_rules = [
PatternRule(r'delimiter', r':=|[():;,\.\$\[\]~]'), 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 = [ function_rules = [
NocaseRegionRule(r'function', r'create function', FunctionGrammar, r';'), NocaseRegionRule(r'function', r'create function', FunctionGrammar, r';'),
NocaseRegionRule(r'function', r'create or replace 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 = [ sql_rules = [
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'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_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, '"'), RegionRule(r'sql_quoted', '"', StringGrammar2, '"'),
] ]
end_rules = [ PlPgSqlGrammar.rules = base_rules + sql_rules + 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): #class FunctionGrammar(Grammar):
rules = base_rules + sql_rules + end_rules # rules = base_rules + [
# PatternRule(r'name', r'[a-zA-Z_][a-zA-Z0-9_]*(?=\()'),
class FunctionGrammar(Grammar): # NocasePatternRule(r'sql_keyword', r'(?:as|returns|language)'),
rules = base_rules + [ # sql_type_rule,
PatternRule(r'name', r'[a-zA-Z_][a-zA-Z0-9_]*(?=\()'), # NocasePatternRule(r'language', r'(?<=language ) *[a-zA-Z_][a-zA-Z0-9_]+'),
NocasePatternRule(r'sql_keyword', r'(?:as|returns|language)'), # RegionRule(r'definition', "'", PlPgSqlGrammar, "'(?!')"),
sql_type_rule, # ] + end_rules
NocasePatternRule(r'language', r'(?<=language ) *[a-zA-Z_][a-zA-Z0-9_]+'),
RegionRule(r'definition', "'", PlPgSqlGrammar, "'(?!')"),
] + end_rules
class SqlGrammar(Grammar): class SqlGrammar(Grammar):
rules = base_rules + function_rules + sql_rules + end_rules rules = base_rules + function_rules + sql_rules + end_rules