Skip to main content

python with braces.

Project description

nestPython

"what if python, with braces, one line?"

SETUP

Install nestPython by executing the following:

$ pip install nestpython

After importing;

  • In order to transpile a string from nestPython to python, use nestpython.ncompile(str)
  • In order to execute a nestPython string, use nestpython.nexec(str)
  • To transpile files and directories, use the nestpython.files module:
    • nestpython.files.ncompile(file) transpiles the specified file to a string
    • nestpython.files.ncompile_to(file) transpiles the specified file to a new file
    • nestpython.files.nexec(file) executes the specified file
    • nestpython.files.build(dir, new_dir) transpiles a directory
    • arguments can be provided:
      • indent_amount=1: determines the indentation increment in the resulting python file
      • transfer_other_files=True: determines whether non-.npy (or .npx) files should be copied into the build directory
      • replace_previous=False: determines whether already built files should be replaced
      • erase_dir:bool=None: determines whether the previously built directory should be completely erased. If not specified, you will be asked to specify in the console
      • cythonic:bool=None: determines if code should be perceived as nestCython or nestPython
      • tokenlog=False: determines if tokenization progress should be logged
      • new_file:str=None: determines where to compile a source file. Reverts to the original filename with a .py(x) extension if unspecified

Use .npy for nestPython files, .npx for nestCython files.

FEATURING:

braces

Use {, ; and } instead of indentation - indentation and newline characters in source files will be ignored. e.g.:

n = input('Enter Number: ');
if (n % 2 == 0) {
	print('n is even')
} else {
	print('n is odd')
}

Use ~{ as a shorthand for while True {.

syntactical changes

Several keywords are altered:

Python nestPython Python nestPython
def := del ~>
return => yield :>
in -> and &&
not in !> or ||
is =& := <-
is not !=& case ?
lambda ;= ; ,,
-> >: // ~/
+= 1 ++ -= 1 --
{ -{ } }-

A variable like return will be replaced with return_ on transpilation. using pass is never required, do-nothing braces can be left empty. One-line functions can still be written with colons: := foo(): => bar, same for if-else and for statements.

Cython keywords are also altered for .npx:

Cython nestCython
cdef $=
cpdef ~$=

Strings or ternaries do not have to be one-line; if they are not, you can use \ and # to reserve whitespace as follows:

'string \
continues here'

is equivalent to

'string continues here'

and transpiles to a python string with the newline character ignored. This can be used to explicitly reserve whitespace before the newline character.

Same thing can be done with the # character outside of a string:

a if b #
else c

is equivalent to

a if b else c

The # is ignored by the transpiler.

comments

  • For block comments, use /*, */.
  • For line comments, use //.
  • Block and line comments will be ignored during transpilation.
  • For comments that need to be cpiled into python ones, use /|, |\ .

(to be continued)


github : https://github.com/svntythsnd/nestpy

pypi : https://pypi.org/project/nestpython

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nestpython-0.3.34.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

nestpython-0.3.34-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file nestpython-0.3.34.tar.gz.

File metadata

  • Download URL: nestpython-0.3.34.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.14

File hashes

Hashes for nestpython-0.3.34.tar.gz
Algorithm Hash digest
SHA256 c67fa7740d820a51b63e58b480b9868a2e0c1df3478479a0c8e655a92e45b5c9
MD5 9ca4e3c4f9fb8a2d69f865bef14f6282
BLAKE2b-256 5a9f40d465c5505b9c562897b75b44fdca598de6a8832dbf662cbaa76de10190

See more details on using hashes here.

File details

Details for the file nestpython-0.3.34-py3-none-any.whl.

File metadata

  • Download URL: nestpython-0.3.34-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.14

File hashes

Hashes for nestpython-0.3.34-py3-none-any.whl
Algorithm Hash digest
SHA256 8edcfe7b03190d65c46106ca46dd451ab6d9f8c639cfadf6a1320e89eb5dfd66
MD5 4534dde749e573722e3114546b61ba5d
BLAKE2b-256 28a0101ac50edeca4e6e3031b1e97aacf0704478c6e8bf88740663370117e0ab

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page