whizz 0.9.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
whizz/base.py ADDED
@@ -0,0 +1,56 @@
1
+ """
2
+ Whizz Programming Language / Transpiled Program
3
+ language by splot.dev
4
+ """
5
+
6
+ ##### BASE CODE #####
7
+
8
+ import random
9
+ import readchar
10
+
11
+ _variables = {}
12
+ _selected = None
13
+
14
+ def _need_selected():
15
+ if _selected is None:
16
+ raise RuntimeError('Cannot perform actions without selected variable.')
17
+
18
+ def _select(name):
19
+ global _variables
20
+ if name not in _variables:
21
+ _variables[name] = 0
22
+
23
+ global _selected
24
+ _selected = name
25
+
26
+ def _increment(amount):
27
+ _need_selected()
28
+ global variables
29
+ _variables[_selected] += amount
30
+
31
+ def _decrement(amount):
32
+ _need_selected()
33
+ global variables
34
+ _variables[_selected] -= amount
35
+
36
+ def _random():
37
+ _need_selected()
38
+ global variables
39
+ _variables[_selected] = random.randint(1, 1000000)
40
+
41
+ def _print():
42
+ _need_selected()
43
+ try:
44
+ print(chr(_variables[_selected]), end="")
45
+ except:
46
+ raise RuntimeError(f'Could not print integer "{_variables[_selected]}".')
47
+
48
+ def _input():
49
+ _need_selected()
50
+ global variables
51
+ try:
52
+ _variables[_selected] = ord(readchar.readchar())
53
+ except:
54
+ _variables[_selected] = -1
55
+
56
+ ##### STARTING USER CODE #####
whizz/cli.py ADDED
@@ -0,0 +1,29 @@
1
+ """
2
+ Whizz Programming Language / Command-Line Interface
3
+ by splot.dev
4
+ """
5
+
6
+ from transpiler import transpile
7
+ import typer
8
+
9
+ def main(file: str):
10
+ try:
11
+ with open(file) as f:
12
+ code = f.read()
13
+ except Exception as e:
14
+ print(f"đź’¬ Couldn't read your file:\n{e}")
15
+
16
+ try:
17
+ transpiled = transpile(code)
18
+ except Exception as e:
19
+ print(f"đź’¬ Couldn't transpile your code:\n{e}")
20
+
21
+ try:
22
+ exec(transpiled)
23
+ except Exception as e:
24
+ print(f"đź’¬ Couldn't execute your code without errors:\n{e}")
25
+
26
+ return True
27
+
28
+ if __name__ == "__main__":
29
+ typer.run(main)
whizz/grammar.lark ADDED
@@ -0,0 +1,29 @@
1
+ # Whizz Programming Language / Lark Grammar
2
+ # by splot.dev
3
+
4
+ start: ( _command | function )*
5
+
6
+ _command: select | increment | decrement | random
7
+ | forever | call
8
+ | print | input
9
+
10
+ select: NAME
11
+ increment: INTEGER? "+"
12
+ decrement: INTEGER? "-"
13
+ random: "~"
14
+
15
+ function: NAME "{" _command* "}"
16
+ forever: "(" ( _command | end )* ")"
17
+ end: ";"
18
+ call: NAME "*"
19
+
20
+ print: "!"
21
+ input: "?"
22
+
23
+ NAME: /[a-zA-Z]+/
24
+ INTEGER: /[0-9]+/
25
+
26
+ COMMENT: /\[[\s\S]*?\]/
27
+ %ignore COMMENT
28
+ %ignore WHITESPACE
29
+ %import common.WS -> WHITESPACE
whizz/transpiler.py ADDED
@@ -0,0 +1,85 @@
1
+ """
2
+ Whizz Programming Language / Transpiler
3
+ by splot.dev
4
+ """
5
+
6
+ from lark import Lark
7
+ from lark.visitors import Interpreter
8
+
9
+ # acquire grammar and load into lark
10
+ with open("grammar.lark") as file:
11
+ grammar = file.read()
12
+ parser = Lark(grammar)
13
+
14
+ # set transpilation base from file
15
+ with open("base.py") as file:
16
+ transpilation_base = file.read()
17
+
18
+ # lark interpreter class
19
+ class Transpiler(Interpreter):
20
+ def __init__(self):
21
+ self.code = transpilation_base + "\n\n"
22
+ self.level = 0
23
+
24
+ def _indent(self):
25
+ return self.level * " "
26
+
27
+ def forever(self, tree):
28
+ self.code += self._indent() + "while True:\n"
29
+ if tree.children:
30
+ self.level += 1
31
+ self.visit_children(tree)
32
+ self.level -= 1
33
+ else:
34
+ self.code += self._indent() + " pass\n"
35
+
36
+ def function(self, tree):
37
+ self.code += f"def {tree.children[0]}():\n"
38
+ if tree.children[1:]:
39
+ self.level += 1
40
+ for child in tree.children[1:]:
41
+ self.visit(child)
42
+ self.level -= 1
43
+ else:
44
+ self.code += " pass\n"
45
+
46
+ def end(self, tree):
47
+ self.code += self._indent() + "_need_selected()\n"
48
+ self.code += self._indent() + "if _variables[_selected] == 0:\n"
49
+ self.code += self._indent() + " break\n"
50
+
51
+ def call(self, tree):
52
+ self.code += self._indent() + tree.children[0] + "()\n"
53
+
54
+ def select(self, tree):
55
+ self.code += self._indent() + f"_select('{tree.children[0]}')\n"
56
+
57
+ def increment(self, tree):
58
+ if tree.children:
59
+ self.code += self._indent() + f"_increment({tree.children[0]})\n"
60
+ else:
61
+ self.code += self._indent() + "_increment(1)\n"
62
+
63
+ def decrement(self, tree):
64
+ if tree.children:
65
+ self.code += self._indent() + f"_decrement({tree.children[0]})\n"
66
+ else:
67
+ self.code += self._indent() + "_decrement(1)\n"
68
+
69
+ def random(self, tree):
70
+ self.code += self._indent() + "_random()\n"
71
+
72
+ def print(self, tree):
73
+ self.code += self._indent() + "_print()\n"
74
+
75
+ def input(self, tree):
76
+ self.code += self._indent() + "_input()\n"
77
+
78
+ # usage of class
79
+ def transpile(code):
80
+ tree = parser.parse(
81
+ code.replace("\n", "").replace("\t", "").replace("\r", "").replace(" ", "") # lark is funny with whitespace
82
+ )
83
+ transpiler = Transpiler()
84
+ transpiler.visit(tree)
85
+ return transpiler.code
@@ -0,0 +1,20 @@
1
+ Metadata-Version: 2.4
2
+ Name: whizz
3
+ Version: 0.9.0
4
+ Summary: Whizz is a succinct esoteric programming language that is almost, contradictorily, relatively usable.
5
+ License: MIT
6
+ License-File: LICENSE
7
+ Author: splot.dev
8
+ Requires-Python: >=3.11,<4.0
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Classifier: Programming Language :: Python :: 3.13
14
+ Classifier: Programming Language :: Python :: 3.14
15
+ Requires-Dist: readchar (>=4.2.2,<5.0.0)
16
+ Requires-Dist: typer (>=0.27.0,<1.0.0)
17
+ Description-Content-Type: text/markdown
18
+
19
+ # Whizz Programming Language
20
+ ## Learn more at [the repository](https://codeberg.org/splot-dev/whizz).
@@ -0,0 +1,9 @@
1
+ whizz/base.py,sha256=C8oH2a40r4bsPG8EzP5DQiRFY6T82T4qX8qdlXdNd4A,1091
2
+ whizz/cli.py,sha256=DsRDDEAhtdDeX4_gCXyJn2fDjBKU4_IbTlHf3CJpOfk,572
3
+ whizz/grammar.lark,sha256=yu7Ph_M5WWkPuWCvSUapQrNNiS2kXjaY9XEn3M3OMJA,512
4
+ whizz/transpiler.py,sha256=xT1k6Qxg5dVpwx8hM6vmjbIQnrD2nKI_BVSYF3HiEIM,2247
5
+ whizz-0.9.0.dist-info/METADATA,sha256=fpAV8PRtpPVAVsUttfsDrc2Fvy0zE4zNBGHnaFnxx9U,768
6
+ whizz-0.9.0.dist-info/WHEEL,sha256=Vz2fHgx6HFtSwhs8KvkHLqH5Ea4w1_rner5uNVGCeIE,88
7
+ whizz-0.9.0.dist-info/entry_points.txt,sha256=bX4MClP1vrEAK1PNhtSfGvvJEiDGqlcoiY_cQYm9Kfk,40
8
+ whizz-0.9.0.dist-info/licenses/LICENSE,sha256=ad6qgZWlNqvG3mu237OJKhV9QeY6ZWkDbQzGsXSRx7U,1056
9
+ whizz-0.9.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: poetry-core 2.3.2
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,3 @@
1
+ [console_scripts]
2
+ whizz=whizz.cli:main
3
+
@@ -0,0 +1,7 @@
1
+ Copyright 2026 splot.dev
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.