Fix xonsh integration breaking on backslash line-continuation#905
Open
anki-code wants to merge 1 commit into
Open
Fix xonsh integration breaking on backslash line-continuation#905anki-code wants to merge 1 commit into
anki-code wants to merge 1 commit into
Conversation
|
Works for me, thanks @anki-code :) |
|
This was answered by my ai arkhan by itself jorel666 be a part of the future hit me up |
Owner
|
This looks great! Can you rebase and retest on |
When Coconut is loaded as a xonsh xontrib and the user enters a multiline subprocess command joined by ``\<newline>``, xonsh raises ``SyntaxError: unexpected indent`` for input that worked fine without Coconut. Root cause: ``Compiler.reind_proc`` intentionally splits backslash- continued source into two physical lines and indents the continuation tail by ``tabideal`` spaces "for readability" of the compiled output. That is fine for standalone Coconut output — Python tolerates it via the implicit string/expression continuation rules — but the xonsh xontrib feeds the compiled output back through xonsh's own parser as top-level statements, where a complete statement followed by an unexpected INDENT is a SyntaxError. Concretely, ``echo a \<nl>b`` becomes ``echo a evhub#1: echo a \<nl> b evhub#1: echo a \<nl>``, which neither xonsh nor CPython will parse. Fix: collapse ``\<newline><indent>`` into a single space before handing the source to ``parse_xonsh``, so the compiler emits one physical line on the other side and the host parser is happy. The collapse walks the source manually so backslash sequences inside string literals and comments are left alone (a plain ``re.sub`` would silently rewrite ``"a\<nl>b"``, which is a Python implicit-string line continuation and must keep its meaning). Reproducer (with the xontrib autoloaded): @ echo a \\ b SyntaxError: code: b ← before a b ← after Other xonsh-side scenarios (``echo && cmd`` chains, Coconut features like ``|>``/``->``/``<|``, capture forms, xonsh assignments) are unaffected.
f64e0fb to
c1ae96f
Compare
Contributor
Author
|
@evhub Rebased onto Retested against
The patch logic is byte-identical to before the rebase. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #906
Summary
When the Coconut xontrib is autoloaded into xonsh and the user enters a multiline subprocess command joined with
\<newline>, xonsh raisesSyntaxError: unexpected indenton input that works fine without Coconut.Root cause
Compiler.reind_procintentionally splits backslash-continued source into two physical lines and indents the continuation tail bytabidealspaces "for readability". For standalone Coconut output that's fine — Python tolerates it through implicit string/expression continuation. But the xonsh xontrib feeds the compiled output back through xonsh's own parser as top-level statements, where a complete statement followed by an unexpectedINDENTis aSyntaxError. Concretely,echo a \<nl>bbecomesecho a #1: echo a \<nl> b #1: echo a \<nl>, which neither xonsh nor CPython will parse.I confirmed via
tokenize.tokenizethat this output is invalid CPython too — not just xonsh-specific:The
INDENTafter a completeecho astatement is the bug.Fix
Collapse
\<newline><indent>into a single space before handing the source toparse_xonsh. With the line continuation already collapsed, the compiler emits one physical line on the other side and the host parser is happy.The collapse is a small manual scanner — string literals and comments are skipped so backslash sequences inside them keep their original meaning. (A plain
re.subwould silently rewrite"a\<nl>b", which is a Python implicit-string line continuation.)Test plan
Reproduced + verified against
xonsh-dev(Python 3.13, xonsh main, coconut 3.2.0 + this patch):@ echo a \⏎b→a b(wasSyntaxError)@ print(range(5) |> list)→[0, 1, 2, 3, 4](Coconut features unchanged)@ double = x -> x*2; print(double(5))→10@ print(sum <| [1,2,3])→6@ s = "a\⏎b"; print(repr(s))→'ab'(Python implicit-string continuation preserved)_collapse_xonsh_line_continuations(no-op input, simple/multi continuations, strings/triple-quotes/comments preserved, trailing continuation, empty input)test_xontribscenarios still pass when run against the patched compile path (single-quoted continuation, semicolon chains, env-var f-strings, multi-line strings)Compatibility
No core compiler changes — patch is contained to
coconut/integrations.py(xonsh-specific module). Other Coconut endpoints (parse_sys,parse_eval,parse_file, …) and the rest of the runtime are untouched.Reported by xonsh users at #906 (the linked xonsh issue is about a related but separate xonsh-side bug; this fixes a Coconut-specific path that surfaces only with the xontrib loaded).