Skip to content

Commit

Permalink
transformed Jelly into a package
Browse files Browse the repository at this point in the history
  • Loading branch information
DennisMitchell committed Apr 9, 2018
1 parent aa03a90 commit 656a566
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 51 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
__pycache__/
build
*.pyc
File renamed without changes.
77 changes: 49 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,66 @@

Jelly is a golfing language inspired by J.

Please note that Jelly is currently under development; features will change or disappear without prior notice.
### Documentation

### Getting started
* [Tutorial]
* [Code page]
* [Atoms]
* [Quicks]
* [Syntax]

The Jelly interpreter requires Python 3, [NumPy] and [SymPy].
### Quickstart

To execute a Jelly program, you have three options:
The Jelly interpreter requires Python 3.

1. `jelly f <file> [input]` reads the Jelly program stored in the specified file, using the [Jelly code page].
To download, install, and use Jelly, proceed as follows.

This option should be considered the default, but it exists solely for scoring purposes in code golf contests.
```
$ git clone -q https://github.com/DennisMitchell/jellylanguage.git
$ cd jellylanguage
$ pip3 install --upgrade --user .
$ jelly eun '“3ḅaė;œ»'
Hello, World!
$ jelly eun '×' 14 3
42
$ jelly
Usage:
1. `jelly fu <file> [input]` reads the Jelly program stored in the specified file, using the UTF-8 encoding.
jelly f <file> [input] Reads the Jelly program stored in the
specified file, using the Jelly code page.
This option should be considered the default,
but it exists solely for scoring purposes in
code golf contests.
1. `jelly e <code> [input]` reads the Jelly program as command line argument, using the [Jelly code page].
jelly fu <file> [input] Reads the Jelly program stored in the
specified file, using the UTF-8 encoding.
This requires setting the environment variable *LANG* (or your OS's equivalent) to *en_US* or compatible.
jelly e <code> [input] Reads a Jelly program as a command line
argument, using the Jelly code page. This
requires setting the environment variable
LANG (or your OS's equivalent) to en_US or
compatible.
1. `jelly eu <code> [input]` reads the Jelly program as command line argument, using the UTF-8 encoding.
jelly eu <code> [input] Reads a Jelly program as a command line
argument, using the UTF-8 encoding. This
requires setting the environment variable
LANG (or your OS's equivalent) to en_US.UTF8
or compatible.
This requires setting the environment variable *LANG* (or your OS's equivalent) to *en_US.UTF8* or compatible.
Append an `n` to the flag list to append a trailing newline to the
program's output.
Alternatively, you can use the [Jelly interpreter] on [Try it online!]
Visit http://github.com/DennisMitchell/jellylanguage for more information.
```

Jelly's main input method is via command line arguments, although reading input from STDIN is also possible.
Alternatively, you can use the [Jelly interpreter] on [Try It Online].

### Documentation

* [Tutorial]
* [Atoms]
* [Quicks]
* [Syntax]
Jelly's main input method is via command line arguments, although reading input from STDIN is also possible.

[Atoms]: https://github.com/DennisMitchell/jelly/wiki/Atoms
[Jelly code page]: https://github.com/DennisMitchell/jelly/wiki/Code-page
[Jelly interpreter]: http://jelly.tryitonline.net
[NumPy]: http://www.numpy.org/
[Quicks]: https://github.com/DennisMitchell/jelly/wiki/Quicks
[SymPy]: http://www.sympy.org/
[Syntax]: https://github.com/DennisMitchell/jelly/wiki/Syntax
[Try it online!]: http://tryitonline.net
[Tutorial]: https://github.com/DennisMitchell/jelly/wiki/Tutorial
[Atoms]: https://github.com/DennisMitchell/jellylanguage/wiki/Atoms
[Code page]: https://github.com/DennisMitchell/jellylanguage/wiki/Code-page
[Jelly interpreter]: https://tio.run/#jelly
[Quicks]: https://github.com/DennisMitchell/jellylanguage/wiki/Quicks
[Syntax]: https://github.com/DennisMitchell/jellylanguage/wiki/Syntax
[Try It Online]: https://tryitonline.net
[Tutorial]: https://github.com/DennisMitchell/jellylanguage/wiki/Tutorial
14 changes: 14 additions & 0 deletions jelly/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from sys import stderr

from .interpreter import *

def main(code, args, end):
for index in range(min(7, len(args))):
atoms['³⁴⁵⁶⁷⁸⁹'[index]].call = lambda literal = args[index]: literal

try:
output(jelly_eval(code, args[:2]), end)
except KeyboardInterrupt:
if stderr.isatty():
sys.stderr.write('\n')
return 130
41 changes: 20 additions & 21 deletions jelly → jelly/__main__.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
#!/usr/bin/env python3
#!python3

import jelly
if __package__ == '':
from os.path import dirname
from sys import path

path[0] = dirname(path[0])

from jelly import code_page, main, try_eval
from sys import argv

flag_utf8 = False
end = ''
Expand Down Expand Up @@ -31,12 +38,12 @@
Append an `n` to the flag list to append a trailing newline to the
program's output.
Visit http://github.com/DennisMitchell/jelly for more information.\n'''
Visit http://github.com/DennisMitchell/jellylanguage for more information.'''

if len(jelly.sys.argv) < 3:
if len(argv) < 3:
raise SystemExit(usage)

for char in jelly.sys.argv[1]:
for char in argv[1]:
if char == 'f':
flag_file = True
elif char == 'u':
Expand All @@ -47,27 +54,19 @@
end = '\n'

if flag_file:
with open(jelly.sys.argv[2], 'rb') as file:
with open(argv[2], 'rb') as file:
code = file.read()
if flag_utf8:
code = ''.join(char for char in code.decode('utf-8').replace('\n', '¶') if char in jelly.code_page)
code = ''.join(char for char in code.decode('utf-8').replace('\n', '¶') if char in code_page)
else:
code = ''.join(jelly.code_page[i] for i in code)
code = ''.join(code_page[i] for i in code)
else:
code = jelly.sys.argv[2]
code = argv[2]
if flag_utf8:
code = ''.join(char for char in code.replace('\n', '¶') if char in jelly.code_page)
code = ''.join(char for char in code.replace('\n', '¶') if char in code_page)
else:
code = ''.join(jelly.code_page[ord(i)] for i in code)

args = list(map(jelly.try_eval, jelly.sys.argv[3:]))
code = ''.join(code_page[ord(i)] for i in code)

for index in range(min(7, len(args))):
jelly.atoms['³⁴⁵⁶⁷⁸⁹'[index]].call = lambda literal = args[index]: literal
args = list(map(try_eval, argv[3:]))

try:
jelly.output(jelly.jelly_eval(code, args[:2]), end)
except KeyboardInterrupt:
if jelly.sys.stderr.isatty():
jelly.sys.stderr.write('\n')
raise SystemExit(130)
raise SystemExit(main(code, args, end))
File renamed without changes.
2 changes: 1 addition & 1 deletion jelly.py → jelly/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,7 @@ def sss(compressed):
flag_swap = flag != 1
flag_space ^= flag != 0
integer, short = divmod(integer, 2)
the_dictionary = (__import__('dictionary').long, __import__('dictionary').short)[short]
the_dictionary = (__import__('.dictionary').long, __import__('.dictionary').short)[short]
integer, index = divmod(integer, len(the_dictionary))
word = the_dictionary[index]
if flag_swap:
Expand Down
1 change: 1 addition & 0 deletions scripts/jelly
16 changes: 16 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from distutils.core import setup

setup(
name = 'jellylanguage',
version = '0.1.0',
packages = [
'jelly'
],
scripts = [
'scripts/jelly'
],
requires = [
'numpy',
'sympy'
]
)

0 comments on commit 656a566

Please sign in to comment.