/
scanner_command_global.py
59 lines (45 loc) · 1.55 KB
/
scanner_command_global.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
from .state import EOF
from .tokens import TokenEof
from .tokens_base import TOKEN_COMMAND_GLOBAL
from .tokens_base import TokenOfCommand
from .parser import parse_ex_command
from Vintageous.ex import register_ex_command
@register_ex_command('global', 'g')
class TokenCommandGlobal(TokenOfCommand):
def __init__(self, params, *args, **kwargs):
super().__init__(params,
TOKEN_COMMAND_GLOBAL,
'global', *args, **kwargs)
self.addressable = True
self.target_command = 'ex_global'
@property
def pattern(self):
return self.params['pattern']
@property
def subcommand(self):
return self.params['subcommand']
def scan_command_global(state):
params = {
'pattern': None,
'subcommand': parse_ex_command('print').command
}
c = state.consume()
bang = c == '!'
sep = c if not bang else c.consume()
# TODO: we're probably missing legal separators.
assert c in '!:?/\\&$', 'bad separator'
state.ignore()
while True:
c = state.consume()
if c == EOF:
raise ValueError('unexpected EOF in: ' + state.source)
if c == sep:
state.backup()
params['pattern'] = state.emit()
state.consume()
state.ignore()
break
command = state.match(r'.*$').group(0).strip()
command = parse_ex_command(command).command or params['subcommand']
params['subcommand'] = command
return None, [TokenCommandGlobal(params, forced=bang), TokenEof()]