parent
a235355533
commit
4c63cdcd60
42
mode/awk.py
42
mode/awk.py
|
@ -53,18 +53,15 @@ class AwkGrammar(Grammar):
|
||||||
class AwkTabber(StackTabber2):
|
class AwkTabber(StackTabber2):
|
||||||
open_tokens = {'delimiter': {'{': '}', '(': ')', '[': ']'}}
|
open_tokens = {'delimiter': {'{': '}', '(': ')', '[': ']'}}
|
||||||
close_tokens = {'delimiter': {'}': '{', ')': '(', ']': '['}}
|
close_tokens = {'delimiter': {'}': '{', ')': '(', ']': '['}}
|
||||||
control_tokens = {
|
control_tokens = {'awk.keyword': set(['if', 'else', 'while', 'do', 'for'])}
|
||||||
'awk.keyword': set(['if', 'else', 'while', 'do', 'for'])
|
end_at_eof = True
|
||||||
}
|
end_at_tokens = {}
|
||||||
end_at_eof = True
|
|
||||||
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.fqisa('awk.regex.start'): return True
|
if t.fqisa('awk.regex.start'): return True
|
||||||
if t.isa('awk.field', 'awk.global'): return True
|
if t.isa('awk.field', 'awk.global'): return True
|
||||||
if t.matchs('awk.keyword', ('BEGIN', 'END')): return True
|
if t.matchs('awk.keyword', ('BEGIN', 'END')): return True
|
||||||
|
|
||||||
return False
|
return False
|
||||||
def _is_indent(self, t): return t.isa('spaces')
|
def _is_indent(self, t): return t.isa('spaces')
|
||||||
def _is_ignored(self, t): return t.isa('spaces', 'eol', 'comment')
|
def _is_ignored(self, t): return t.isa('spaces', 'eol', 'comment')
|
||||||
|
@ -72,17 +69,17 @@ class AwkTabber(StackTabber2):
|
||||||
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'''
|
||||||
show_success = True
|
show_success = True
|
||||||
args = [arg('path', dt="path", p="Filter File: ", dv=default.path_dirname,
|
args = [arg('path', dt='path', p='Filter File: ', dv=default.path_dirname,
|
||||||
ld=True, h="file to open")]
|
ld=True, h='file to open')]
|
||||||
def _execute(self, w, **vargs):
|
def _execute(self, w, **vargs):
|
||||||
if not hasattr(w.buffer, 'path'):
|
if not hasattr(w.buffer, 'path'):
|
||||||
w.set_error("Buffer %r has no program" % w.buffer.name())
|
w.set_error('Buffer %r has no program' % w.buffer.name())
|
||||||
return
|
return
|
||||||
elif w.buffer.changed():
|
elif w.buffer.changed():
|
||||||
w.set_error("Buffer %r is not saved" % w.buffer.name())
|
w.set_error('Buffer %r is not saved' % w.buffer.name())
|
||||||
return
|
return
|
||||||
elif not os.path.exists(vargs['path']):
|
elif not os.path.exists(vargs['path']):
|
||||||
w.set_error("File %r not found" % vargs['path'])
|
w.set_error('File %r not found' % vargs['path'])
|
||||||
return
|
return
|
||||||
|
|
||||||
cmd = 'awk -f %r %r' % (w.buffer.path, vargs['path'])
|
cmd = 'awk -f %r %r' % (w.buffer.path, vargs['path'])
|
||||||
|
@ -90,20 +87,21 @@ class AwkFilterFile(Exec):
|
||||||
outdata = pipe.stdout.read()
|
outdata = pipe.stdout.read()
|
||||||
status = pipe.wait() >> 8
|
status = pipe.wait() >> 8
|
||||||
w.application.data_buffer('*Awk-Output*', outdata, switch_to=True)
|
w.application.data_buffer('*Awk-Output*', outdata, switch_to=True)
|
||||||
w.set_error("awk exited with status %d" % status)
|
w.set_error('awk exited with status %d' % status)
|
||||||
|
|
||||||
class AwkFilterBuffer(Pipe):
|
class AwkFilterBuffer(Pipe):
|
||||||
'''Filter a buffer through the current buffer's AWK program'''
|
'''Filter a buffer through the current buffer's AWK program'''
|
||||||
args = [arg('name', dt="buffer", p="Filter Buffer: ", h="name of the buffer to switch to")]
|
args = [arg('name', dt='buffer', p='Filter Buffer: ',
|
||||||
|
h='name of the buffer to switch to')]
|
||||||
def _execute(self, w, **vargs):
|
def _execute(self, w, **vargs):
|
||||||
if not hasattr(w.buffer, 'path'):
|
if not hasattr(w.buffer, 'path'):
|
||||||
w.set_error("Buffer %r has no program" % w.buffer.name())
|
w.set_error('Buffer %r has no program' % w.buffer.name())
|
||||||
return
|
return
|
||||||
elif w.buffer.changed():
|
elif w.buffer.changed():
|
||||||
w.set_error("Buffer %r is not saved" % w.buffer.name())
|
w.set_error('Buffer %r is not saved' % w.buffer.name())
|
||||||
return
|
return
|
||||||
elif not w.application.has_buffer_name(vargs['name']):
|
elif not w.application.has_buffer_name(vargs['name']):
|
||||||
w.set_error("Buffer %r not found" % vargs['name'])
|
w.set_error('Buffer %r not found' % vargs['name'])
|
||||||
return
|
return
|
||||||
|
|
||||||
b = w.application.bufferlist.get_buffer_by_name(vargs['name'])
|
b = w.application.bufferlist.get_buffer_by_name(vargs['name'])
|
||||||
|
@ -115,17 +113,17 @@ class AwkFilterBuffer(Pipe):
|
||||||
output = pipe.stdout.read()
|
output = pipe.stdout.read()
|
||||||
status = pipe.wait() >> 8
|
status = pipe.wait() >> 8
|
||||||
w.application.data_buffer('*Awk-Output*', output, switch_to=True)
|
w.application.data_buffer('*Awk-Output*', output, switch_to=True)
|
||||||
w.set_error("awk exited with status %d" % status)
|
w.set_error('awk exited with status %d' % status)
|
||||||
|
|
||||||
class AwkFilterInput(Method):
|
class AwkFilterInput(Method):
|
||||||
'''Filter input through the current buffer's AWK program'''
|
'''Filter input through the current buffer's AWK program'''
|
||||||
args = [arg('input', p="Data To Filter: ", h="data to filter")]
|
args = [arg('input', p='Data To Filter: ', h='data to filter')]
|
||||||
def _execute(self, w, **vargs):
|
def _execute(self, w, **vargs):
|
||||||
if not hasattr(w.buffer, 'path'):
|
if not hasattr(w.buffer, 'path'):
|
||||||
w.set_error("Buffer %r has no program" % w.buffer.name())
|
w.set_error('Buffer %r has no program' % w.buffer.name())
|
||||||
return
|
return
|
||||||
elif w.buffer.changed():
|
elif w.buffer.changed():
|
||||||
w.set_error("Buffer %r is not saved" % w.buffer.name())
|
w.set_error('Buffer %r is not saved' % w.buffer.name())
|
||||||
return
|
return
|
||||||
|
|
||||||
opts = w.application.config['awk.cmd-opts']
|
opts = w.application.config['awk.cmd-opts']
|
||||||
|
@ -136,7 +134,7 @@ class AwkFilterInput(Method):
|
||||||
output = pipe.stdout.read()
|
output = pipe.stdout.read()
|
||||||
status = pipe.wait() >> 8
|
status = pipe.wait() >> 8
|
||||||
w.application.data_buffer('*Awk-Output*', output, switch_to=True)
|
w.application.data_buffer('*Awk-Output*', output, switch_to=True)
|
||||||
w.set_error("awk exited with status %d" % status)
|
w.set_error('awk exited with status %d' % status)
|
||||||
|
|
||||||
class Awk(Fundamental):
|
class Awk(Fundamental):
|
||||||
name = 'awk'
|
name = 'awk'
|
||||||
|
@ -147,7 +145,7 @@ class Awk(Fundamental):
|
||||||
opentags = {'(': ')', '[': ']', '{': '}'}
|
opentags = {'(': ')', '[': ']', '{': '}'}
|
||||||
closetokens = ('delimiter',)
|
closetokens = ('delimiter',)
|
||||||
closetags = {')': '(', ']': '[', '}': '{'}
|
closetags = {')': '(', ']': '[', '}': '{'}
|
||||||
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'),
|
||||||
|
|
Loading…
Reference in New Issue