pyscript-programming-language 1.8.0__tar.gz → 1.8.1__tar.gz
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.
- pyscript_programming_language-1.8.1/PKG-INFO +86 -0
- pyscript_programming_language-1.8.1/README.md +51 -0
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/core/buffer.py +2 -2
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/core/cache.py +4 -3
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/core/lexer.py +15 -5
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/core/objects.py +9 -8
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/core/parser.py +11 -6
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/core/position.py +1 -1
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/core/results.py +7 -4
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/core/symtab.py +7 -6
- pyscript_programming_language-1.8.1/pyscript/core/utils/ansi.py +125 -0
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/core/version.py +18 -18
- pyscript_programming_language-1.8.1/pyscript/lib/ansi.pys +14 -0
- pyscript_programming_language-1.8.1/pyscript_programming_language.egg-info/PKG-INFO +86 -0
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/setup.py +1 -1
- pyscript_programming_language-1.8.0/PKG-INFO +0 -86
- pyscript_programming_language-1.8.0/README.md +0 -51
- pyscript_programming_language-1.8.0/pyscript/core/utils/ansi.py +0 -64
- pyscript_programming_language-1.8.0/pyscript/lib/ansi.pys +0 -10
- pyscript_programming_language-1.8.0/pyscript_programming_language.egg-info/PKG-INFO +0 -86
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/MANIFEST.in +0 -0
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/__init__.py +0 -0
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/__init__.pyi +0 -0
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/__main__.py +0 -0
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/core/__init__.py +0 -0
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/core/analyzer.py +0 -0
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/core/bases.py +0 -0
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/core/checks.py +0 -0
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/core/constants.py +0 -0
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/core/context.py +0 -0
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/core/exceptions.py +0 -0
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/core/handlers.py +0 -0
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/core/highlight.py +0 -0
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/core/interpreter.py +0 -0
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/core/mapping.py +0 -0
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/core/nodes.py +0 -0
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/core/pysbuiltins.py +0 -0
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/core/runner.py +0 -0
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/core/token.py +0 -0
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/core/utils/__init__.py +0 -0
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/core/utils/debug.py +0 -0
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/core/utils/decorators.py +0 -0
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/core/utils/generic.py +0 -0
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/core/utils/module.py +0 -0
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/core/utils/path.py +0 -0
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/core/utils/shell.py +0 -0
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/core/utils/similarity.py +0 -0
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/core/utils/string.py +0 -0
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/lib/__hello__.pys +0 -0
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/lib/ast/__init__.pys +0 -0
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/lib/ast/ast_dump.py +0 -0
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/lib/ast/ast_literal_eval.py +0 -0
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/lib/ast/ast_unparse.py +0 -0
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/lib/ast/ast_walk.py +0 -0
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/lib/brainfuck.pys +0 -0
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/lib/dis.pys +0 -0
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/lib/explorer.pys +0 -0
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/lib/fpstimer.pys +0 -0
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/lib/getch.pys +0 -0
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/lib/inspect.pys +0 -0
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/lib/jsdict.pys +0 -0
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/lib/keyword.pys +0 -0
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/lib/parser.pys +0 -0
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/lib/site.pys +0 -0
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/lib/symtable.pys +0 -0
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/lib/sys.pys +0 -0
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/lib/this.pys +0 -0
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/lib/token.pys +0 -0
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/lib/tokenize/__init__.pys +0 -0
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/lib/tokenize/tok_untokenize.py +0 -0
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/site-packages/67.pys +0 -0
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/this.py +0 -0
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript_programming_language.egg-info/SOURCES.txt +0 -0
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript_programming_language.egg-info/dependency_links.txt +0 -0
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript_programming_language.egg-info/requires.txt +0 -0
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript_programming_language.egg-info/top_level.txt +0 -0
- {pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/setup.cfg +0 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pyscript-programming-language
|
|
3
|
+
Version: 1.8.1
|
|
4
|
+
Summary: PyScript Programming Language
|
|
5
|
+
Home-page: https://azzammuhyala.github.io/pyscript
|
|
6
|
+
Author: azzammuhyala
|
|
7
|
+
Author-email: azzammuhyala@gmail.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Project-URL: Source, https://github.com/azzammuhyala/pyscript
|
|
10
|
+
Project-URL: Bug Tracker, https://github.com/azzammuhyala/pyscript/issues
|
|
11
|
+
Keywords: pyscript,pyslang,pys,programming,language,programming language
|
|
12
|
+
Classifier: Programming Language :: Python
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
16
|
+
Classifier: Topic :: Software Development :: Interpreters
|
|
17
|
+
Classifier: Topic :: Software Development :: Compilers
|
|
18
|
+
Requires-Python: >=3.10
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
Provides-Extra: extras
|
|
21
|
+
Requires-Dist: beartype; extra == "extras"
|
|
22
|
+
Requires-Dist: pygments; extra == "extras"
|
|
23
|
+
Dynamic: author
|
|
24
|
+
Dynamic: author-email
|
|
25
|
+
Dynamic: classifier
|
|
26
|
+
Dynamic: description
|
|
27
|
+
Dynamic: description-content-type
|
|
28
|
+
Dynamic: home-page
|
|
29
|
+
Dynamic: keywords
|
|
30
|
+
Dynamic: license
|
|
31
|
+
Dynamic: project-url
|
|
32
|
+
Dynamic: provides-extra
|
|
33
|
+
Dynamic: requires-python
|
|
34
|
+
Dynamic: summary
|
|
35
|
+
|
|
36
|
+
# PyScript
|
|
37
|
+
|
|
38
|
+
<p align="center">
|
|
39
|
+
<img src="https://github.com/azzammuhyala/pyscript/blob/main/PyScript.png?raw=true" alt="PyScript Logo" width="200">
|
|
40
|
+
</p>
|
|
41
|
+
|
|
42
|
+
PyScript is a simple programming language built on top of Python. It combines some syntax from Python and JavaScript,
|
|
43
|
+
so if you're already familiar with Python or JavaScript, or both, it should be quite easy to learn.
|
|
44
|
+
|
|
45
|
+
## Introduction
|
|
46
|
+
PyScript may not be the language we'll be discussing, but the name PyScript already exists, a flexible and platform for
|
|
47
|
+
running Python in a browser. Since it's inception, the language was inspired by Python and JavaScript, which are
|
|
48
|
+
relatively easy for humans to read. This name was chosen because it wasn't immediately known whether this name was
|
|
49
|
+
already in use.
|
|
50
|
+
|
|
51
|
+
This language wasn't designed to compete with other modern programming languages, but rather as a learning for
|
|
52
|
+
understanding how programming languages work and how human written code can be understood by machines. Furthermore, this
|
|
53
|
+
language was created as a relatively complex project. Using Python as the foundation for PyScript, it's easy to
|
|
54
|
+
understand syntax makes it easy to understand how the language is built without having to understand complex
|
|
55
|
+
instructions like those in C, C++, and other low-level languages.
|
|
56
|
+
|
|
57
|
+
To learn more about PyScript, you can see on [PyScript documentation](https://azzammuhyala.github.io/pyscript) or
|
|
58
|
+
[PyScript repository](https://github.com/azzammuhyala/pyscript) for full source code.
|
|
59
|
+
|
|
60
|
+
## Installation
|
|
61
|
+
First, you'll need to download Python. Make sure you're using the latest version above `3.10`, to ensure the code runs
|
|
62
|
+
correctly. Visit the official [Python website](https://python.org) to download it.
|
|
63
|
+
|
|
64
|
+
Next, after downloading and configuring the Python application, you can download the PyScript interpreter from
|
|
65
|
+
[PyScript releases](https://github.com/azzammuhyala/pyscript/releases) or from Python Pip with this command
|
|
66
|
+
(_Recommended_):
|
|
67
|
+
```sh
|
|
68
|
+
python -m pip install -U pyscript-programming-language
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
After that, you can run the PyScript shell (_REPL_) with this command:
|
|
72
|
+
```sh
|
|
73
|
+
python -m pyscript
|
|
74
|
+
```
|
|
75
|
+
If successful, you can see the version, release date, and a `>>>` like Python shell (_REPL_).
|
|
76
|
+
|
|
77
|
+
> If you are using the VS Code editor, you can use the
|
|
78
|
+
[PyScript extension](https://marketplace.visualstudio.com/items?itemName=azzammuhyala.pyslang) for Syntax Highlight!
|
|
79
|
+
|
|
80
|
+
## Syntax
|
|
81
|
+
<pre><span style="color:#8CDCFE">a</span><span style="color:#D4D4D4"> = </span><span style="color:#4EC9B0">float</span><span style="color:#FFD705">(</span><span style="color:#DCDCAA">input</span><span style="color:#D45DBA">(</span><span style="color:#CE9178">"Enter a first number : "</span><span style="color:#D45DBA">)</span><span style="color:#FFD705">)</span><br><span style="color:#8CDCFE">b</span><span style="color:#D4D4D4"> = </span><span style="color:#4EC9B0">float</span><span style="color:#FFD705">(</span><span style="color:#DCDCAA">input</span><span style="color:#D45DBA">(</span><span style="color:#CE9178">"Enter a second number: "</span><span style="color:#D45DBA">)</span><span style="color:#FFD705">)</span><br><span style="color:#8CDCFE">op</span><span style="color:#D4D4D4"> = </span><span style="color:#DCDCAA">input</span><span style="color:#FFD705">(</span><span style="color:#CE9178">"Enter an operation (+, -, *, /): "</span><span style="color:#FFD705">)</span><br><br><span style="color:#C586C0">switch</span><span style="color:#D4D4D4"> </span><span style="color:#FFD705">(</span><span style="color:#8CDCFE">op</span><span style="color:#D4D4D4">.</span><span style="color:#DCDCAA">strip</span><span style="color:#D45DBA">()</span><span style="color:#FFD705">)</span><br><span style="color:#FFD705">{</span><br><span style="color:#D4D4D4"> </span><span style="color:#C586C0">case</span><span style="color:#D4D4D4"> </span><span style="color:#CE9178">'+'</span><span style="color:#D4D4D4">:</span><br><span style="color:#D4D4D4"> </span><span style="color:#8CDCFE">result</span><span style="color:#D4D4D4"> = </span><span style="color:#8CDCFE">a</span><span style="color:#D4D4D4"> + </span><span style="color:#8CDCFE">b</span><br><span style="color:#D4D4D4"> </span><span style="color:#DCDCAA">print</span><span style="color:#D45DBA">(</span><span style="color:#CE9178">"Result of {} + {} = {}"</span><span style="color:#D4D4D4">.</span><span style="color:#DCDCAA">format</span><span style="color:#1A9FFF">(</span><span style="color:#8CDCFE">a</span><span style="color:#D4D4D4">, </span><span style="color:#8CDCFE">b</span><span style="color:#D4D4D4">, </span><span style="color:#8CDCFE">result</span><span style="color:#1A9FFF">)</span><span style="color:#D45DBA">)</span><br><span style="color:#D4D4D4"> </span><span style="color:#C586C0">break</span><br><br><span style="color:#D4D4D4"> </span><span style="color:#C586C0">case</span><span style="color:#D4D4D4"> </span><span style="color:#CE9178">'-'</span><span style="color:#D4D4D4">:</span><br><span style="color:#D4D4D4"> </span><span style="color:#8CDCFE">result</span><span style="color:#D4D4D4"> = </span><span style="color:#8CDCFE">a</span><span style="color:#D4D4D4"> - </span><span style="color:#8CDCFE">b</span><br><span style="color:#D4D4D4"> </span><span style="color:#DCDCAA">print</span><span style="color:#D45DBA">(</span><span style="color:#CE9178">"Result of {} - {} = {}"</span><span style="color:#D4D4D4">.</span><span style="color:#DCDCAA">format</span><span style="color:#1A9FFF">(</span><span style="color:#8CDCFE">a</span><span style="color:#D4D4D4">, </span><span style="color:#8CDCFE">b</span><span style="color:#D4D4D4">, </span><span style="color:#8CDCFE">result</span><span style="color:#1A9FFF">)</span><span style="color:#D45DBA">)</span><br><span style="color:#D4D4D4"> </span><span style="color:#C586C0">break</span><br><br><span style="color:#D4D4D4"> </span><span style="color:#C586C0">case</span><span style="color:#D4D4D4"> </span><span style="color:#CE9178">'*'</span><span style="color:#D4D4D4">:</span><br><span style="color:#D4D4D4"> </span><span style="color:#8CDCFE">result</span><span style="color:#D4D4D4"> = </span><span style="color:#8CDCFE">a</span><span style="color:#D4D4D4"> * </span><span style="color:#8CDCFE">b</span><br><span style="color:#D4D4D4"> </span><span style="color:#DCDCAA">print</span><span style="color:#D45DBA">(</span><span style="color:#CE9178">"Result of {} * {} = {}"</span><span style="color:#D4D4D4">.</span><span style="color:#DCDCAA">format</span><span style="color:#1A9FFF">(</span><span style="color:#8CDCFE">a</span><span style="color:#D4D4D4">, </span><span style="color:#8CDCFE">b</span><span style="color:#D4D4D4">, </span><span style="color:#8CDCFE">result</span><span style="color:#1A9FFF">)</span><span style="color:#D45DBA">)</span><br><span style="color:#D4D4D4"> </span><span style="color:#C586C0">break</span><br><br><span style="color:#D4D4D4"> </span><span style="color:#C586C0">case</span><span style="color:#D4D4D4"> </span><span style="color:#CE9178">'/'</span><span style="color:#D4D4D4">:</span><br><span style="color:#D4D4D4"> </span><span style="color:#8CDCFE">result</span><span style="color:#D4D4D4"> = </span><span style="color:#8CDCFE">b</span><span style="color:#D4D4D4"> != </span><span style="color:#B5CEA8">0</span><span style="color:#D4D4D4"> ? </span><span style="color:#8CDCFE">a</span><span style="color:#D4D4D4"> / </span><span style="color:#8CDCFE">b</span><span style="color:#D4D4D4"> : </span><span style="color:#CE9178">"Cannot be divided by 0!"</span><br><span style="color:#D4D4D4"> </span><span style="color:#DCDCAA">print</span><span style="color:#D45DBA">(</span><span style="color:#CE9178">"Result of {} / {} = {}"</span><span style="color:#D4D4D4">.</span><span style="color:#DCDCAA">format</span><span style="color:#1A9FFF">(</span><span style="color:#8CDCFE">a</span><span style="color:#D4D4D4">, </span><span style="color:#8CDCFE">b</span><span style="color:#D4D4D4">, </span><span style="color:#8CDCFE">result</span><span style="color:#1A9FFF">)</span><span style="color:#D45DBA">)</span><br><span style="color:#D4D4D4"> </span><span style="color:#C586C0">break</span><br><br><span style="color:#D4D4D4"> </span><span style="color:#C586C0">default</span><span style="color:#D4D4D4">:</span><br><span style="color:#D4D4D4"> </span><span style="color:#DCDCAA">print</span><span style="color:#D45DBA">(</span><span style="color:#CE9178">"Unknown operation"</span><span style="color:#D45DBA">)</span><br><span style="color:#FFD705">}</span></pre>
|
|
82
|
+
|
|
83
|
+
## Behind it
|
|
84
|
+
This language created from based up on a
|
|
85
|
+
[YouTube tutorial](https://www.youtube.com/playlist?list=PLZQftyCk7_SdoVexSmwy_tBgs7P0b97yD) (check more on GitHub [here](https://github.com/davidcallanan/py-myopl-code)). At least, it takes
|
|
86
|
+
about 6 months to learn it, and also need to learn general things that exist in other programming languages.
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# PyScript
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<img src="https://github.com/azzammuhyala/pyscript/blob/main/PyScript.png?raw=true" alt="PyScript Logo" width="200">
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
PyScript is a simple programming language built on top of Python. It combines some syntax from Python and JavaScript,
|
|
8
|
+
so if you're already familiar with Python or JavaScript, or both, it should be quite easy to learn.
|
|
9
|
+
|
|
10
|
+
## Introduction
|
|
11
|
+
PyScript may not be the language we'll be discussing, but the name PyScript already exists, a flexible and platform for
|
|
12
|
+
running Python in a browser. Since it's inception, the language was inspired by Python and JavaScript, which are
|
|
13
|
+
relatively easy for humans to read. This name was chosen because it wasn't immediately known whether this name was
|
|
14
|
+
already in use.
|
|
15
|
+
|
|
16
|
+
This language wasn't designed to compete with other modern programming languages, but rather as a learning for
|
|
17
|
+
understanding how programming languages work and how human written code can be understood by machines. Furthermore, this
|
|
18
|
+
language was created as a relatively complex project. Using Python as the foundation for PyScript, it's easy to
|
|
19
|
+
understand syntax makes it easy to understand how the language is built without having to understand complex
|
|
20
|
+
instructions like those in C, C++, and other low-level languages.
|
|
21
|
+
|
|
22
|
+
To learn more about PyScript, you can see on [PyScript documentation](https://azzammuhyala.github.io/pyscript) or
|
|
23
|
+
[PyScript repository](https://github.com/azzammuhyala/pyscript) for full source code.
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
First, you'll need to download Python. Make sure you're using the latest version above `3.10`, to ensure the code runs
|
|
27
|
+
correctly. Visit the official [Python website](https://python.org) to download it.
|
|
28
|
+
|
|
29
|
+
Next, after downloading and configuring the Python application, you can download the PyScript interpreter from
|
|
30
|
+
[PyScript releases](https://github.com/azzammuhyala/pyscript/releases) or from Python Pip with this command
|
|
31
|
+
(_Recommended_):
|
|
32
|
+
```sh
|
|
33
|
+
python -m pip install -U pyscript-programming-language
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
After that, you can run the PyScript shell (_REPL_) with this command:
|
|
37
|
+
```sh
|
|
38
|
+
python -m pyscript
|
|
39
|
+
```
|
|
40
|
+
If successful, you can see the version, release date, and a `>>>` like Python shell (_REPL_).
|
|
41
|
+
|
|
42
|
+
> If you are using the VS Code editor, you can use the
|
|
43
|
+
[PyScript extension](https://marketplace.visualstudio.com/items?itemName=azzammuhyala.pyslang) for Syntax Highlight!
|
|
44
|
+
|
|
45
|
+
## Syntax
|
|
46
|
+
<pre><span style="color:#8CDCFE">a</span><span style="color:#D4D4D4"> = </span><span style="color:#4EC9B0">float</span><span style="color:#FFD705">(</span><span style="color:#DCDCAA">input</span><span style="color:#D45DBA">(</span><span style="color:#CE9178">"Enter a first number : "</span><span style="color:#D45DBA">)</span><span style="color:#FFD705">)</span><br><span style="color:#8CDCFE">b</span><span style="color:#D4D4D4"> = </span><span style="color:#4EC9B0">float</span><span style="color:#FFD705">(</span><span style="color:#DCDCAA">input</span><span style="color:#D45DBA">(</span><span style="color:#CE9178">"Enter a second number: "</span><span style="color:#D45DBA">)</span><span style="color:#FFD705">)</span><br><span style="color:#8CDCFE">op</span><span style="color:#D4D4D4"> = </span><span style="color:#DCDCAA">input</span><span style="color:#FFD705">(</span><span style="color:#CE9178">"Enter an operation (+, -, *, /): "</span><span style="color:#FFD705">)</span><br><br><span style="color:#C586C0">switch</span><span style="color:#D4D4D4"> </span><span style="color:#FFD705">(</span><span style="color:#8CDCFE">op</span><span style="color:#D4D4D4">.</span><span style="color:#DCDCAA">strip</span><span style="color:#D45DBA">()</span><span style="color:#FFD705">)</span><br><span style="color:#FFD705">{</span><br><span style="color:#D4D4D4"> </span><span style="color:#C586C0">case</span><span style="color:#D4D4D4"> </span><span style="color:#CE9178">'+'</span><span style="color:#D4D4D4">:</span><br><span style="color:#D4D4D4"> </span><span style="color:#8CDCFE">result</span><span style="color:#D4D4D4"> = </span><span style="color:#8CDCFE">a</span><span style="color:#D4D4D4"> + </span><span style="color:#8CDCFE">b</span><br><span style="color:#D4D4D4"> </span><span style="color:#DCDCAA">print</span><span style="color:#D45DBA">(</span><span style="color:#CE9178">"Result of {} + {} = {}"</span><span style="color:#D4D4D4">.</span><span style="color:#DCDCAA">format</span><span style="color:#1A9FFF">(</span><span style="color:#8CDCFE">a</span><span style="color:#D4D4D4">, </span><span style="color:#8CDCFE">b</span><span style="color:#D4D4D4">, </span><span style="color:#8CDCFE">result</span><span style="color:#1A9FFF">)</span><span style="color:#D45DBA">)</span><br><span style="color:#D4D4D4"> </span><span style="color:#C586C0">break</span><br><br><span style="color:#D4D4D4"> </span><span style="color:#C586C0">case</span><span style="color:#D4D4D4"> </span><span style="color:#CE9178">'-'</span><span style="color:#D4D4D4">:</span><br><span style="color:#D4D4D4"> </span><span style="color:#8CDCFE">result</span><span style="color:#D4D4D4"> = </span><span style="color:#8CDCFE">a</span><span style="color:#D4D4D4"> - </span><span style="color:#8CDCFE">b</span><br><span style="color:#D4D4D4"> </span><span style="color:#DCDCAA">print</span><span style="color:#D45DBA">(</span><span style="color:#CE9178">"Result of {} - {} = {}"</span><span style="color:#D4D4D4">.</span><span style="color:#DCDCAA">format</span><span style="color:#1A9FFF">(</span><span style="color:#8CDCFE">a</span><span style="color:#D4D4D4">, </span><span style="color:#8CDCFE">b</span><span style="color:#D4D4D4">, </span><span style="color:#8CDCFE">result</span><span style="color:#1A9FFF">)</span><span style="color:#D45DBA">)</span><br><span style="color:#D4D4D4"> </span><span style="color:#C586C0">break</span><br><br><span style="color:#D4D4D4"> </span><span style="color:#C586C0">case</span><span style="color:#D4D4D4"> </span><span style="color:#CE9178">'*'</span><span style="color:#D4D4D4">:</span><br><span style="color:#D4D4D4"> </span><span style="color:#8CDCFE">result</span><span style="color:#D4D4D4"> = </span><span style="color:#8CDCFE">a</span><span style="color:#D4D4D4"> * </span><span style="color:#8CDCFE">b</span><br><span style="color:#D4D4D4"> </span><span style="color:#DCDCAA">print</span><span style="color:#D45DBA">(</span><span style="color:#CE9178">"Result of {} * {} = {}"</span><span style="color:#D4D4D4">.</span><span style="color:#DCDCAA">format</span><span style="color:#1A9FFF">(</span><span style="color:#8CDCFE">a</span><span style="color:#D4D4D4">, </span><span style="color:#8CDCFE">b</span><span style="color:#D4D4D4">, </span><span style="color:#8CDCFE">result</span><span style="color:#1A9FFF">)</span><span style="color:#D45DBA">)</span><br><span style="color:#D4D4D4"> </span><span style="color:#C586C0">break</span><br><br><span style="color:#D4D4D4"> </span><span style="color:#C586C0">case</span><span style="color:#D4D4D4"> </span><span style="color:#CE9178">'/'</span><span style="color:#D4D4D4">:</span><br><span style="color:#D4D4D4"> </span><span style="color:#8CDCFE">result</span><span style="color:#D4D4D4"> = </span><span style="color:#8CDCFE">b</span><span style="color:#D4D4D4"> != </span><span style="color:#B5CEA8">0</span><span style="color:#D4D4D4"> ? </span><span style="color:#8CDCFE">a</span><span style="color:#D4D4D4"> / </span><span style="color:#8CDCFE">b</span><span style="color:#D4D4D4"> : </span><span style="color:#CE9178">"Cannot be divided by 0!"</span><br><span style="color:#D4D4D4"> </span><span style="color:#DCDCAA">print</span><span style="color:#D45DBA">(</span><span style="color:#CE9178">"Result of {} / {} = {}"</span><span style="color:#D4D4D4">.</span><span style="color:#DCDCAA">format</span><span style="color:#1A9FFF">(</span><span style="color:#8CDCFE">a</span><span style="color:#D4D4D4">, </span><span style="color:#8CDCFE">b</span><span style="color:#D4D4D4">, </span><span style="color:#8CDCFE">result</span><span style="color:#1A9FFF">)</span><span style="color:#D45DBA">)</span><br><span style="color:#D4D4D4"> </span><span style="color:#C586C0">break</span><br><br><span style="color:#D4D4D4"> </span><span style="color:#C586C0">default</span><span style="color:#D4D4D4">:</span><br><span style="color:#D4D4D4"> </span><span style="color:#DCDCAA">print</span><span style="color:#D45DBA">(</span><span style="color:#CE9178">"Unknown operation"</span><span style="color:#D45DBA">)</span><br><span style="color:#FFD705">}</span></pre>
|
|
47
|
+
|
|
48
|
+
## Behind it
|
|
49
|
+
This language created from based up on a
|
|
50
|
+
[YouTube tutorial](https://www.youtube.com/playlist?list=PLZQftyCk7_SdoVexSmwy_tBgs7P0b97yD) (check more on GitHub [here](https://github.com/davidcallanan/py-myopl-code)). At least, it takes
|
|
51
|
+
about 6 months to learn it, and also need to learn general things that exist in other programming languages.
|
{pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/core/buffer.py
RENAMED
|
@@ -13,7 +13,7 @@ class PysFileBuffer(PysBuffer):
|
|
|
13
13
|
|
|
14
14
|
__slots__ = ('text', 'name')
|
|
15
15
|
|
|
16
|
-
def __init__(self, text, name=None):
|
|
16
|
+
def __init__(self, text, name=None) -> None:
|
|
17
17
|
|
|
18
18
|
if isinstance(text, PysFileBuffer):
|
|
19
19
|
name = normstr(text.name if name is None else name)
|
|
@@ -30,5 +30,5 @@ class PysFileBuffer(PysBuffer):
|
|
|
30
30
|
setimuattr(self, 'text', text)
|
|
31
31
|
setimuattr(self, 'name', name)
|
|
32
32
|
|
|
33
|
-
def __repr__(self):
|
|
33
|
+
def __repr__(self) -> str:
|
|
34
34
|
return f'<FileBuffer from {self.name!r}>'
|
{pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/core/cache.py
RENAMED
|
@@ -4,6 +4,7 @@ from .utils.debug import print_display, print_traceback
|
|
|
4
4
|
from .utils.decorators import inheritable, singleton
|
|
5
5
|
|
|
6
6
|
from threading import RLock
|
|
7
|
+
from typing import Literal
|
|
7
8
|
|
|
8
9
|
loading_modules = set()
|
|
9
10
|
lock = RLock()
|
|
@@ -17,15 +18,15 @@ class PysUndefined(Pys):
|
|
|
17
18
|
|
|
18
19
|
__slots__ = ()
|
|
19
20
|
|
|
20
|
-
def __new_singleton__(cls):
|
|
21
|
+
def __new_singleton__(cls) -> 'PysUndefined':
|
|
21
22
|
global undefined
|
|
22
23
|
undefined = super(cls, cls).__new__(cls)
|
|
23
24
|
return undefined
|
|
24
25
|
|
|
25
|
-
def __repr__(self):
|
|
26
|
+
def __repr__(self) -> Literal['undefined']:
|
|
26
27
|
return 'undefined'
|
|
27
28
|
|
|
28
|
-
def __bool__(self):
|
|
29
|
+
def __bool__(self) -> Literal[False]:
|
|
29
30
|
return False
|
|
30
31
|
|
|
31
32
|
@singleton
|
{pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/core/lexer.py
RENAMED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
from .bases import Pys
|
|
2
2
|
from .buffer import PysFileBuffer
|
|
3
3
|
from .checks import is_keyword
|
|
4
|
-
from .constants import TOKENS, DEFAULT, SILENT, HIGHLIGHT
|
|
4
|
+
from .constants import TOKENS, DEFAULT, SILENT, HIGHLIGHT, NO_COLOR
|
|
5
5
|
from .context import PysContext
|
|
6
6
|
from .exceptions import PysTraceback
|
|
7
|
-
from .position import PysPosition
|
|
7
|
+
from .position import PysPosition, format_arrow
|
|
8
8
|
from .token import PysToken
|
|
9
9
|
from .utils.decorators import typechecked
|
|
10
|
+
from .utils.string import indent
|
|
10
11
|
|
|
11
12
|
from unicodedata import lookup as unicode_lookup
|
|
12
13
|
from types import MappingProxyType
|
|
@@ -57,7 +58,7 @@ class PysLexer(Pys):
|
|
|
57
58
|
self.update_current_character()
|
|
58
59
|
|
|
59
60
|
def not_end_of_file(self):
|
|
60
|
-
return self.current_character is not None
|
|
61
|
+
return self.current_character is not None and self.error is None
|
|
61
62
|
|
|
62
63
|
def character_in(self, characters):
|
|
63
64
|
return self.not_end_of_file() and self.current_character in characters
|
|
@@ -521,8 +522,17 @@ class PysLexer(Pys):
|
|
|
521
522
|
string += '\\'
|
|
522
523
|
break
|
|
523
524
|
|
|
524
|
-
|
|
525
|
-
|
|
525
|
+
position = PysPosition(self.file, self.index, self.index + 1)
|
|
526
|
+
character = self.current_character
|
|
527
|
+
|
|
528
|
+
string += '\\' + character
|
|
529
|
+
self.warning(
|
|
530
|
+
f"{self.file.name}:{position.start_line}:{position.start_column + 1}: "
|
|
531
|
+
f"SyntaxWarning: \"\\{character}\" "
|
|
532
|
+
"is an invalid escape sequence. Such sequences will not work in the future. Did you mean "
|
|
533
|
+
f"\"\\\\{character}\"? A raw string is also an option.\n" +
|
|
534
|
+
indent(format_arrow(position, not (self.flags & NO_COLOR)), 2)
|
|
535
|
+
)
|
|
526
536
|
self.advance()
|
|
527
537
|
|
|
528
538
|
else:
|
{pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/core/objects.py
RENAMED
|
@@ -60,6 +60,7 @@ class PysFunction(PysObject):
|
|
|
60
60
|
context=context,
|
|
61
61
|
visit=visit,
|
|
62
62
|
call_context=context,
|
|
63
|
+
parameters_length=len(parameters),
|
|
63
64
|
argument_names=tuple(item for item in parameters if not isinstance(item, tuple)),
|
|
64
65
|
keyword_argument_names=tuple(item[0] for item in parameters if isinstance(item, tuple)),
|
|
65
66
|
parameter_names=tuple(item[0] if isinstance(item, tuple) else item for item in parameters),
|
|
@@ -78,9 +79,9 @@ class PysFunction(PysObject):
|
|
|
78
79
|
code_position = code.position
|
|
79
80
|
code_context = code.context
|
|
80
81
|
code_call_context = code.call_context
|
|
82
|
+
code_parameters_length = code.parameters_length
|
|
81
83
|
code_parameter_names = code.parameter_names
|
|
82
|
-
|
|
83
|
-
total_parameters = len(code.parameters)
|
|
84
|
+
arguments_length = len(args)
|
|
84
85
|
|
|
85
86
|
result = PysRunTimeResult()
|
|
86
87
|
symbol_table = PysSymbolTable(code_context.symbol_table)
|
|
@@ -138,7 +139,7 @@ class PysFunction(PysObject):
|
|
|
138
139
|
|
|
139
140
|
total_registered = len(registered_arguments)
|
|
140
141
|
|
|
141
|
-
if total_registered <
|
|
142
|
+
if total_registered < code_parameters_length:
|
|
142
143
|
missing_arguments = [repr(name) for name in code_parameter_names if name not in registered_arguments]
|
|
143
144
|
total_missing = len(missing_arguments)
|
|
144
145
|
|
|
@@ -159,19 +160,19 @@ class PysFunction(PysObject):
|
|
|
159
160
|
)
|
|
160
161
|
)
|
|
161
162
|
|
|
162
|
-
elif total_registered >
|
|
163
|
-
given_arguments =
|
|
163
|
+
elif total_registered > code_parameters_length or arguments_length > code_parameters_length:
|
|
164
|
+
given_arguments = arguments_length if arguments_length > code_parameters_length else total_registered
|
|
164
165
|
|
|
165
166
|
raise PysSignal(
|
|
166
167
|
result.failure(
|
|
167
168
|
PysTraceback(
|
|
168
169
|
TypeError(
|
|
169
170
|
f"{qualname}() takes no arguments ({given_arguments} given)"
|
|
170
|
-
if
|
|
171
|
+
if code_parameters_length == 0 else
|
|
171
172
|
"{}() takes {} positional argument{} but {} were given".format(
|
|
172
173
|
qualname,
|
|
173
|
-
|
|
174
|
-
'' if
|
|
174
|
+
code_parameters_length,
|
|
175
|
+
'' if code_parameters_length == 1 else 's',
|
|
175
176
|
given_arguments
|
|
176
177
|
)
|
|
177
178
|
),
|
{pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/core/parser.py
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from .bases import Pys
|
|
2
|
-
from .checks import is_right_bracket
|
|
2
|
+
from .checks import is_left_bracket, is_right_bracket
|
|
3
3
|
from .constants import TOKENS, KEYWORDS, DEFAULT, REVERSE_POW_XOR
|
|
4
4
|
from .context import PysContext
|
|
5
5
|
from .exceptions import PysTraceback
|
|
@@ -982,6 +982,9 @@ class PysParser(Pys):
|
|
|
982
982
|
self.advance()
|
|
983
983
|
self.skip(result)
|
|
984
984
|
|
|
985
|
+
elif is_left_bracket(self.current_token.type):
|
|
986
|
+
return result.failure(self.new_error(f"expected '(' not {chr(self.current_token.type)!r}"))
|
|
987
|
+
|
|
985
988
|
if self.current_token.type != TOKENS['IDENTIFIER']:
|
|
986
989
|
return result.failure(self.new_error("expected identifier"))
|
|
987
990
|
|
|
@@ -1262,9 +1265,9 @@ class PysParser(Pys):
|
|
|
1262
1265
|
target = None
|
|
1263
1266
|
|
|
1264
1267
|
if self.current_token.type != TOKENS['LEFT-CURLY']:
|
|
1265
|
-
target = result.
|
|
1268
|
+
target = result.register(self.walrus(), True)
|
|
1266
1269
|
if result.error:
|
|
1267
|
-
return result
|
|
1270
|
+
return result.failure(self.new_error("expected expression or '{'"))
|
|
1268
1271
|
|
|
1269
1272
|
self.skip(result)
|
|
1270
1273
|
|
|
@@ -1481,6 +1484,8 @@ class PysParser(Pys):
|
|
|
1481
1484
|
self.advance()
|
|
1482
1485
|
self.skip(result)
|
|
1483
1486
|
|
|
1487
|
+
bracket = False
|
|
1488
|
+
|
|
1484
1489
|
if self.current_token.type == TOKENS['LEFT-PARENTHESIS']:
|
|
1485
1490
|
bracket = True
|
|
1486
1491
|
left_bracket_token = self.current_token
|
|
@@ -1490,9 +1495,6 @@ class PysParser(Pys):
|
|
|
1490
1495
|
self.advance()
|
|
1491
1496
|
self.skip(result)
|
|
1492
1497
|
|
|
1493
|
-
else:
|
|
1494
|
-
bracket = False
|
|
1495
|
-
|
|
1496
1498
|
contexts = []
|
|
1497
1499
|
|
|
1498
1500
|
while True:
|
|
@@ -1978,6 +1980,9 @@ class PysParser(Pys):
|
|
|
1978
1980
|
self.advance()
|
|
1979
1981
|
self.skip(result)
|
|
1980
1982
|
|
|
1983
|
+
elif is_left_bracket(self.current_token.type):
|
|
1984
|
+
return result.failure(self.new_error(f"expected '(' not {chr(self.current_token.type)!r}"))
|
|
1985
|
+
|
|
1981
1986
|
if self.current_token.type != TOKENS['IDENTIFIER']:
|
|
1982
1987
|
return result.failure(self.new_error("expected identifier"))
|
|
1983
1988
|
|
|
@@ -22,7 +22,7 @@ class PysPosition(Pys):
|
|
|
22
22
|
setimuattr(self, 'end_column', -1 if is_positionless else end - file.text.rfind('\n', 0, end))
|
|
23
23
|
setimuattr(self, 'is_positionless', is_positionless)
|
|
24
24
|
|
|
25
|
-
def __repr__(self):
|
|
25
|
+
def __repr__(self) -> str:
|
|
26
26
|
return f'<Position({self.start!r}, {self.end!r}) from {self.file.name!r}>'
|
|
27
27
|
|
|
28
28
|
def format_arrow(position, colored=True):
|
{pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/core/results.py
RENAMED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
from .bases import Pys
|
|
2
2
|
from .cache import hook
|
|
3
|
+
from .context import PysContext
|
|
3
4
|
from .exceptions import PysTraceback, PysSignal
|
|
4
5
|
from .position import PysPosition
|
|
5
6
|
from .utils.debug import print_traceback
|
|
6
7
|
from .utils.generic import get_error_args
|
|
7
8
|
|
|
9
|
+
from typing import Any
|
|
10
|
+
|
|
8
11
|
class PysResult(Pys):
|
|
9
12
|
__slots__ = ()
|
|
10
13
|
|
|
@@ -140,23 +143,23 @@ class PysRunTimeResult(PysResult):
|
|
|
140
143
|
|
|
141
144
|
class PysExecuteResult(PysResult):
|
|
142
145
|
|
|
143
|
-
def __init__(self, context):
|
|
146
|
+
def __init__(self, context: PysContext) -> None:
|
|
144
147
|
self.context = context
|
|
145
148
|
|
|
146
149
|
self.value = None
|
|
147
150
|
self.error = None
|
|
148
151
|
|
|
149
|
-
def success(self, value):
|
|
152
|
+
def success(self, value: Any) -> 'PysExecuteResult':
|
|
150
153
|
self.value = value
|
|
151
154
|
return self
|
|
152
155
|
|
|
153
|
-
def failure(self, error):
|
|
156
|
+
def failure(self, error: PysTraceback) -> 'PysExecuteResult':
|
|
154
157
|
self.error = error
|
|
155
158
|
return self
|
|
156
159
|
|
|
157
160
|
# --- HANDLE EXECUTE ---
|
|
158
161
|
|
|
159
|
-
def process(self):
|
|
162
|
+
def process(self) -> tuple[int | Any, bool]:
|
|
160
163
|
result = PysRunTimeResult()
|
|
161
164
|
|
|
162
165
|
with result(self.context, PysPosition(self.context.file, -1, -1)):
|
{pyscript_programming_language-1.8.0 → pyscript_programming_language-1.8.1}/pyscript/core/symtab.py
RENAMED
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
from .bases import Pys
|
|
2
2
|
from .checks import is_equals
|
|
3
3
|
from .constants import TOKENS
|
|
4
|
-
from .cache import undefined
|
|
4
|
+
from .cache import PysUndefined, undefined
|
|
5
5
|
from .mapping import BINARY_FUNCTIONS_MAP, EMPTY_MAP
|
|
6
6
|
from .utils.decorators import immutable
|
|
7
7
|
from .utils.generic import setimuattr
|
|
8
8
|
from .utils.similarity import get_closest
|
|
9
9
|
|
|
10
10
|
from types import ModuleType
|
|
11
|
+
from typing import Any, Optional
|
|
11
12
|
|
|
12
13
|
@immutable
|
|
13
14
|
class PysSymbolTable(Pys):
|
|
14
15
|
|
|
15
16
|
__slots__ = ('parent', 'symbols', 'globals')
|
|
16
17
|
|
|
17
|
-
def __init__(self, parent=None):
|
|
18
|
+
def __init__(self, parent: Optional['PysSymbolTable'] = None) -> None:
|
|
18
19
|
setimuattr(self, 'parent', parent.parent if isinstance(parent, PysClassSymbolTable) else parent)
|
|
19
20
|
setimuattr(self, 'symbols', {})
|
|
20
21
|
setimuattr(self, 'globals', set())
|
|
21
22
|
|
|
22
|
-
def get(self, name):
|
|
23
|
+
def get(self, name: str) -> Any | PysUndefined:
|
|
23
24
|
value = self.symbols.get(name, undefined)
|
|
24
25
|
|
|
25
26
|
if value is undefined:
|
|
@@ -34,7 +35,7 @@ class PysSymbolTable(Pys):
|
|
|
34
35
|
|
|
35
36
|
return value
|
|
36
37
|
|
|
37
|
-
def set(self, name, value, *, operand=TOKENS['EQUAL']):
|
|
38
|
+
def set(self, name: str, value: Any, *, operand: int = TOKENS['EQUAL']) -> bool:
|
|
38
39
|
if is_equals(operand):
|
|
39
40
|
|
|
40
41
|
if name in self.globals and self.parent:
|
|
@@ -53,7 +54,7 @@ class PysSymbolTable(Pys):
|
|
|
53
54
|
self.symbols[name] = BINARY_FUNCTIONS_MAP[operand](self.symbols[name], value)
|
|
54
55
|
return True
|
|
55
56
|
|
|
56
|
-
def remove(self, name):
|
|
57
|
+
def remove(self, name: str) -> bool:
|
|
57
58
|
if name not in self.symbols:
|
|
58
59
|
if name in self.globals and self.parent:
|
|
59
60
|
return self.parent.remove(name)
|
|
@@ -66,7 +67,7 @@ class PysClassSymbolTable(PysSymbolTable):
|
|
|
66
67
|
|
|
67
68
|
__slots__ = ()
|
|
68
69
|
|
|
69
|
-
def __init__(self, parent):
|
|
70
|
+
def __init__(self, parent: PysSymbolTable) -> None:
|
|
70
71
|
super().__init__(parent)
|
|
71
72
|
|
|
72
73
|
def find_closest(symtab, name):
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
from collections.abc import Iterable
|
|
2
|
+
from functools import reduce
|
|
3
|
+
from html.parser import HTMLParser
|
|
4
|
+
from operator import or_
|
|
5
|
+
from types import MappingProxyType
|
|
6
|
+
|
|
7
|
+
DEFAULT = 0
|
|
8
|
+
BACKGROUND = 1 << 0
|
|
9
|
+
BOLD = 1 << 1
|
|
10
|
+
FAINT = 1 << 2
|
|
11
|
+
ITALIC = 1 << 3
|
|
12
|
+
UNDERLINE = 1 << 4
|
|
13
|
+
BLINK = 1 << 5
|
|
14
|
+
RAPIDBLINK = 1 << 6
|
|
15
|
+
STRIKETHROUGH = 1 << 7
|
|
16
|
+
DOUBLEUNDERLINE = 1 << 8
|
|
17
|
+
|
|
18
|
+
ANSI_NAMES_MAP = MappingProxyType({
|
|
19
|
+
'reset': 0,
|
|
20
|
+
'black': 30,
|
|
21
|
+
'red': 31,
|
|
22
|
+
'green': 32,
|
|
23
|
+
'yellow': 33,
|
|
24
|
+
'blue': 34,
|
|
25
|
+
'magenta': 35,
|
|
26
|
+
'cyan': 36,
|
|
27
|
+
'white': 37,
|
|
28
|
+
'gray': 90,
|
|
29
|
+
'bright-black': 90,
|
|
30
|
+
'bright-red': 91,
|
|
31
|
+
'bright-green': 92,
|
|
32
|
+
'bright-yellow': 93,
|
|
33
|
+
'bright-blue': 94,
|
|
34
|
+
'bright-magenta': 95,
|
|
35
|
+
'bright-cyan': 96,
|
|
36
|
+
'bright-white': 97
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
STYLE_MAP = MappingProxyType({
|
|
40
|
+
'DEFAULT': DEFAULT,
|
|
41
|
+
'BACKGROUND': BACKGROUND,
|
|
42
|
+
'BOLD': BOLD,
|
|
43
|
+
'FAINT': FAINT,
|
|
44
|
+
'ITALIC': ITALIC,
|
|
45
|
+
'UNDERLINE': UNDERLINE,
|
|
46
|
+
'BLINK': BLINK,
|
|
47
|
+
'RAPIDBLINK': RAPIDBLINK,
|
|
48
|
+
'STRIKETHROUGH': STRIKETHROUGH,
|
|
49
|
+
'DOUBLEUNDERLINE': DOUBLEUNDERLINE,
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
def acolor(*args, style: int = DEFAULT) -> str:
|
|
53
|
+
if not args:
|
|
54
|
+
raise TypeError("acolor(): need at least 1 argument")
|
|
55
|
+
elif len(args) == 1:
|
|
56
|
+
arg = args[0]
|
|
57
|
+
else:
|
|
58
|
+
arg = args
|
|
59
|
+
|
|
60
|
+
styles = ''
|
|
61
|
+
|
|
62
|
+
if style & BOLD:
|
|
63
|
+
styles += '1'
|
|
64
|
+
if style & ITALIC:
|
|
65
|
+
styles += '3'
|
|
66
|
+
if style & UNDERLINE:
|
|
67
|
+
styles += '4'
|
|
68
|
+
if style & STRIKETHROUGH:
|
|
69
|
+
styles += '9'
|
|
70
|
+
|
|
71
|
+
offset = 10 if style & BACKGROUND else 0
|
|
72
|
+
style = f'\x1b[{";".join(styles)}m' if styles else ''
|
|
73
|
+
|
|
74
|
+
if isinstance(arg, str):
|
|
75
|
+
if (color := arg.strip().lower().replace(' ', '-').replace('_', '-')) in ANSI_NAMES_MAP:
|
|
76
|
+
return f'{style}\x1b[{ANSI_NAMES_MAP[color] + offset}m'
|
|
77
|
+
arg = arg.replace(',', ' ').split()
|
|
78
|
+
|
|
79
|
+
if isinstance(arg, Iterable):
|
|
80
|
+
color = tuple(map(int, arg))
|
|
81
|
+
if len(color) == 3 and all(0 <= c <= 255 for c in color):
|
|
82
|
+
return f'{style}\x1b[{38 + offset};2;{";".join(map(str, color))}m'
|
|
83
|
+
|
|
84
|
+
raise TypeError("acolor(): the argument is invalid for ansi color")
|
|
85
|
+
|
|
86
|
+
class AnsiParser(HTMLParser):
|
|
87
|
+
|
|
88
|
+
def __init__(self):
|
|
89
|
+
super().__init__()
|
|
90
|
+
self.result = []
|
|
91
|
+
self.stack = 0
|
|
92
|
+
|
|
93
|
+
def handle_starttag(self, tag, attrs):
|
|
94
|
+
if tag != 'ansi':
|
|
95
|
+
raise ValueError(f'unknown tag: {tag}')
|
|
96
|
+
|
|
97
|
+
attrs = dict(attrs)
|
|
98
|
+
|
|
99
|
+
color = attrs.get('color')
|
|
100
|
+
if color is None:
|
|
101
|
+
color = (attrs['r'], attrs['g'], attrs['b'])
|
|
102
|
+
styles = attrs.get('style', 'DEFAULT').split()
|
|
103
|
+
|
|
104
|
+
self.result.append(acolor(color, style=reduce(or_, (STYLE_MAP[style].upper() for style in styles))))
|
|
105
|
+
self.stack += 1
|
|
106
|
+
|
|
107
|
+
def handle_endtag(self, tag):
|
|
108
|
+
if self.stack <= 0:
|
|
109
|
+
raise SyntaxError(f'unmatch tag: {tag}')
|
|
110
|
+
if tag != 'ansi':
|
|
111
|
+
raise ValueError(f'unknown tag: {tag}')
|
|
112
|
+
|
|
113
|
+
self.result.append(acolor('reset'))
|
|
114
|
+
self.stack -= 1
|
|
115
|
+
|
|
116
|
+
def handle_data(self, data):
|
|
117
|
+
self.result.append(data)
|
|
118
|
+
|
|
119
|
+
def get_output(self):
|
|
120
|
+
return ''.join(self.result)
|
|
121
|
+
|
|
122
|
+
def fansi(string: str) -> str:
|
|
123
|
+
parser = AnsiParser()
|
|
124
|
+
parser.feed(string)
|
|
125
|
+
return parser.get_output()
|