Repository: xonsh/xonsh

Issue:
`\` fails to separate lines
I tried 
```
git pull upstream master \
or git pull origin master \
or git pull @(rc.remote) master \
or git pull @(rc.remote) @(rc.branch) \
or git pull
```

and xonsh was not happy:
```python
../../mc/envs/regro/lib/python3.6/site-packages/_pytest/python.py:403: in _importtestmodule
    mod = self.fspath.pyimport(ensuresyspath=importmode)
../../mc/envs/regro/lib/python3.6/site-packages/py/_path/local.py:668: in pyimport
    __import__(modname)
<frozen importlib._bootstrap>:971: in _find_and_load
    ???
<frozen importlib._bootstrap>:955: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:656: in _load_unlocked
    ???
<frozen importlib._bootstrap>:626: in _load_backward_compatible
    ???
../../mc/envs/regro/lib/python3.6/site-packages/_pytest/assertion/rewrite.py:212: in load_module
    py.builtin.exec_(co, mod.__dict__)
tests/test_validate.py:8: in <module>
    from regolith.main import main
regolith/main.py:11: in <module>
    from regolith.database import connect
<frozen importlib._bootstrap>:971: in _find_and_load
    ???
<frozen importlib._bootstrap>:955: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:665: in _load_unlocked
    ???
<frozen importlib._bootstrap_external>:674: in exec_module
    ???
../../mc/envs/regro/lib/python3.6/site-packages/xonsh/__amalgam__.py:20145: in get_code
    code = execer.compile(src, glbs=ctx, locs=ctx)
../../mc/envs/regro/lib/python3.6/site-packages/xonsh/__amalgam__.py:19877: in compile
    transform=transform)
../../mc/envs/regro/lib/python3.6/site-packages/xonsh/__amalgam__.py:19846: in parse
    tree, input = self._parse_ctx_free(input, mode=mode, filename=filename)
../../mc/envs/regro/lib/python3.6/site-packages/xonsh/__amalgam__.py:19946: in _parse_ctx_free
    raise original_error from None
../../mc/envs/regro/lib/python3.6/site-packages/xonsh/__amalgam__.py:19933: in _parse_ctx_free
    debug_level=(self.debug_level > 2))
../../mc/envs/regro/lib/python3.6/site-packages/xonsh/parsers/base.py:349: in parse
    tree = self.parser.parse(input=s, lexer=self.lexer, debug=debug_level)
../../mc/envs/regro/lib/python3.6/site-packages/ply/yacc.py:331: in parse
    return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)
../../mc/envs/regro/lib/python3.6/site-packages/ply/yacc.py:1199: in parseopt_notrack
    tok = call_errorfunc(self.errorfunc, errtoken, self)
../../mc/envs/regro/lib/python3.6/site-packages/ply/yacc.py:193: in call_errorfunc
    r = errorfunc(token)
../../mc/envs/regro/lib/python3.6/site-packages/xonsh/parsers/base.py:2741: in p_error
    column=p.lexpos))
../../mc/envs/regro/lib/python3.6/site-packages/xonsh/parsers/base.py:482: in _parse_error
    raise err
E     File "<string>", line None
E   SyntaxError: /home/christopher/dev/regolith/regolith/database.xsh:34:16: ('code: pull',)
E               git pull upstream master \
```

Discussion:

Patch:
diff --git a/.travis.yml b/.travis.yml
index dfabd2b4..5a662188 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -30,7 +30,8 @@ matrix:
           language: generic
           env: PYTHON="3.7" MINICONDA_OS="MacOSX"
     allow_failures:
-        - python: ["nightly", "pypy3"]
+        - python: "nightly"
+        - python: "pypy3"
 
 before_install:
   - if [[ ! ("$TRAVIS_PYTHON_VERSION" == "nightly" || "$TRAVIS_PYTHON_VERSION" == "3.6-dev") && ! $BUILD_DOCS ]]; then
diff --git a/news/multiwrap2.rst b/news/multiwrap2.rst
new file mode 100644
index 00000000..e9a6c141
--- /dev/null
+++ b/news/multiwrap2.rst
@@ -0,0 +1,20 @@
+**Added:** None
+
+**Changed:** None
+
+**Deprecated:** None
+
+**Removed:** None
+
+**Fixed:**
+
+* Fixed automatic wrapping of many subprocesses that spanned multiple lines via
+  line continuation characters with logical operators separating the commands.
+  For example, the following now works:
+
+  .. code-block:: sh
+
+        echo 'a' \
+        and echo 'b'
+
+**Security:** None
diff --git a/xonsh/execer.py b/xonsh/execer.py
index f9775a5d..dc2e9788 100644
--- a/xonsh/execer.py
+++ b/xonsh/execer.py
@@ -151,7 +151,18 @@ class Execer(object):
             return None  # handles comment only input
         return exec(code, glbs, locs)
 
-    def _parse_ctx_free(self, input, mode='exec', filename=None):
+    def _print_debug_wrapping(self, line, sbpline, last_error_line, last_error_col,
+                              maxcol=None):
+        """print some debugging info if asked for."""
+        if self.debug_level > 1:
+            msg = ('{0}:{1}:{2}{3} - {4}\n'
+                   '{0}:{1}:{2}{3} + {5}')
+            mstr = '' if maxcol is None else ':' + str(maxcol)
+            msg = msg.format(self.filename, last_error_line,
+                             last_error_col, mstr, line, sbpline)
+            print(msg, file=sys.stderr)
+
+    def _parse_ctx_free(self, input, mode='exec', filename=None, logical_input=False):
         last_error_line = last_error_col = -1
         parsed = False
         original_error = None
@@ -184,6 +195,16 @@ class Execer(object):
                 idx = last_error_line - 1
                 lines = input.splitlines()
                 line, nlogical, idx = get_logical_line(lines, idx)
+                if nlogical > 1 and not logical_input:
+                    _, sbpline = self._parse_ctx_free(line, mode=mode,
+                                                      filename=filename,
+                                                      logical_input=True)
+                    self._print_debug_wrapping(line, sbpline, last_error_line,
+                                               last_error_col, maxcol=None)
+                    replace_logical_line(lines, sbpline, idx, nlogical)
+                    last_error_col += 3
+                    input = '\n'.join(lines)
+                    continue
                 if input.endswith('\n'):
                     lines.append('')
                 if len(line.strip()) == 0:
@@ -239,17 +260,10 @@ class Execer(object):
                         continue
                     else:
                         raise original_error
-                else:
-                    # print some debugging info
-                    if self.debug_level > 1:
-                        msg = ('{0}:{1}:{2}{3} - {4}\n'
-                               '{0}:{1}:{2}{3} + {5}')
-                        mstr = '' if maxcol is None else ':' + str(maxcol)
-                        msg = msg.format(self.filename, last_error_line,
-                                         last_error_col, mstr, line, sbpline)
-                        print(msg, file=sys.stderr)
-                    # replace the line
-                    replace_logical_line(lines, sbpline, idx, nlogical)
+                # replace the line
+                self._print_debug_wrapping(line, sbpline, last_error_line,
+                                           last_error_col, maxcol=maxcol)
+                replace_logical_line(lines, sbpline, idx, nlogical)
                 last_error_col += 3
                 input = '\n'.join(lines)
         return tree, input


Test patch:
diff --git a/tests/test_execer.py b/tests/test_execer.py
index 17b44079..1c03054c 100644
--- a/tests/test_execer.py
+++ b/tests/test_execer.py
@@ -121,4 +121,10 @@ def test_echo_line_cont():
     code = 'echo "1 \\\n2"\n'
     assert check_parse(code)
 
-
+@pytest.mark.parametrize('code', [
+    "echo a and \\\necho b\n",
+    "echo a \\\n or echo b\n",
+    "echo a \\\n or echo b and \\\n echo c\n",
+])
+def test_two_echo_line_cont(code):
+    assert check_parse(code)