tab bug fix... base format fix, awk improvements
--HG-- branch : pmacs2
This commit is contained in:
parent
357ca8dd07
commit
343d1c2383
|
@ -102,7 +102,7 @@ class Fundamental(Handler):
|
|||
actions = []
|
||||
_bindings = {}
|
||||
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_fg = 'default'
|
||||
|
|
70
mode/awk.py
70
mode/awk.py
|
@ -20,53 +20,54 @@ class RegexGrammar(Grammar):
|
|||
|
||||
class AwkGrammar(Grammar):
|
||||
rules = [
|
||||
PatternRule(r'comment', r'#.*\n$'),
|
||||
PatternRule(r'spaces', r' +'),
|
||||
RegionRule(r'awk_regex', r'/(?! )', RegexGrammar, r'/'),
|
||||
PatternRule('comment', r'#.*\n$'),
|
||||
PatternRule('spaces', ' +'),
|
||||
RegionRule('awk.regex', '/(?! )', RegexGrammar, '/'),
|
||||
|
||||
PatternMatchRule('x', r'(function)( +)(' + word + ')',
|
||||
'keyword', 'spaces', r'function'),
|
||||
PatternMatchRule('x', '(function)( +)(' + word + ')',
|
||||
'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(r'delimiter', r'(?:[\{\}()\[\]?:;,]|=(?!=)|\+=|-=|\*=|/=|\%=|\^=)'),
|
||||
PatternRule(r'keyword', r'(?: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.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('delimiter', r'(?:[\{\}()\[\]?:;,]|=(?!=)|\+=|-=|\*=|/=|\%=|\^=)'),
|
||||
PatternRule('awk.keyword', '(?:BEGIN|END|function|if|else|while|do|for|break|continue|delete|exit)(?!' + 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(r'number', r'-?0[0-7]*'),
|
||||
PatternRule(r'number', r'-?[0-9]+\.?[0-9]*'),
|
||||
PatternRule(r'number', r'-?\.[0-9]+'),
|
||||
PatternRule('awk.number', '-?0x[0-9A-Fa-f]+'),
|
||||
PatternRule('awk.number', '-?0[0-7]*'),
|
||||
PatternRule('awk.number', r'-?[0-9]+\.?[0-9]*'),
|
||||
PatternRule('awk.number', r'-?\.[0-9]+'),
|
||||
|
||||
PatternRule(r'operator', r'!(?![=~])|--|\+\+'),
|
||||
PatternRule(r'operator', r'(?:&&|\|\||<=|>=|!=|!~|==|\^|%|[-~/+*<>])'),
|
||||
PatternRule('awk.operator', r'!(?![=~])|--|\+\+'),
|
||||
PatternRule('awk.operator', r'(?:&&|\|\||<=|>=|!=|!~|==|\^|%|[-~/+*<>])'),
|
||||
|
||||
RegionRule(r'string', r'"', StringGrammar2, r'"'),
|
||||
PatternRule(r'awk_function', word + '(?=\()'),
|
||||
PatternRule(r'awk_identifier', word),
|
||||
RegionRule('awk.string', '"', StringGrammar2, '"'),
|
||||
PatternRule('awk.function', word + r'(?=\()'),
|
||||
PatternRule('awk_identifier', word),
|
||||
|
||||
PatternRule(r'continuation', r'\\\n$'),
|
||||
PatternRule(r'eol', r'\n'),
|
||||
PatternRule('continuation', r'\\\n$'),
|
||||
PatternRule('eol', r'\n'),
|
||||
]
|
||||
|
||||
class AwkTabber(StackTabber2):
|
||||
open_tokens = {'delimiter': {'{': '}', '(': ')', '[': ']'}}
|
||||
close_tokens = {'delimiter': {'}': '{', ')': '(', ']': '['}}
|
||||
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_tokens = {}
|
||||
def _is_base(self, y):
|
||||
if y == 0: return True
|
||||
t = self._get_tokens(y)[0]
|
||||
if t.fqname() == 'awk_regex.start': return True
|
||||
if t.name in ('awk_field', 'awk_global'): return True
|
||||
if t.name == 'keyword' and t.string in ('BEGIN', 'END'): return True
|
||||
if t.fqisa('awk.regex.start'): return True
|
||||
if t.isa('awk.field', 'awk.global'): return True
|
||||
if t.matchs('awk.keyword', ('BEGIN', 'END')): return True
|
||||
|
||||
return False
|
||||
def _is_indent(self, t): return t.name == 'spaces'
|
||||
def _is_ignored(self, t): return t.name in ('spaces', 'eol', 'comment')
|
||||
def _is_indent(self, t): return t.isa('spaces')
|
||||
def _is_ignored(self, t): return t.isa('spaces', 'eol', 'comment')
|
||||
|
||||
class AwkFilterFile(Exec):
|
||||
'''Filter a file through the current buffer's AWK program'''
|
||||
|
@ -149,14 +150,13 @@ class Awk(Fundamental):
|
|||
config = {'awk.cmd-opts': ""}
|
||||
actions = [AwkFilterFile, AwkFilterBuffer, AwkFilterInput]
|
||||
colors = {
|
||||
'awk_global': ('yellow', 'default', 'bold'),
|
||||
'awk_function': ('magenta', 'default', 'bold'),
|
||||
'awk_field': ('yellow', 'default', 'bold'),
|
||||
#'awk_identifier': ('yellow', 'default', 'bold'),
|
||||
'awk_regex.start': ('cyan', 'default', 'bold'),
|
||||
'awk_regex.null': ('cyan', 'default', 'bold'),
|
||||
'awk_regex.data': ('cyan', 'default', 'bold'),
|
||||
'awk_regex.end': ('cyan', 'default', 'bold'),
|
||||
'awk.global': ('yellow', 'default', 'bold'),
|
||||
'awk.function': ('magenta', 'default', 'bold'),
|
||||
'awk.field': ('yellow', 'default', 'bold'),
|
||||
'awk.regex.start': ('cyan', 'default', 'bold'),
|
||||
'awk.regex.null': ('cyan', 'default', 'bold'),
|
||||
'awk.regex.data': ('cyan', 'default', 'bold'),
|
||||
'awk.regex.end': ('cyan', 'default', 'bold'),
|
||||
}
|
||||
_bindings = {
|
||||
'close-paren': (')',),
|
||||
|
|
11
tab.py
11
tab.py
|
@ -375,14 +375,18 @@ class StackTabber2(Tabber):
|
|||
self.stack.pop()
|
||||
break
|
||||
else:
|
||||
raise Exception, "mismatched %r, line %d (expected %r)" % \
|
||||
(t.string, y, self.open_tokens[marker.type_][marker.name])
|
||||
msg = "mismatched %r, line %d (expected %r)"
|
||||
raise Exception, msg % (t.string, y, s)
|
||||
else:
|
||||
raise Exception, "what? %r" % marker.name
|
||||
if i == 0:
|
||||
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
|
||||
top = self._peek()
|
||||
atscope = True
|
||||
|
@ -395,7 +399,6 @@ class StackTabber2(Tabber):
|
|||
if s not in self.close_scope_tokens.get(name, set()):
|
||||
nextlvl = self._get_next_level()
|
||||
self._append_unless('continue', name, nextlvl, y)
|
||||
#XYZYZYXYXY
|
||||
|
||||
def _is_open_token(self, t):
|
||||
return t.string in self.open_tokens.get(t.name, set())
|
||||
|
|
Loading…
Reference in New Issue