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

Hy as a Python syntax extension #368

Closed
wants to merge 7 commits into from
Closed

Conversation

lmatthieu
Copy link

Hi,

A test, inspired by Pyxl of using hy as a syntax extension.
It uses Python support for specifying source code encodings (PEP 263).

How to use it

All python files with inline Hy code must have the following first line

coding: hy

You can mix Python and Hy code with this syntax:

@(defn hello [] 
     (print "hello"))
@(hello)

sum = 1 + @(+ 1 1)

After installing Hy, you must install the syntax extension with:

python setup.py hysyntax

This step add a file hy.pth in your python site-package directory (allows hy syntax extension to be loaded on Python startup).

A test file is provided in tests/contrib/hysyntax.

Any questions, bug reports, and other feedback on this code are welcomed !

Matthieu

@paultag
Copy link
Member

paultag commented Dec 9, 2013

no effing way

@paultag
Copy link
Member

paultag commented Dec 9, 2013

This is awesome. I'll get on reviewing this tonight. Steller work, @lmatthieu !

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling f3e9e56 on yminer:master into 8970662 on hylang:master.

self.module_name = module_name
if not module_name.startswith("hy.core"):
# everything in core needs to be explicit.
load_stdlib()

def getContext(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there any chance we could move this to get_context ? We use underscores consistently :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prod. I'd love to get this in if you don't mind fixing this (otherwise I can fix it and open a new PR)

@paultag
Copy link
Member

paultag commented Dec 22, 2013

This is great. Code changes look good. Let's get an ack, @hylang/core

"""
Inspired by PyXL, register.py.
"""
from __future__ import with_statement
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't support Python versions older than 2.7. You can safely remove this line.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do support Python 2.6 if we can avoid breaking it. Don't you run tox?

On Sat, Jan 4, 2014 at 7:39 AM, Berker Peksag [email protected]:

In hy/contrib/hysyntax.py:

@@ -0,0 +1,89 @@
+"""

  • Inspired by PyXL, register.py.
    +"""
    +from future import with_statement

We don't support Python versions older than 2.7. You can safely remove
this line.


Reply to this email directly or view it on GitHubhttps://github.com//pull/368/files#r8651563
.

:wq

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, you're right :(

@lmatthieu
Copy link
Author

I have updated the hy extension with your comments. In the repo https://github.com/lmatthieu/myemacs, you will find an example of emacs configuration handling hy/python code-mixing.

import shutil
from distutils.sysconfig import get_python_lib
python_lib = get_python_lib()
print "Installing Hy syntax extension"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks Python 3 :)

I'd just remove the print

@paultag
Copy link
Member

paultag commented Jan 4, 2014

Nice work so far!

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling b1df057 on yminer:master into d9d1136 on hylang:master.

@Foxboron
Copy link
Member

Foxboron commented Sep 5, 2014

ping @lmatthieu!

@paultag
Copy link
Member

paultag commented Nov 15, 2014

It's been a few months since we had any activity on this :(

I'm going to close this for now, please do reopen it if we can get it rebased on master and stuff.

❤️

@paultag paultag closed this Nov 15, 2014
@brandonwillard
Copy link
Member

brandonwillard commented Feb 3, 2020

I was just reminded of this codecs-based embedded syntax approach and just noticed this attempt to integrate it into Hy. @hylang/core, is this something that's still worth considering? Seems like it could provide a nice form of Hy-in-Python (e.g. a non-string one).

Using this approach, it also seems like we could nicely determine Hy vs. Python source strings based on a custom encoding (see my comment here regarding the use of source type delineation of strings).

@Kodiologist
Copy link
Member

It's not something I'd invest effort in, personally, but I guess it could be cool to have. The devil's in the details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants