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:
Using xonsh/0.6.5
Thanks for reporting @CJ-Wright! Can you provide a minimal example, probably with echo, or something that doesn't touch a git repo? Thanks!
I can confirm that:
```
echo 'a' \
and echo 'b'

xonsh: To log full traceback to a file set: $XONSH_TRACEBACK_LOGFILE = <filename>
Traceback (most recent call last):
  File "/usr/lib/python3.7/site-packages/xonsh/ptk/shell.py", line 138, in _push
    locs=None)
  File "/usr/lib/python3.7/site-packages/xonsh/__amalgam__.py", line 20084, in compile
    transform=transform)
  File "/usr/lib/python3.7/site-packages/xonsh/__amalgam__.py", line 20053, in parse
    tree, input = self._parse_ctx_free(input, mode=mode, filename=filename)
  File "/usr/lib/python3.7/site-packages/xonsh/__amalgam__.py", line 20153, in _parse_ctx_free
    raise original_error from None
  File "/usr/lib/python3.7/site-packages/xonsh/__amalgam__.py", line 20140, in _parse_ctx_free
    debug_level=(self.debug_level > 2))
  File "/usr/lib/python3.7/site-packages/xonsh/parsers/base.py", line 349, in parse
    tree = self.parser.parse(input=s, lexer=self.lexer, debug=debug_level)
  File "/usr/lib/python3.7/site-packages/ply/yacc.py", line 333, in parse
    return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)
  File "/usr/lib/python3.7/site-packages/ply/yacc.py", line 1201, in parseopt_notrack
    tok = call_errorfunc(self.errorfunc, errtoken, self)
  File "/usr/lib/python3.7/site-packages/ply/yacc.py", line 192, in call_errorfunc
    r = errorfunc(token)
  File "/usr/lib/python3.7/site-packages/xonsh/parsers/base.py", line 2760, in p_error
    column=p.lexpos))
  File "/usr/lib/python3.7/site-packages/xonsh/parsers/base.py", line 482, in _parse_error
    raise err
  File "<string>", line None
SyntaxError: <xonsh-code>:2:10: ("code: 'b'",)
 and echo 'b'
          ^
```
```
xonfig
+------------------+-----------------+
| xonsh            | 0.7.2           |
| Python           | 3.7.0           |
| PLY              | 3.11            |
| have readline    | True            |
| prompt toolkit   | 1.0.15          |
| shell type       | prompt_toolkit1 |
| pygments         | 2.2.0           |
| on posix         | True            |
| on linux         | True            |
| distro           | arch            |
| on darwin        | False           |
| on windows       | False           |
| on cygwin        | False           |
| on msys2         | False           |
| is superuser     | False           |
| default encoding | utf-8           |
| xonsh encoding   | utf-8           |
| encoding errors  | surrogateescape |
+------------------+-----------------+
```
Thanks @laloch - I can reproduce your example.
It seems to only be transforming the first line:

```sh
scopatz@artemis ~ $ $XONSH_DEBUG = 2 
scopatz@artemis ~ $ echo a \ 
`·.,¸,.·*¯`·.,¸,.·* and echo b 
`·.,¸,.·*¯`·.,¸,.·*          
<xonsh-code>:1:5:8 - echo a and echo b
<xonsh-code>:1:5:8 + ![echo a] and echo b
```

Resolving patch:
diff --git a/xonsh/execer.py b/xonsh/execer.py
--- a/xonsh/execer.py
+++ b/xonsh/execer.py
@@ -151,7 +151,18 @@ def exec(self, input, mode='exec', glbs=None, locs=None, stacklevel=2,
             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 @@ def _parse_ctx_free(self, input, mode='exec', filename=None):
                 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 @@ def _parse_ctx_free(self, input, mode='exec', filename=None):
                         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
--- 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)