Merge pull request #3011 from xonsh/linecont

fixed indentation errors
This commit is contained in:
Gil Forsyth 2019-02-05 09:02:09 -05:00 committed by GitHub
commit 080afa7eaa
Failed to generate hash of commit
4 changed files with 41 additions and 0 deletions

24
news/linecont.rst Normal file
View file

@ -0,0 +1,24 @@
**Added:**
* <news item>
**Changed:**
* <news item>
**Deprecated:**
* <news item>
**Removed:**
* <news item>
**Fixed:**
* Fixed regression with line continuations in implicit subprocess mode within
indented blocks of code, such as if-statements.
**Security:**
* <news item>

View file

@ -133,6 +133,7 @@ def test_echo_line_cont():
"echo a and \\\necho b\n", "echo a and \\\necho b\n",
"echo a \\\n or echo b\n", "echo a \\\n or echo b\n",
"echo a \\\n or echo b and \\\n echo c\n", "echo a \\\n or echo b and \\\n echo c\n",
"if True:\\\n echo a \\\n b\n",
], ],
) )
def test_two_echo_line_cont(code): def test_two_echo_line_cont(code):

View file

@ -14,6 +14,7 @@ from xonsh.tools import (
get_logical_line, get_logical_line,
replace_logical_line, replace_logical_line,
balanced_parens, balanced_parens,
starting_whitespace,
) )
from xonsh.built_ins import load_builtins, unload_builtins, load_proxies, unload_proxies from xonsh.built_ins import load_builtins, unload_builtins, load_proxies, unload_proxies
@ -207,6 +208,9 @@ class Execer(object):
greedy = False greedy = False
if filename is None: if filename is None:
filename = self.filename filename = self.filename
if logical_input:
beg_spaces = starting_whitespace(input)
input = input[len(beg_spaces) :]
while not parsed: while not parsed:
try: try:
tree = self.parser.parse( tree = self.parser.parse(
@ -313,4 +317,6 @@ class Execer(object):
replace_logical_line(lines, sbpline, idx, nlogical) replace_logical_line(lines, sbpline, idx, nlogical)
last_error_col += 3 last_error_col += 3
input = "\n".join(lines) input = "\n".join(lines)
if logical_input:
input = beg_spaces + input
return tree, input return tree, input

View file

@ -616,6 +616,16 @@ def subexpr_before_unbalanced(expr, ltok, rtok):
return subexpr return subexpr
@lazyobject
def STARTING_WHITESPACE_RE():
return re.compile(r"^(\s*)")
def starting_whitespace(s):
"""Returns the whitespace at the start of a string"""
return STARTING_WHITESPACE_RE.match(s).group(1)
def decode(s, encoding=None): def decode(s, encoding=None):
encoding = encoding or DEFAULT_ENCODING encoding = encoding or DEFAULT_ENCODING
return s.decode(encoding, "replace") return s.decode(encoding, "replace")