Yapton 0.1.2__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.
yapton/__init__.py ADDED
@@ -0,0 +1,111 @@
1
+ import sys
2
+ import io
3
+ import tokenize
4
+
5
+ # Yapton -> Python keyword / literal mapping
6
+ # We only touch NAME tokens, so strings and comments stay the same.
7
+ NAME_MAP = {
8
+ # control flow
9
+ "optionC": "elif", # optionC -> elif
10
+ "otherwise": "else", # otherwise -> else
11
+
12
+ # booleans
13
+ "W": "True", # W -> True
14
+ "L": "False", # L -> False
15
+
16
+ # functions / I/O
17
+ "yap": "print", # yap(...) -> print(...)
18
+ # NOTE: spill is implemented as a real Python helper function below,
19
+ # not just a rename, so it can auto-convert numbers.
20
+
21
+ # function definition
22
+ "vibe": "def", # vibe foo(): -> def foo():
23
+
24
+ # imports
25
+ "fanumtax": "import", # fanumtax math -> import math
26
+ }
27
+
28
+
29
+ def spill(prompt: str = "") -> object:
30
+ """Yapton input function.
31
+
32
+ Behaves like Python's input(), but tries to convert what the user typed
33
+ into an int or float. If that fails, it returns the raw string.
34
+ """
35
+
36
+ raw = input(prompt)
37
+ # Try int first
38
+ try:
39
+ return int(raw)
40
+ except ValueError:
41
+ pass
42
+
43
+ # Then try float
44
+ try:
45
+ return float(raw)
46
+ except ValueError:
47
+ return raw
48
+
49
+
50
+ def transpile(source: str) -> str:
51
+ """Turn Yapton source into real Python source.
52
+
53
+ This uses the tokenize module so we only rewrite identifier tokens,
54
+ not things inside strings or comments. That way Python's own
55
+ features (types, lists, slicing, loops, etc.) just work.
56
+ """
57
+
58
+ out_tokens = []
59
+
60
+ # tokenize.tokenize works on bytes; we wrap the string in a BytesIO
61
+ byte_stream = io.BytesIO(source.encode("utf-8"))
62
+ try:
63
+ for tok in tokenize.tokenize(byte_stream.readline):
64
+ tok_type = tok.type
65
+ tok_string = tok.string
66
+
67
+ # Replace only identifier / name tokens that are in our mapping
68
+ if tok_type == tokenize.NAME and tok_string in NAME_MAP:
69
+ tok_string = NAME_MAP[tok_string]
70
+ tok = tokenize.TokenInfo(tok_type, tok_string, tok.start, tok.end, tok.line)
71
+
72
+ out_tokens.append(tok)
73
+ except tokenize.TokenError as exc:
74
+ raise SyntaxError(f"Yapton could not be tokenized: {exc}")
75
+
76
+ # untokenize back to Python code
77
+ return tokenize.untokenize(out_tokens).decode("utf-8")
78
+
79
+
80
+ def run_file(path: str) -> None:
81
+ with open(path, "r", encoding="utf-8") as f:
82
+ source = f.read()
83
+
84
+ python_code = transpile(source)
85
+
86
+ # Execute the transpiled Python. We let Python handle all the real
87
+ # work: numbers, strings, lists, slicing, loops, functions, imports, etc.
88
+ # Expose spill() so Yapton code can call it directly.
89
+ globals_dict = {"__name__": "__main__", "spill": spill}
90
+ try:
91
+ exec(python_code, globals_dict)
92
+ except Exception as exc: # noqa: BLE001
93
+ # Wrap any Python error with your custom prefix.
94
+ print(f"error 67: {exc.__class__.__name__}: {exc}")
95
+ sys.exit(1)
96
+
97
+
98
+ def print_slang_help() -> None:
99
+ print("Yapton slang dictionary:\n")
100
+ print(" W -> True (boolean)")
101
+ print(" L -> False (boolean)")
102
+ print(" if -> if (same as Python)")
103
+ print(" optionC -> elif")
104
+ print(" otherwise -> else")
105
+ print(" yap -> print")
106
+ print(" spill -> input (auto-converts to number when possible)")
107
+ print(" vibe -> def (define a function)")
108
+ print(" fanumtax -> import (bring in Python modules)")
109
+ print(" # -> comment (same as Python)")
110
+ print(" type(...) -> same as Python type() and casts")
111
+ print(" lists, slicing, for/while loops -> same as Python syntax")
yapton/cli.py ADDED
@@ -0,0 +1,25 @@
1
+ import sys
2
+
3
+ from . import print_slang_help, run_file
4
+
5
+
6
+ def main(argv: list[str] | None = None) -> None:
7
+ if argv is None:
8
+ argv = sys.argv[1:]
9
+
10
+ # Usage:
11
+ # yap program.yap
12
+ # yap --slang-help
13
+ if len(argv) == 1 and argv[0] == "--slang-help":
14
+ print_slang_help()
15
+ raise SystemExit(0)
16
+
17
+ if len(argv) != 1:
18
+ print("Usage: yap <program.yap> | --slang-help")
19
+ raise SystemExit(1)
20
+
21
+ run_file(argv[0])
22
+
23
+
24
+ if __name__ == "__main__": # pragma: no cover
25
+ main()
@@ -0,0 +1,168 @@
1
+ Metadata-Version: 2.4
2
+ Name: Yapton
3
+ Version: 0.1.2
4
+ Summary: Yapton is an fun Python library that helps kids learn how to code Python using fun slang-keywords
5
+ Requires-Python: >=3.10
6
+ Description-Content-Type: text/markdown
7
+ License-File: LICENSE
8
+ Dynamic: license-file
9
+
10
+ # Yapton
11
+
12
+ **Yapton is a small educational programming language that lets learners write Python-style programs with a few slang-inspired keywords.** A Yapton file (`.yap`) is translated to Python in memory and then run with the normal Python runtime. It is intended as a friendly bridge to Python, not as a replacement for it.
13
+
14
+ ## What this project does
15
+
16
+ Yapton keeps ordinary Python syntax, data types, loops, expressions, and standard-library imports. It adds the following alternative words:
17
+
18
+ | Yapton | Python meaning |
19
+ | --- | --- |
20
+ | `yap(...)` | `print(...)` |
21
+ | `spill(...)` | `input(...)`, converting number-looking input to `int` or `float` |
22
+ | `vibe name():` | `def name():` |
23
+ | `fanumtax math` | `import math` |
24
+ | `optionC` | `elif` |
25
+ | `otherwise` | `else` |
26
+ | `W` / `L` | `True` / `False` |
27
+
28
+ For example:
29
+
30
+ ```yap
31
+ fanumtax math
32
+
33
+ vibe greet(name):
34
+ yap("Welcome,", name)
35
+
36
+ name = spill("What is your name? ")
37
+ greet(name)
38
+ ```
39
+
40
+ ## Project roles
41
+
42
+ The codebase has three clear responsibilities:
43
+
44
+ | Part | Role |
45
+ | --- | --- |
46
+ | `src/yapton/__init__.py` | The **Yapton language engine**. It translates Yapton keywords into Python tokens, provides `spill`, runs `.yap` files, and prints the slang reference. |
47
+ | `src/yapton/cli.py` | The **command-line interface**. It accepts `yap program.yap` and `yap --slang-help`, then calls the language engine. |
48
+ | `pyproject.toml` | The **package configuration**. It declares the Python requirement and installs the `yap` command. |
49
+ | `sample1.yap` to `sample7.yap` | **Example Yapton programs**, ordered from small language demonstrations to larger projects. |
50
+ | `yap.bat` | The **Windows launcher**. It runs `python -m yapton.cli`, so it never depends on a copied, moved, or stale virtual environment. |
51
+
52
+ ## Requirements
53
+
54
+ - Python 3.10 or newer
55
+ - PowerShell, Command Prompt, or another terminal
56
+ - Git, only if you want to publish the project on GitHub
57
+
58
+ Check that Python is available:
59
+
60
+ ```powershell
61
+ py --version
62
+ ```
63
+
64
+ If `py` is not found, install Python from [python.org](https://www.python.org/downloads/) and make sure the installer option to add Python to PATH is enabled.
65
+
66
+ ## Run it locally (Windows / PowerShell)
67
+
68
+ Open PowerShell in this project folder, then create a fresh virtual environment and install Yapton in editable mode:
69
+
70
+ ```powershell
71
+ cd "C:\path\to\Yapton"
72
+ py -m venv .venv
73
+ .\.venv\Scripts\Activate.ps1
74
+ python -m pip install --upgrade pip
75
+ python -m pip install -e .
76
+ ```
77
+
78
+ Run an example:
79
+
80
+ ```powershell
81
+ yap sample2.yap
82
+ ```
83
+
84
+ Or run the larger example:
85
+
86
+ ```powershell
87
+ yap sample5.yap
88
+ ```
89
+
90
+ See the built-in language reference at any time:
91
+
92
+ ```powershell
93
+ yap --slang-help
94
+ ```
95
+
96
+ ### If PowerShell blocks activation
97
+
98
+ Activation is optional. Use the environment's Python directly instead:
99
+
100
+ ```powershell
101
+ .\.venv\Scripts\python.exe -m pip install -e .
102
+ .\.venv\Scripts\yap.exe sample2.yap
103
+ ```
104
+
105
+ ### Run a new program
106
+
107
+ 1. Create a file ending in `.yap`, such as `hello.yap`.
108
+ 2. Add Yapton/Python code.
109
+ 3. Run `yap hello.yap` while the environment is active.
110
+
111
+ Indentation and colons work exactly like Python. Regular Python can be mixed with the Yapton keywords shown above.
112
+
113
+ ### Sample guide
114
+
115
+ | File | Demonstrates |
116
+ | --- | --- |
117
+ | `sample1.yap` | Functions, loops, lists, conditions, and Yapton booleans. |
118
+ | `sample2.yap` | Adding two numbers entered by the user. |
119
+ | `sample3.yap` | Subtracting two numbers entered by the user. |
120
+ | `sample4.yap` | Checking whether a number is positive or negative. |
121
+ | `sample5.yap` | A menu-driven student score tracker using Yapton imports. |
122
+ | `sample6.yap` | The same student tracker, showing that regular Python `import` also works. |
123
+ | `sample7.yap` | A first-person 3D maze. Install its extra dependency first with `python -m pip install ursina`. |
124
+
125
+ ### Why `yap` works reliably in this folder
126
+
127
+ Windows chooses `yap.bat` in the current folder before an installed `yap` command. This project launcher deliberately uses `python -m yapton.cli` instead of a hard-coded path to `venv\\Scripts\\python.exe`. That means it uses the same Python installation that installed Yapton and will not break merely because a virtual-environment folder was moved, deleted, or created on another computer.
128
+
129
+ ## Put it on GitHub
130
+
131
+ 1. Sign in to [GitHub](https://github.com/) and select **New repository**.
132
+ 2. Name it `Yapton`, choose Public or Private, and **do not** initialize it with a README, `.gitignore`, or license—the project already has the first two.
133
+ 3. In PowerShell, from this project folder, run the following. Replace `YOUR-USERNAME` with your GitHub username:
134
+
135
+ ```powershell
136
+ cd "C:\path\to\Yapton"
137
+ git init
138
+ git add .
139
+ git commit -m "Initial commit: Yapton language"
140
+ git branch -M main
141
+ git remote add origin https://github.com/YOUR-USERNAME/Yapton.git
142
+ git push -u origin main
143
+ ```
144
+
145
+ GitHub may ask you to sign in or create a personal access token when you push over HTTPS. If Git reports that a remote called `origin` already exists, update it instead:
146
+
147
+ ```powershell
148
+ git remote set-url origin https://github.com/YOUR-USERNAME/Yapton.git
149
+ git push -u origin main
150
+ ```
151
+
152
+ The included `.gitignore` prevents virtual environments, cache files, and build outputs from being uploaded. Do not upload `.venv/` or `venv/`; each contributor should create their own using the local setup steps above.
153
+
154
+ ### Privacy check before publishing
155
+
156
+ The publishable source files contain no personal names, email addresses, passwords, API keys, or local computer paths. The ignored `venv/` folder is machine-specific and must not be uploaded. The `.gitignore` also excludes virtual environments and `.env` files, which are common places for private settings. Before each push, review exactly what will be uploaded with:
157
+
158
+ ```powershell
159
+ git status
160
+ ```
161
+
162
+ ## Contributing
163
+
164
+ When adding a slang keyword, update both `NAME_MAP` and `print_slang_help()` in `src/yapton/__init__.py`, then add or update a `.yap` example that demonstrates it. Before committing, run an example and `yap --slang-help` to confirm the command still works.
165
+
166
+ ## Current status
167
+
168
+ Yapton is an early educational prototype. Because programs ultimately execute as Python, only run `.yap` files you trust.
@@ -0,0 +1,8 @@
1
+ yapton/__init__.py,sha256=WVqklB4ELcwy8IxTED0Z4TTRCvkDGKhUykLjFnrmE80,3728
2
+ yapton/cli.py,sha256=m7R2gAImAYsr7uyB4sZkjO3SVwOTcHKi3tocKCxsOYQ,541
3
+ yapton-0.1.2.dist-info/licenses/LICENSE,sha256=k6AAdrqOHkz-lKfQCbjReP0sxkLgIVvBWWRLTdLCMZ0,1089
4
+ yapton-0.1.2.dist-info/METADATA,sha256=VEDPN26hBYDjPLr4fUpT95psoa_iBVncDHt_YNeryO8,6566
5
+ yapton-0.1.2.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
6
+ yapton-0.1.2.dist-info/entry_points.txt,sha256=cCjLYS2eslC0PcRIOW7RiM0S_3mtkpMNLZN-EvFzqEs,40
7
+ yapton-0.1.2.dist-info/top_level.txt,sha256=c5_o2DCHM4QMfWssXIEPfXADr3-uyvXenaj5HOZmknc,7
8
+ yapton-0.1.2.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.0.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ yap = yapton.cli:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Zahi Najmal
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ yapton