tab bug fix... base format fix, awk improvements

--HG--
branch : pmacs2
This commit is contained in:
moculus 2009-04-06 15:21:43 +00:00
parent 357ca8dd07
commit 343d1c2383
3 changed files with 43 additions and 40 deletions

View File

@ -102,7 +102,7 @@ class Fundamental(Handler):
actions = [] actions = []
_bindings = {} _bindings = {}
completers = {} completers = {}
format = "%(flag)s %(bname)-18s (%(mname)s) %(indent)s %(cursor)s %(perc)s %(vc-info)s" format = "%(flag)s %(bname)s (%(mname)s) %(indent)s %(cursor)s %(perc)s %(vc-info)s"
header_size = 3 header_size = 3
header_fg = 'default' header_fg = 'default'

View File

@ -20,53 +20,54 @@ class RegexGrammar(Grammar):
class AwkGrammar(Grammar): class AwkGrammar(Grammar):
rules = [ rules = [
PatternRule(r'comment', r'#.*\n$'), PatternRule('comment', r'#.*\n$'),
PatternRule(r'spaces', r' +'), PatternRule('spaces', ' +'),
RegionRule(r'awk_regex', r'/(?! )', RegexGrammar, r'/'), RegionRule('awk.regex', '/(?! )', RegexGrammar, '/'),
PatternMatchRule('x', r'(function)( +)(' + word + ')', PatternMatchRule('x', '(function)( +)(' + word + ')',
'keyword', 'spaces', r'function'), 'awk.keyword', 'spaces', 'awk.function'),
PatternRule(r'awk_global', r'(?:TEXTDOMAIN|SUBSEP|RLENGTH|RSTART|RT|RS|PROCINFO|ORS|OFS|OFMT|NR|NF|LINT|IGNORECASE|FS|FNR|FILENAME|FIELDWIDTHS|ERRNO|ENVIRON|CONVFMT|BINMODE|ARGV|ARGIND|ARGC)(?!' + chr2 + ')'), PatternRule('awk.global', '(?:TEXTDOMAIN|SUBSEP|RLENGTH|RSTART|RT|RS|PROCINFO|ORS|OFS|OFMT|NR|NF|LINT|IGNORECASE|FS|FNR|FILENAME|FIELDWIDTHS|ERRNO|ENVIRON|CONVFMT|BINMODE|ARGV|ARGIND|ARGC)(?!' + chr2 + ')'),
PatternRule(r'delimiter', r'(?:[\{\}()\[\]?:;,]|=(?!=)|\+=|-=|\*=|/=|\%=|\^=)'), PatternRule('delimiter', r'(?:[\{\}()\[\]?:;,]|=(?!=)|\+=|-=|\*=|/=|\%=|\^=)'),
PatternRule(r'keyword', r'(?:BEGIN|END|function|if|else|while|do|for|break|continue|delete|exit)(?!' + chr2 + ')'), PatternRule('awk.keyword', '(?:BEGIN|END|function|if|else|while|do|for|break|continue|delete|exit)(?!' + chr2 + ')'),
PatternRule(r'builtin', r'(?:return|close|getline|nextfile|next|printf|print|system|fflush|atan2|cos|exp|int|log|rand|sin|sqrt|srand|asorti|asort|gensub|gsub|index|length|match|split|sprintf|strtonum|substr|sub|tolower|toupper|mktime|strftime|systime|and|compl|lshift|or|xor|rshift|bindtextdomain|dcgettext|dcngettext|extension)(?!' + chr2 + ')'), PatternRule('awk.builtin', '(?:return|close|getline|nextfile|next|printf|print|system|fflush|atan2|cos|exp|int|log|rand|sin|sqrt|srand|asorti|asort|gensub|gsub|index|length|match|split|sprintf|strtonum|substr|sub|tolower|toupper|mktime|strftime|systime|and|compl|lshift|or|xor|rshift|bindtextdomain|dcgettext|dcngettext|extension)(?!' + chr2 + ')'),
PatternRule(r'awk_field', r'\$\d*'), PatternRule('awk.field', r'\$\d*'),
PatternRule(r'number', r'-?0x[0-9A-Fa-f]+'), PatternRule('awk.number', '-?0x[0-9A-Fa-f]+'),
PatternRule(r'number', r'-?0[0-7]*'), PatternRule('awk.number', '-?0[0-7]*'),
PatternRule(r'number', r'-?[0-9]+\.?[0-9]*'), PatternRule('awk.number', r'-?[0-9]+\.?[0-9]*'),
PatternRule(r'number', r'-?\.[0-9]+'), PatternRule('awk.number', r'-?\.[0-9]+'),
PatternRule(r'operator', r'!(?![=~])|--|\+\+'), PatternRule('awk.operator', r'!(?![=~])|--|\+\+'),
PatternRule(r'operator', r'(?:&&|\|\||<=|>=|!=|!~|==|\^|%|[-~/+*<>])'), PatternRule('awk.operator', r'(?:&&|\|\||<=|>=|!=|!~|==|\^|%|[-~/+*<>])'),
RegionRule(r'string', r'"', StringGrammar2, r'"'), RegionRule('awk.string', '"', StringGrammar2, '"'),
PatternRule(r'awk_function', word + '(?=\()'), PatternRule('awk.function', word + r'(?=\()'),
PatternRule(r'awk_identifier', word), PatternRule('awk_identifier', word),
PatternRule(r'continuation', r'\\\n$'), PatternRule('continuation', r'\\\n$'),
PatternRule(r'eol', r'\n'), PatternRule('eol', r'\n'),
] ]
class AwkTabber(StackTabber2): class AwkTabber(StackTabber2):
open_tokens = {'delimiter': {'{': '}', '(': ')', '[': ']'}} open_tokens = {'delimiter': {'{': '}', '(': ')', '[': ']'}}
close_tokens = {'delimiter': {'}': '{', ')': '(', ']': '['}} close_tokens = {'delimiter': {'}': '{', ')': '(', ']': '['}}
control_tokens = { control_tokens = {
'keyword': {'if': 1, 'else': 1, 'while': 1, 'do': 1, 'for': 1}, 'awk.keyword': set(['if', 'else', 'while', 'do', 'for'])
} }
end_at_eof = True end_at_eof = True
end_at_tokens = {} end_at_tokens = {}
def _is_base(self, y): def _is_base(self, y):
if y == 0: return True if y == 0: return True
t = self._get_tokens(y)[0] t = self._get_tokens(y)[0]
if t.fqname() == 'awk_regex.start': return True if t.fqisa('awk.regex.start'): return True
if t.name in ('awk_field', 'awk_global'): return True if t.isa('awk.field', 'awk.global'): return True
if t.name == 'keyword' and t.string in ('BEGIN', 'END'): return True if t.matchs('awk.keyword', ('BEGIN', 'END')): return True
return False return False
def _is_indent(self, t): return t.name == 'spaces' def _is_indent(self, t): return t.isa('spaces')
def _is_ignored(self, t): return t.name in ('spaces', 'eol', 'comment') def _is_ignored(self, t): return t.isa('spaces', 'eol', 'comment')
class AwkFilterFile(Exec): class AwkFilterFile(Exec):
'''Filter a file through the current buffer's AWK program''' '''Filter a file through the current buffer's AWK program'''
@ -149,14 +150,13 @@ class Awk(Fundamental):
config = {'awk.cmd-opts': ""} config = {'awk.cmd-opts': ""}
actions = [AwkFilterFile, AwkFilterBuffer, AwkFilterInput] actions = [AwkFilterFile, AwkFilterBuffer, AwkFilterInput]
colors = { colors = {
'awk_global': ('yellow', 'default', 'bold'), 'awk.global': ('yellow', 'default', 'bold'),
'awk_function': ('magenta', 'default', 'bold'), 'awk.function': ('magenta', 'default', 'bold'),
'awk_field': ('yellow', 'default', 'bold'), 'awk.field': ('yellow', 'default', 'bold'),
#'awk_identifier': ('yellow', 'default', 'bold'), 'awk.regex.start': ('cyan', 'default', 'bold'),
'awk_regex.start': ('cyan', 'default', 'bold'), 'awk.regex.null': ('cyan', 'default', 'bold'),
'awk_regex.null': ('cyan', 'default', 'bold'), 'awk.regex.data': ('cyan', 'default', 'bold'),
'awk_regex.data': ('cyan', 'default', 'bold'), 'awk.regex.end': ('cyan', 'default', 'bold'),
'awk_regex.end': ('cyan', 'default', 'bold'),
} }
_bindings = { _bindings = {
'close-paren': (')',), 'close-paren': (')',),

11
tab.py
View File

@ -375,14 +375,18 @@ class StackTabber2(Tabber):
self.stack.pop() self.stack.pop()
break break
else: else:
raise Exception, "mismatched %r, line %d (expected %r)" % \ msg = "mismatched %r, line %d (expected %r)"
(t.string, y, self.open_tokens[marker.type_][marker.name]) raise Exception, msg % (t.string, y, s)
else: else:
raise Exception, "what? %r" % marker.name raise Exception, "what? %r" % marker.name
if i == 0: if i == 0:
self._save_curr_level() self._save_curr_level()
# add implicit continuation XYZYXYZY # if we don't want implicit continuation, return.
if self.end_at_eof:
return
# if we do want implicit continuation, see if we need it.
name, s = t.fqname(), t.string name, s = t.fqname(), t.string
top = self._peek() top = self._peek()
atscope = True atscope = True
@ -395,7 +399,6 @@ class StackTabber2(Tabber):
if s not in self.close_scope_tokens.get(name, set()): if s not in self.close_scope_tokens.get(name, set()):
nextlvl = self._get_next_level() nextlvl = self._get_next_level()
self._append_unless('continue', name, nextlvl, y) self._append_unless('continue', name, nextlvl, y)
#XYZYZYXYXY
def _is_open_token(self, t): def _is_open_token(self, t):
return t.string in self.open_tokens.get(t.name, set()) return t.string in self.open_tokens.get(t.name, set())