only issue one ws

This commit is contained in:
Anthony Scopatz 2017-03-02 00:19:03 -05:00
parent c59b534861
commit f9d6c8660f
4 changed files with 46 additions and 8 deletions

View file

@ -245,7 +245,7 @@ def test_not_really_or_pre_post():
assert check_tokens(inp, exp)
def test_subproc_line_cont():
def test_subproc_line_cont_space():
inp = ("![echo --option1 value1 \\\n"
" --option2 value2 \\\n"
" --optionZ valueZ]")
@ -259,14 +259,42 @@ def test_subproc_line_cont():
('WS', ' ', 16),
('NAME', 'value1', 17),
('WS', ' ', 23),
('WS', ' ', 24),
('MINUS', '-', 5),
('MINUS', '-', 6),
('NAME', 'option2', 7),
('WS', ' ', 14),
('NAME', 'value2', 15),
('WS', ' ', 21),
('WS', ' ', 22),
('MINUS', '-', 5),
('MINUS', '-', 6),
('NAME', 'optionZ', 7),
('WS', ' ', 14),
('NAME', 'valueZ', 15),
('RBRACKET',']', 21),
]
assert check_tokens(inp, exp)
def test_subproc_line_cont_nospace():
inp = ("![echo --option1 value1\\\n"
" --option2 value2\\\n"
" --optionZ valueZ]")
exp = [
('BANG_LBRACKET', '![', 0),
('NAME', 'echo', 2),
('WS', ' ', 6),
('MINUS', '-', 7),
('MINUS', '-', 8),
('NAME', 'option1', 9),
('WS', ' ', 16),
('NAME', 'value1', 17),
('WS', '\\', 23),
('MINUS', '-', 5),
('MINUS', '-', 6),
('NAME', 'option2', 7),
('WS', ' ', 14),
('NAME', 'value2', 15),
('WS', '\\', 21),
('MINUS', '-', 5),
('MINUS', '-', 6),
('NAME', 'optionZ', 7),

View file

@ -181,7 +181,8 @@ class Execer(object):
last_error_line = e.loc.lineno
idx = last_error_line - 1
lines = input.splitlines()
line, nlogical = get_logical_line(lines, idx)
line, nlogical, idx = get_logical_line(lines, idx)
print(repr(line), nlogical, idx)
if input.endswith('\n'):
lines.append('')
if len(line.strip()) == 0:

View file

@ -150,8 +150,11 @@ def handle_error_linecont(state, token):
"""
if state['pymode'][-1][0]:
return
prev = state['last']
if prev.end != token.start:
return # previous token is separated by whitespace
state['last'] = token
yield _new_token('WS', ' ', token.start)
yield _new_token('WS', '\\', token.start)
def handle_error_token(state, token):

View file

@ -318,7 +318,9 @@ def subproc_toks(line, mincol=-1, maxcol=None, lexer=None, returnline=False,
if pos < mincol:
continue
toks.append(tok)
if tok.type == 'NEWLINE':
if tok.type == 'WS' and tok.value == '\\':
pass # line continuation
elif tok.type == 'NEWLINE':
break
elif tok.type == 'DEDENT':
# fake a newline when dedenting without a newline
@ -423,9 +425,13 @@ def get_logical_line(lines, idx):
"""
n = 1
nlines = len(lines)
line = lines[idx]
linecont = str(LINE_CONTINUATION)
while idx > 0 and lines[idx-1].endswith(linecont):
idx -= 1
start = idx
line = lines[idx]
open_triple = _have_open_triple_quotes(line)
print(idx)
while (line.endswith(linecont) or open_triple) and idx < nlines:
n += 1
idx += 1
@ -434,7 +440,7 @@ def get_logical_line(lines, idx):
else:
line = line + '\n' + lines[idx]
open_triple = _have_open_triple_quotes(line)
return line, n
return line, n, start
def replace_logical_line(lines, logical, idx, n):