From e81712afc178359dd9e079283d5ccf3f5dd6e612 Mon Sep 17 00:00:00 2001 From: moculus Date: Sat, 14 Feb 2009 20:51:01 +0000 Subject: [PATCH] sql mode for real --HG-- branch : pmacs2 --- mode/sql.py | 48 ++++++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/mode/sql.py b/mode/sql.py index d648ae8..c71a24d 100644 --- a/mode/sql.py +++ b/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