better highlighting/tabbing for postgresql
--HG-- branch : pmacs2
This commit is contained in:
parent
71adad5551
commit
195bfd98c7
53
mode/sql.py
53
mode/sql.py
|
@ -57,30 +57,23 @@ sql_rules = [
|
||||||
RegionRule(r'sql_quoted', '"', StringGrammar2, '"'),
|
RegionRule(r'sql_quoted', '"', StringGrammar2, '"'),
|
||||||
]
|
]
|
||||||
|
|
||||||
string_rules = [
|
def make_string_rules(q="'"):
|
||||||
RegionRule(r'string', "B'", BitStringGrammar, "'"),
|
return [
|
||||||
RegionRule(r'string', "X'", HexStringGrammar, "'"),
|
RegionRule(r'string', "B" + q, BitStringGrammar, q),
|
||||||
RegionRule(r'string', "'", StringGrammar1, "'"),
|
RegionRule(r'string', "X" + q, HexStringGrammar, q),
|
||||||
]
|
RegionRule(r'string', q, StringGrammar1, q),
|
||||||
|
]
|
||||||
|
|
||||||
PlPgSqlGrammar1.rules = [
|
PlPgSqlGrammar1.rules = [
|
||||||
PatternRule(r'variable', r'\$[0-9]+'),
|
PatternRule(r'variable', r'\$[0-9]+'),
|
||||||
] + base_rules + sql_rules + [
|
] + base_rules + sql_rules + make_string_rules("''") + end_rules
|
||||||
RegionRule(r'string', "B''", BitStringGrammar, "''"),
|
|
||||||
RegionRule(r'string', "X''", HexStringGrammar, "''"),
|
|
||||||
RegionRule(r'string', "''", StringGrammar1, "''"),
|
|
||||||
] + end_rules
|
|
||||||
|
|
||||||
PlPgSqlGrammar2.rules = [
|
PlPgSqlGrammar2.rules = [
|
||||||
PatternRule(r'variable', r'\$[0-9]+'),
|
PatternRule(r'variable', r'\$[0-9]+'),
|
||||||
] + base_rules + sql_rules + [
|
] + base_rules + sql_rules + make_string_rules("'") + end_rules
|
||||||
RegionRule(r'string', "B'", BitStringGrammar, "'"),
|
|
||||||
RegionRule(r'string', "X'", HexStringGrammar, "'"),
|
|
||||||
RegionRule(r'string', "'", StringGrammar1, "'"),
|
|
||||||
] + end_rules
|
|
||||||
|
|
||||||
class SqlGrammar(Grammar):
|
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):
|
class SqlTabber(StackTabber):
|
||||||
wst = ('spaces', 'null', 'eol', 'function.body.spaces', 'function.body.eol')
|
wst = ('spaces', 'null', 'eol', 'function.body.spaces', 'function.body.eol')
|
||||||
|
@ -91,6 +84,20 @@ class SqlTabber(StackTabber):
|
||||||
if not highlighter.tokens[y]: return False
|
if not highlighter.tokens[y]: return False
|
||||||
t = highlighter.tokens[y][0]
|
t = highlighter.tokens[y][0]
|
||||||
return t.name == 'function'
|
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):
|
def _handle_other_token(self, currlvl, y, i):
|
||||||
w = self.mode.tabwidth
|
w = self.mode.tabwidth
|
||||||
token = self.get_token(y, i)
|
token = self.get_token(y, i)
|
||||||
|
@ -98,8 +105,13 @@ class SqlTabber(StackTabber):
|
||||||
fqname = token.fqname()
|
fqname = token.fqname()
|
||||||
|
|
||||||
unhandled = False
|
unhandled = False
|
||||||
if token.name == 'delimiter' and s == ';':
|
if token.name == 'delimiter':
|
||||||
self._opt_pop('cont')
|
if s == ';':
|
||||||
|
self._opt_pop('cont')
|
||||||
|
elif s == ',':
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
unhandled = True
|
||||||
elif token.name == 'eol':
|
elif token.name == 'eol':
|
||||||
pass
|
pass
|
||||||
elif token.name == 'spaces':
|
elif token.name == 'spaces':
|
||||||
|
@ -140,8 +152,9 @@ class SqlTabber(StackTabber):
|
||||||
else:
|
else:
|
||||||
unhandled = True
|
unhandled = True
|
||||||
|
|
||||||
#if self.is_rightmost_token(y, i) and unhandled:
|
if self.is_rightmost_token(y, i):
|
||||||
# self._opt_append('cont', currlvl + w)
|
if unhandled:
|
||||||
|
self._opt_append('cont', currlvl + w)
|
||||||
|
|
||||||
return currlvl
|
return currlvl
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue