/
scanner_command_exit.py
62 lines (49 loc) · 1.7 KB
/
scanner_command_exit.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_EXIT
from .tokens_base import TokenOfCommand
from Vintageous.ex import register_ex_command
@register_ex_command('exit', 'exi')
@register_ex_command('xit', 'x')
class TokenCommandExit(TokenOfCommand):
def __init__(self, params, *args, **kwargs):
super().__init__(params,
TOKEN_COMMAND_EXIT,
'exit', *args, **kwargs)
self.addressable = True
self.target_command = 'ex_exit'
def scan_command_exit(state):
params = {
'file_name': '',
}
bang = state.consume()
if bang == EOF:
return None, [TokenCommandExit(params), TokenEof()]
bang = bang == '!'
if not bang:
state.backup()
state.skip(' ')
state.ignore()
while True:
c = state.consume()
if c == EOF:
return None, [TokenCommandExit(params, forced=bang), TokenEof()]
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()
continue
if c != ' ':
state.match(r'.*')
params['file_name'] = state.emit().strip()
state.skip(' ')
state.ignore()
state.expect(EOF)
return None, [TokenCommandExit (params, forced=bang == '!'), TokenEof ()]