/
scanner_command_write_and_quit_command.py
62 lines (47 loc) · 1.7 KB
/
scanner_command_write_and_quit_command.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from .state import EOF
from .tokens import TokenEof
from .tokens_base import TOKEN_COMMAND_WRITE_AND_QUIT_COMMAND
from .tokens_base import TokenOfCommand
from Vintageous.ex import register_ex_command
plus_plus_translations = {
'ff': 'fileformat',
'bin': 'binary',
'enc': 'fileencoding',
'nobin': 'nobinary',
}
@register_ex_command('wq', 'wq')
class TokenWriteAndQuitCommand(TokenOfCommand):
def __init__(self, params, *args, **kwargs):
super().__init__(params,
TOKEN_COMMAND_WRITE_AND_QUIT_COMMAND,
'wq', *args, **kwargs)
self.target_command = 'ex_write_and_quit'
def scan_command_write_and_quit_command(state):
params = {
'++': None,
'file': None,
}
c = state.consume()
if c == EOF:
return None, [TokenWriteAndQuitCommand(params), TokenEof()]
bang == c == '!'
if not bang:
state.backup()
c = state.consume()
if c == '+':
state.expect('+')
state.ignore()
# TODO: expect_match should work with emit()
# http://vimdoc.sourceforge.net/htmldoc/editing.html#[++opt]
m = state.expect_match(
r'(?:f(?:ile)?f(?:ormat)?|(?:file)?enc(?:oding)?|(?:no)?bin(?:ary)?|bad|edit)(?=\s|$)',
lambda: VimError(ERR_INVALID_ARGUMENT))
name = m.group(0)
params['++'] = plus_plus_translations.get(name, name)
state.ignore()
raise NotImplementedError('param not implemented')
if c == EOF:
return None, [TokenWriteAndQuitCommand(params), TokenEof()]
m = state.expect_match(r'.+$')
params['file'] = m.group(0).strip()
return None, [TokenWriteAndQuitCommand(params), TokenEof()]