Skip to content

thatbirdguythatuknownot/python-token-macros

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

python-token-macros

Token-based macro replacement using codecs/encodings.
Implementation based on incdec.py by dankeyy. Inspired by AnonymousDapper's AST macros.

Initializing

Get local (downloaded/cloned) copies of macros.py and macros_loader.pth and transfer to path/to/python/Lib/site-packages.
Windows commands:

Cmd:
cd path\to\macros_files
for /f "tokens=* USEBACKQ" %f in (`py -c "import site; print(site.getsitepackages()[1])"`) do set SYSTEM_SITE_PACKAGES=%f
copy /y macros.py+macros_loader.pth "%SYSTEM_SITE_PACKAGES%"

Powershell:
cd path\to\macros_files
$SYSTEM_SITE_PACKAGES = py -c "import site; print(site.getsitepackages()[1])"
Copy-Item macros.py,macros_loader.pth $SYSTEM_SITE_PACKAGES

Using

W.I.P VERSION:

from macros import transform

string = """
def a!(x): $x + 2
b = 7
print(a!(b))
"""
transformed = transform(string.encode(), False) # second argument currently has no effect
exec(transformed) # 9

FINISHED VERSION:

# coding: macros
def a!(x): $x + 2
b = 7
print(a!(b)) # 9

About

Token-based macro replacement using codecs/encodings.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages