Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Line break characters aren't compatible with pure Python #818

Closed
kg583 opened this issue Jan 16, 2024 · 2 comments
Closed

Line break characters aren't compatible with pure Python #818

kg583 opened this issue Jan 16, 2024 · 2 comments

Comments

@kg583
Copy link

kg583 commented Jan 16, 2024

Coconut seems to consider quite a few characters that aren't \n\r line breaks, meaning they can't appear inside regular strings. This prevents pure Python code containing such characters from being valid Coconut.

print("����")                 # CoconutSyntaxError: linebreak in non-multi-line string
print("\x0b\x0c\x1c\x1d\x1e")    # This is a workaround

This has a further consequence which breaks the function of some programs: such "line breaks" automatically become \n\r inside multiline strings.

print(*map(ord,"""����"""))             # 10 10 10 10 10
print(*map(ord,"\x0b\x0c\x1c\x1d\x1e"))    # 11 12 28 29 30

It's worth addressing that this was all discovered by Coconut's recent (read: yesterday) addition to code.golf. Many Python competitors (myself included) ported over Python solutions as a starting point and found them breaking due to parser errors.

Of course, golfed code is often objectively disgusting, and it is no surprise that it puts strain on the parser. Other parser incompatibilities have been discovered, and while they do strictly break "all valid Python is valid Coconut", they vary in reasonability. For example, the added imaginary literal syntax leads to

0in[1,2,3]    # CoconutParseError: parsing failed

but this will become a SyntaxError in a future Python version (currently a SyntaxWarning), so there's probably little cause to fix it.

I am happy to open issues for other discovered parsing problems, though I also do not want to load the issue list with trifles. This is a great project and one that is already very well-liked for golfing, even with these hiccups.

@evhub evhub added the bug label Jan 16, 2024
@evhub evhub added this to the v3.1.0 milestone Jan 16, 2024
@evhub
Copy link
Owner

evhub commented Jan 16, 2024

This is great; thanks for raising this! Very happy to get these sorts of nitpicky issues where there are slight differences between Python and Coconut; these are bugs and definitely should be fixed.

@evhub evhub added the resolved label Jan 17, 2024
evhub added a commit that referenced this issue Jan 17, 2024
@evhub
Copy link
Owner

evhub commented Jan 17, 2024

Fixed as of coconut-develop>=3.0.4-post_dev14 (pip install -U coconut-develop>=3.0.4-post_dev14 to get the fix).

(including the 0in[1,2,3] thing)

@evhub evhub closed this as completed Jan 17, 2024
@evhub evhub mentioned this issue Mar 1, 2024
evhub added a commit that referenced this issue Mar 2, 2024
See Coconut's
[documentation](http://coconut.readthedocs.io/en/develop/DOCS.html) for
more information on all of the features listed below.

Language changes:
* #814: Changes to statement lambda scoping rules, including capturing
names introduced in the surrounding expression.
* #618: Changes to handling of pattern-matching function defaults
including support for e.g. `match def f(x, y=x) = (x, y)`.
* #809: New array concatenation implicit partials (e.g. `[. ; a]`).
* #823: New `(x := .)` implicit partial syntax (only available in
pipes).
* #807: New `lift_apart` built-in combinator.
* #813: New `(if)` operator function.
* #826 (thanks @JayXon!): Better universalization and `fmap` support for
`bytes` and `bytearray`.
* #816: Support for `xarray` to match existing `numpy`/`pandas` support.
* #817: New `to` argument to `all_equal`.
* #821 (thanks @GolfingSuccess!): Expanded implicit function application
syntax to support string literal methods.

Compiler changes:
* #799: `coconut-run` and `coconut --run` now work on packages rather
than just files.
* #812: Better formatting of Coconut exceptions.

Bugfixes:
* #810: Fixed an issue compiling certain syntax constructs in the
Coconut Jupyter kernel.
* #818, #825 (thanks @kg583, @dokutan!): Fixed parsing of different
Unicode line break characters.
* #822 (thanks @JayXon!): Fixed parsing of Unicode backward pipe
operators.
* #819, #820 (thanks @kg583!): Fixed some incompatibilities between
Python and Coconut syntax.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants