better highlighting/tabbing for postgresql

--HG--
branch : pmacs2
This commit is contained in:
Erik Osheim 2010-02-12 14:21:18 -05:00
parent 71adad5551
commit 195bfd98c7
1 changed files with 33 additions and 20 deletions

View File

@ -57,30 +57,23 @@ sql_rules = [
RegionRule(r'sql_quoted', '"', StringGrammar2, '"'),
]
string_rules = [
RegionRule(r'string', "B'", BitStringGrammar, "'"),
RegionRule(r'string', "X'", HexStringGrammar, "'"),
RegionRule(r'string', "'", StringGrammar1, "'"),
]
def make_string_rules(q="'"):
return [
RegionRule(r'string', "B" + q, BitStringGrammar, q),
RegionRule(r'string', "X" + q, HexStringGrammar, q),
RegionRule(r'string', q, StringGrammar1, q),
]
PlPgSqlGrammar1.rules = [
PatternRule(r'variable', r'\$[0-9]+'),
] + base_rules + sql_rules + [
RegionRule(r'string', "B''", BitStringGrammar, "''"),
RegionRule(r'string', "X''", HexStringGrammar, "''"),
RegionRule(r'string', "''", StringGrammar1, "''"),
] + end_rules
] + base_rules + sql_rules + make_string_rules("''") + end_rules
PlPgSqlGrammar2.rules = [
PatternRule(r'variable', r'\$[0-9]+'),
] + base_rules + sql_rules + [
RegionRule(r'string', "B'", BitStringGrammar, "'"),
RegionRule(r'string', "X'", HexStringGrammar, "'"),
RegionRule(r'string', "'", StringGrammar1, "'"),
] + end_rules
] + base_rules + sql_rules + make_string_rules("'") + end_rules
class SqlGrammar(Grammar):
rules = base_rules + function_rules + sql_rules + string_rules + end_rules
rules = base_rules + function_rules + sql_rules + make_string_rules("'") + end_rules
class SqlTabber(StackTabber):
wst = ('spaces', 'null', 'eol', 'function.body.spaces', 'function.body.eol')
@ -91,6 +84,20 @@ class SqlTabber(StackTabber):
if not highlighter.tokens[y]: return False
t = highlighter.tokens[y][0]
return t.name == 'function'
def _handle_close_token(self, currlvl, y, i):
self._opt_pop('cont')
token = self.get_token(y, i)
s1 = token.string
if not self.markers:
raise Exception, "unmatched closing token %r" % s1
s2 = self.markers[-1].name
if self.mode.closetags[s1] == s2:
self._pop()
if self.is_leftmost_token(y, i):
currlvl = self.get_curr_level()
else:
raise Exception, "mismatched closing tag %r vs %r" % (s2, s1)
return currlvl
def _handle_other_token(self, currlvl, y, i):
w = self.mode.tabwidth
token = self.get_token(y, i)
@ -98,8 +105,13 @@ class SqlTabber(StackTabber):
fqname = token.fqname()
unhandled = False
if token.name == 'delimiter' and s == ';':
self._opt_pop('cont')
if token.name == 'delimiter':
if s == ';':
self._opt_pop('cont')
elif s == ',':
pass
else:
unhandled = True
elif token.name == 'eol':
pass
elif token.name == 'spaces':
@ -140,8 +152,9 @@ class SqlTabber(StackTabber):
else:
unhandled = True
#if self.is_rightmost_token(y, i) and unhandled:
# self._opt_append('cont', currlvl + w)
if self.is_rightmost_token(y, i):
if unhandled:
self._opt_append('cont', currlvl + w)
return currlvl