pyscript-programming-language 1.6.0a1__tar.gz → 1.7.0__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.6.0a1 → pyscript_programming_language-1.7.0}/PKG-INFO +24 -4
- pyscript_programming_language-1.7.0/README.md +51 -0
- {pyscript_programming_language-1.6.0a1 → pyscript_programming_language-1.7.0}/pyscript/__init__.py +7 -5
- {pyscript_programming_language-1.6.0a1 → pyscript_programming_language-1.7.0}/pyscript/__init__.pyi +17 -10
- {pyscript_programming_language-1.6.0a1 → pyscript_programming_language-1.7.0}/pyscript/__main__.py +27 -52
- {pyscript_programming_language-1.6.0a1 → pyscript_programming_language-1.7.0}/pyscript/core/__init__.py +0 -2
- {pyscript_programming_language-1.6.0a1 → pyscript_programming_language-1.7.0}/pyscript/core/analyzer.py +39 -33
- {pyscript_programming_language-1.6.0a1 → pyscript_programming_language-1.7.0}/pyscript/core/buffer.py +2 -1
- {pyscript_programming_language-1.6.0a1 → pyscript_programming_language-1.7.0}/pyscript/core/cache.py +23 -7
- {pyscript_programming_language-1.6.0a1 → pyscript_programming_language-1.7.0}/pyscript/core/checks.py +13 -12
- {pyscript_programming_language-1.6.0a1 → pyscript_programming_language-1.7.0}/pyscript/core/constants.py +26 -22
- {pyscript_programming_language-1.6.0a1 → pyscript_programming_language-1.7.0}/pyscript/core/exceptions.py +24 -28
- pyscript_programming_language-1.7.0/pyscript/core/handlers.py +61 -0
- pyscript_programming_language-1.7.0/pyscript/core/highlight.py +373 -0
- {pyscript_programming_language-1.6.0a1 → pyscript_programming_language-1.7.0}/pyscript/core/interpreter.py +211 -206
- {pyscript_programming_language-1.6.0a1 → pyscript_programming_language-1.7.0}/pyscript/core/lexer.py +73 -54
- {pyscript_programming_language-1.6.0a1 → pyscript_programming_language-1.7.0}/pyscript/core/mapping.py +16 -16
- {pyscript_programming_language-1.6.0a1 → pyscript_programming_language-1.7.0}/pyscript/core/nodes.py +41 -35
- {pyscript_programming_language-1.6.0a1 → pyscript_programming_language-1.7.0}/pyscript/core/objects.py +16 -51
- {pyscript_programming_language-1.6.0a1 → pyscript_programming_language-1.7.0}/pyscript/core/parser.py +209 -241
- {pyscript_programming_language-1.6.0a1 → pyscript_programming_language-1.7.0}/pyscript/core/position.py +5 -5
- {pyscript_programming_language-1.6.0a1 → pyscript_programming_language-1.7.0}/pyscript/core/pysbuiltins.py +147 -70
- {pyscript_programming_language-1.6.0a1 → pyscript_programming_language-1.7.0}/pyscript/core/results.py +64 -5
- pyscript_programming_language-1.7.0/pyscript/core/runner.py +286 -0
- {pyscript_programming_language-1.6.0a1 → pyscript_programming_language-1.7.0}/pyscript/core/symtab.py +12 -7
- pyscript_programming_language-1.7.0/pyscript/core/utils/__init__.py +23 -0
- pyscript_programming_language-1.7.0/pyscript/core/utils/ansi.py +37 -0
- {pyscript_programming_language-1.6.0a1 → pyscript_programming_language-1.7.0}/pyscript/core/utils/debug.py +6 -6
- {pyscript_programming_language-1.6.0a1 → pyscript_programming_language-1.7.0}/pyscript/core/utils/decorators.py +20 -10
- pyscript_programming_language-1.7.0/pyscript/core/utils/generic.py +47 -0
- pyscript_programming_language-1.7.0/pyscript/core/utils/module.py +25 -0
- pyscript_programming_language-1.7.0/pyscript/core/utils/path.py +26 -0
- pyscript_programming_language-1.7.0/pyscript/core/utils/shell.py +109 -0
- pyscript_programming_language-1.7.0/pyscript/core/utils/similarity.py +22 -0
- pyscript_programming_language-1.7.0/pyscript/core/utils/string.py +40 -0
- {pyscript_programming_language-1.6.0a1 → pyscript_programming_language-1.7.0}/pyscript/core/version.py +10 -7
- pyscript_programming_language-1.7.0/pyscript/lib/ansi.pys +10 -0
- {pyscript_programming_language-1.6.0a1 → pyscript_programming_language-1.7.0}/pyscript/lib/ast/__init__.pys +6 -3
- pyscript_programming_language-1.7.0/pyscript/lib/ast/ast_dump.py +406 -0
- pyscript_programming_language-1.7.0/pyscript/lib/ast/ast_unparse.py +557 -0
- pyscript_programming_language-1.7.0/pyscript/lib/ast/ast_walk.py +242 -0
- pyscript_programming_language-1.7.0/pyscript/lib/dis.pys +7 -0
- {pyscript_programming_language-1.6.0a1 → pyscript_programming_language-1.7.0}/pyscript/lib/explorer.pys +18 -18
- {pyscript_programming_language-1.6.0a1 → pyscript_programming_language-1.7.0}/pyscript/lib/fpstimer.pys +10 -10
- pyscript_programming_language-1.7.0/pyscript/lib/inspect.pys +42 -0
- pyscript_programming_language-1.7.0/pyscript/lib/jsdict.pys +21 -0
- pyscript_programming_language-1.7.0/pyscript/lib/keyword.pys +2 -0
- {pyscript_programming_language-1.6.0a1 → pyscript_programming_language-1.7.0}/pyscript/lib/parser.pys +30 -11
- pyscript_programming_language-1.7.0/pyscript/lib/site.pys +58 -0
- pyscript_programming_language-1.7.0/pyscript/lib/symtable.pys +5 -0
- {pyscript_programming_language-1.6.0a1 → pyscript_programming_language-1.7.0}/pyscript/lib/sys.pys +2 -1
- {pyscript_programming_language-1.6.0a1 → pyscript_programming_language-1.7.0}/pyscript/lib/this.pys +1 -1
- pyscript_programming_language-1.7.0/pyscript/lib/tokenize/__init__.pys +12 -0
- pyscript_programming_language-1.7.0/pyscript/lib/tokenize/tok_untokenize.py +88 -0
- pyscript_programming_language-1.7.0/pyscript/site-packages/67.pys +1 -0
- {pyscript_programming_language-1.6.0a1 → pyscript_programming_language-1.7.0}/pyscript_programming_language.egg-info/PKG-INFO +24 -4
- {pyscript_programming_language-1.6.0a1 → pyscript_programming_language-1.7.0}/pyscript_programming_language.egg-info/SOURCES.txt +12 -2
- {pyscript_programming_language-1.6.0a1 → pyscript_programming_language-1.7.0}/setup.py +1 -1
- pyscript_programming_language-1.6.0a1/README.md +0 -31
- pyscript_programming_language-1.6.0a1/pyscript/core/handlers.py +0 -111
- pyscript_programming_language-1.6.0a1/pyscript/core/highlight.py +0 -218
- pyscript_programming_language-1.6.0a1/pyscript/core/runner.py +0 -368
- pyscript_programming_language-1.6.0a1/pyscript/core/utils/__init__.py +0 -11
- pyscript_programming_language-1.6.0a1/pyscript/core/utils/generic.py +0 -152
- pyscript_programming_language-1.6.0a1/pyscript/lib/ast/pysast.py +0 -670
- pyscript_programming_language-1.6.0a1/pyscript/lib/dis.pys +0 -11
- pyscript_programming_language-1.6.0a1/pyscript/lib/inspect.pys +0 -34
- pyscript_programming_language-1.6.0a1/pyscript/lib/jsdict.pys +0 -28
- pyscript_programming_language-1.6.0a1/pyscript/lib/keyword.pys +0 -2
- pyscript_programming_language-1.6.0a1/pyscript/lib/site.pys +0 -34
- pyscript_programming_language-1.6.0a1/pyscript/lib/symtable.pys +0 -1
- pyscript_programming_language-1.6.0a1/pyscript/lib/tokenize.pys +0 -4
- pyscript_programming_language-1.6.0a1/pyscript/site-packages/67.pys +0 -1
- {pyscript_programming_language-1.6.0a1 → pyscript_programming_language-1.7.0}/MANIFEST.in +0 -0
- {pyscript_programming_language-1.6.0a1 → pyscript_programming_language-1.7.0}/pyscript/core/bases.py +0 -0
- {pyscript_programming_language-1.6.0a1 → pyscript_programming_language-1.7.0}/pyscript/core/context.py +0 -0
- {pyscript_programming_language-1.6.0a1 → pyscript_programming_language-1.7.0}/pyscript/core/token.py +0 -0
- {pyscript_programming_language-1.6.0a1 → pyscript_programming_language-1.7.0}/pyscript/lib/__hello__.pys +0 -0
- {pyscript_programming_language-1.6.0a1 → pyscript_programming_language-1.7.0}/pyscript/lib/brainfuck.pys +0 -0
- {pyscript_programming_language-1.6.0a1 → pyscript_programming_language-1.7.0}/pyscript/lib/getch.pys +0 -0
- {pyscript_programming_language-1.6.0a1 → pyscript_programming_language-1.7.0}/pyscript/lib/token.pys +0 -0
- {pyscript_programming_language-1.6.0a1 → pyscript_programming_language-1.7.0}/pyscript/this.py +0 -0
- {pyscript_programming_language-1.6.0a1 → pyscript_programming_language-1.7.0}/pyscript_programming_language.egg-info/dependency_links.txt +0 -0
- {pyscript_programming_language-1.6.0a1 → pyscript_programming_language-1.7.0}/pyscript_programming_language.egg-info/requires.txt +0 -0
- {pyscript_programming_language-1.6.0a1 → pyscript_programming_language-1.7.0}/pyscript_programming_language.egg-info/top_level.txt +0 -0
- {pyscript_programming_language-1.6.0a1 → pyscript_programming_language-1.7.0}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pyscript-programming-language
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.7.0
|
|
4
4
|
Summary: PyScript Programming Language
|
|
5
5
|
Home-page: https://github.com/azzammuhyala/pyscript
|
|
6
6
|
Author: azzammuhyala
|
|
@@ -53,11 +53,31 @@ language was created as a relatively complex project. Using Python as the founda
|
|
|
53
53
|
understand syntax makes it easy to understand how the language is built without having to understand complex
|
|
54
54
|
instructions like those in C, C++, and other low-level languages.
|
|
55
55
|
|
|
56
|
-
To learn more about PyScript, you can see on [PyScript documentation
|
|
57
|
-
[PyScript repository](https://github.com/azzammuhyala/pyscript).
|
|
56
|
+
To learn more about PyScript, you can see on [PyScript documentation](https://azzammuhyala.github.io/pyscript) or
|
|
57
|
+
[PyScript repository](https://github.com/azzammuhyala/pyscript) for full source code.
|
|
58
|
+
|
|
59
|
+
## Installation
|
|
60
|
+
First, you'll need to download Python. Make sure you're using the latest version above `3.10`, to ensure the code runs
|
|
61
|
+
correctly. Visit the official [Python website](https://python.org) to download it.
|
|
62
|
+
|
|
63
|
+
Next, after downloading and configuring the Python application, you can download the PyScript interpreter from
|
|
64
|
+
[PyScript releases](https://github.com/azzammuhyala/pyscript/releases) or from Python Pip with this command
|
|
65
|
+
(_Recommended_):
|
|
66
|
+
```sh
|
|
67
|
+
python -m pip install -U pyscript-programming-language
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
After that, you can run the PyScript shell (_REPL_) with this command:
|
|
71
|
+
```sh
|
|
72
|
+
python -m pyscript
|
|
73
|
+
```
|
|
74
|
+
If successful, you can see the version, release date, and a `>>>` like Python shell (_REPL_).
|
|
75
|
+
|
|
76
|
+
> If you are using the VS Code editor, you can use the
|
|
77
|
+
[PyScript extension](https://marketplace.visualstudio.com/items?itemName=azzammuhyala.pyslang) for Syntax Highlight!
|
|
58
78
|
|
|
59
79
|
## Syntax
|
|
60
|
-
<pre
|
|
80
|
+
<pre><span style="color:#C586C0">func</span><span style="color:#D4D4D4"> </span><span style="color:#DCDCAA">greet</span><span style="color:#FFD705">(</span><span style="color:#8CDCFE">name</span><span style="color:#FFD705">)</span><span style="color:#D4D4D4"> </span><span style="color:#FFD705">{</span><br><span style="color:#D4D4D4"> </span><span style="color:#DCDCAA">print</span><span style="color:#D45DBA">(</span><span style="color:#CE9178">"Hello, "</span><span style="color:#D4D4D4"> + </span><span style="color:#8CDCFE">name</span><span style="color:#D4D4D4">.</span><span style="color:#DCDCAA">title</span><span style="color:#1A9FFF">()</span><span style="color:#D4D4D4"> + </span><span style="color:#CE9178">"!"</span><span style="color:#D45DBA">)</span><br><span style="color:#FFD705">}</span><br><br><span style="color:#DCDCAA">greet</span><span style="color:#FFD705">(</span><span style="color:#CE9178">"charlie klik"</span><span style="color:#FFD705">)</span></pre>
|
|
61
81
|
|
|
62
82
|
## Behind it
|
|
63
83
|
This language created from based up on a
|
|
@@ -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 PyScript
|
|
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:#C586C0">func</span><span style="color:#D4D4D4"> </span><span style="color:#DCDCAA">greet</span><span style="color:#FFD705">(</span><span style="color:#8CDCFE">name</span><span style="color:#FFD705">)</span><span style="color:#D4D4D4"> </span><span style="color:#FFD705">{</span><br><span style="color:#D4D4D4"> </span><span style="color:#DCDCAA">print</span><span style="color:#D45DBA">(</span><span style="color:#CE9178">"Hello, "</span><span style="color:#D4D4D4"> + </span><span style="color:#8CDCFE">name</span><span style="color:#D4D4D4">.</span><span style="color:#DCDCAA">title</span><span style="color:#1A9FFF">()</span><span style="color:#D4D4D4"> + </span><span style="color:#CE9178">"!"</span><span style="color:#D45DBA">)</span><br><span style="color:#FFD705">}</span><br><br><span style="color:#DCDCAA">greet</span><span style="color:#FFD705">(</span><span style="color:#CE9178">"charlie klik"</span><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). 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.6.0a1 → pyscript_programming_language-1.7.0}/pyscript/__init__.py
RENAMED
|
@@ -8,10 +8,10 @@ if __import__('sys').version_info < (3, 10):
|
|
|
8
8
|
|
|
9
9
|
from . import core
|
|
10
10
|
|
|
11
|
-
from .core.constants import DEFAULT, DEBUG, SILENT, RETRES,
|
|
11
|
+
from .core.constants import DEFAULT, DEBUG, SILENT, RETRES, HIGHLIGHT, NO_COLOR, REVERSE_POW_XOR
|
|
12
12
|
from .core.cache import undefined
|
|
13
|
-
from .core.highlight import HLFMT_HTML, HLFMT_ANSI, HLFMT_BBCODE, pys_highlight
|
|
14
|
-
from .core.runner import pys_exec, pys_eval, pys_shell
|
|
13
|
+
from .core.highlight import HLFMT_HTML, HLFMT_ANSI, HLFMT_BBCODE, pys_highlight, PygmentsPyScriptLexer
|
|
14
|
+
from .core.runner import pys_exec, pys_eval, pys_require, pys_shell
|
|
15
15
|
from .core.version import version_info, __version__, __date__
|
|
16
16
|
|
|
17
17
|
__all__ = (
|
|
@@ -20,7 +20,7 @@ __all__ = (
|
|
|
20
20
|
'DEBUG',
|
|
21
21
|
'SILENT',
|
|
22
22
|
'RETRES',
|
|
23
|
-
'
|
|
23
|
+
'HIGHLIGHT',
|
|
24
24
|
'NO_COLOR',
|
|
25
25
|
'REVERSE_POW_XOR',
|
|
26
26
|
'HLFMT_HTML',
|
|
@@ -31,5 +31,7 @@ __all__ = (
|
|
|
31
31
|
'pys_highlight',
|
|
32
32
|
'pys_exec',
|
|
33
33
|
'pys_eval',
|
|
34
|
-
'
|
|
34
|
+
'pys_require',
|
|
35
|
+
'pys_shell',
|
|
36
|
+
'PygmentsPyScriptLexer'
|
|
35
37
|
)
|
{pyscript_programming_language-1.6.0a1 → pyscript_programming_language-1.7.0}/pyscript/__init__.pyi
RENAMED
|
@@ -1,15 +1,18 @@
|
|
|
1
|
+
from .core.highlight import PygmentsPyScriptLexer as PygmentsPyScriptLexer
|
|
2
|
+
|
|
1
3
|
from typing import TYPE_CHECKING, Any, Callable, Iterator, Literal, Optional
|
|
2
4
|
|
|
3
5
|
if TYPE_CHECKING:
|
|
4
6
|
from .core.buffer import PysFileBuffer
|
|
5
7
|
from .core.cache import PysUndefined
|
|
6
|
-
from .core.highlight import
|
|
8
|
+
from .core.highlight import _PysHighlightFormatter
|
|
7
9
|
from .core.position import PysPosition
|
|
8
10
|
from .core.results import PysExecuteResult
|
|
9
11
|
from .core.symtab import PysSymbolTable
|
|
10
12
|
from .core.version import PysVersionInfo
|
|
11
13
|
|
|
12
14
|
from io import IOBase
|
|
15
|
+
from types import ModuleType
|
|
13
16
|
|
|
14
17
|
from . import core as core
|
|
15
18
|
|
|
@@ -17,13 +20,13 @@ DEFAULT: int
|
|
|
17
20
|
DEBUG: int
|
|
18
21
|
SILENT: int
|
|
19
22
|
RETRES: int
|
|
20
|
-
|
|
23
|
+
HIGHLIGHT: int
|
|
21
24
|
NO_COLOR: int
|
|
22
25
|
REVERSE_POW_XOR: int
|
|
23
26
|
|
|
24
|
-
HLFMT_HTML:
|
|
25
|
-
HLFMT_ANSI:
|
|
26
|
-
HLFMT_BBCODE:
|
|
27
|
+
HLFMT_HTML: _PysHighlightFormatter
|
|
28
|
+
HLFMT_ANSI: _PysHighlightFormatter
|
|
29
|
+
HLFMT_BBCODE: _PysHighlightFormatter
|
|
27
30
|
|
|
28
31
|
undefined: PysUndefined
|
|
29
32
|
version_info: PysVersionInfo
|
|
@@ -35,9 +38,9 @@ def pys_highlight(
|
|
|
35
38
|
[
|
|
36
39
|
str | Literal[
|
|
37
40
|
'start',
|
|
38
|
-
'
|
|
39
|
-
'identifier', 'identifier-
|
|
40
|
-
'keyword', 'keyword-
|
|
41
|
+
'invalid',
|
|
42
|
+
'identifier', 'identifier-constant', 'identifier-function', 'identifier-type',
|
|
43
|
+
'keyword', 'keyword-constant',
|
|
41
44
|
'number', 'string', 'comment', 'newline',
|
|
42
45
|
'default',
|
|
43
46
|
'end'
|
|
@@ -48,8 +51,7 @@ def pys_highlight(
|
|
|
48
51
|
str
|
|
49
52
|
]
|
|
50
53
|
] = None,
|
|
51
|
-
|
|
52
|
-
flags: int = DEFAULT
|
|
54
|
+
max_bracket_level: int = 3
|
|
53
55
|
) -> str: ...
|
|
54
56
|
|
|
55
57
|
def pys_exec(
|
|
@@ -64,6 +66,11 @@ def pys_eval(
|
|
|
64
66
|
flags: int = DEFAULT
|
|
65
67
|
) -> Any | PysExecuteResult: ...
|
|
66
68
|
|
|
69
|
+
def pys_require(
|
|
70
|
+
name: str | bytes,
|
|
71
|
+
flags: int = DEFAULT
|
|
72
|
+
) -> ModuleType | Any: ...
|
|
73
|
+
|
|
67
74
|
def pys_shell(
|
|
68
75
|
globals: Optional[dict[str, Any] | PysSymbolTable | PysUndefined] = None,
|
|
69
76
|
flags: int = DEFAULT
|
{pyscript_programming_language-1.6.0a1 → pyscript_programming_language-1.7.0}/pyscript/__main__.py
RENAMED
|
@@ -1,21 +1,26 @@
|
|
|
1
1
|
from .core.buffer import PysFileBuffer
|
|
2
2
|
from .core.cache import path, undefined
|
|
3
3
|
from .core.constants import DEFAULT, DEBUG, NO_COLOR
|
|
4
|
-
from .core.handlers import handle_execute
|
|
5
4
|
from .core.highlight import HLFMT_HTML, HLFMT_ANSI, HLFMT_BBCODE, pys_highlight
|
|
6
5
|
from .core.runner import pys_runner, pys_shell
|
|
7
|
-
from .core.symtab import
|
|
8
|
-
from .core.utils.
|
|
6
|
+
from .core.symtab import new_symbol_table
|
|
7
|
+
from .core.utils.module import get_module_name_from_path
|
|
8
|
+
from .core.utils.path import normpath
|
|
9
9
|
from .core.version import __version__
|
|
10
10
|
|
|
11
11
|
from argparse import ArgumentParser
|
|
12
|
-
|
|
12
|
+
from os import environ
|
|
13
13
|
from sys import executable, stderr, version_info, exit, setrecursionlimit
|
|
14
|
-
|
|
14
|
+
|
|
15
|
+
FORMAT_HIGHLIGHT_MAP = {
|
|
16
|
+
'html': HLFMT_HTML,
|
|
17
|
+
'ansi': HLFMT_ANSI,
|
|
18
|
+
'bbcode': HLFMT_BBCODE
|
|
19
|
+
}
|
|
15
20
|
|
|
16
21
|
parser = ArgumentParser(
|
|
17
|
-
prog=
|
|
18
|
-
description='PyScript Launcher for Python Version
|
|
22
|
+
prog=f'{get_module_name_from_path(executable)} -m pyscript',
|
|
23
|
+
description=f'PyScript Launcher for Python Version {".".join(map(str, version_info))}'
|
|
19
24
|
)
|
|
20
25
|
|
|
21
26
|
parser.add_argument(
|
|
@@ -53,7 +58,7 @@ parser.add_argument(
|
|
|
53
58
|
|
|
54
59
|
parser.add_argument(
|
|
55
60
|
'-l', '--highlight',
|
|
56
|
-
choices=(
|
|
61
|
+
choices=tuple(FORMAT_HIGHLIGHT_MAP.keys()),
|
|
57
62
|
default=None,
|
|
58
63
|
help='generate PyScript highlight code from a file'
|
|
59
64
|
)
|
|
@@ -91,89 +96,59 @@ flags = DEFAULT
|
|
|
91
96
|
|
|
92
97
|
if args.debug:
|
|
93
98
|
flags |= DEBUG
|
|
94
|
-
if args.no_color:
|
|
99
|
+
if args.no_color or environ.get('NO_COLOR') is not None:
|
|
95
100
|
flags |= NO_COLOR
|
|
96
101
|
|
|
97
|
-
set_python_path(getcwd())
|
|
98
|
-
|
|
99
102
|
if args.file is not None:
|
|
100
103
|
path = normpath(args.file)
|
|
101
104
|
|
|
102
105
|
try:
|
|
103
106
|
with open(path, 'r', encoding='utf-8') as file:
|
|
104
107
|
file = PysFileBuffer(file, path)
|
|
105
|
-
|
|
106
108
|
except FileNotFoundError:
|
|
107
109
|
parser.error(f"can't open file {path!r}: No such file or directory")
|
|
108
|
-
|
|
109
110
|
except PermissionError:
|
|
110
111
|
parser.error(f"can't open file {path!r}: Permission denied.")
|
|
111
|
-
|
|
112
112
|
except IsADirectoryError:
|
|
113
113
|
parser.error(f"can't open file {path!r}: Path is not a file.")
|
|
114
|
-
|
|
115
114
|
except NotADirectoryError:
|
|
116
115
|
parser.error(f"can't open file {path!r}: Attempting to access directory from file.")
|
|
117
|
-
|
|
118
116
|
except (OSError, IOError):
|
|
119
117
|
parser.error(f"can't open file {path!r}: Attempting to access a system directory or file.")
|
|
120
|
-
|
|
121
118
|
except UnicodeDecodeError:
|
|
122
119
|
parser.error(f"can't read file {path!r}: Bad file.")
|
|
123
|
-
|
|
124
120
|
except BaseException as e:
|
|
125
121
|
parser.error(f"file {path!r}: Unexpected error: {e}")
|
|
126
122
|
|
|
127
123
|
if args.highlight:
|
|
128
|
-
format_map = {
|
|
129
|
-
'html': HLFMT_HTML,
|
|
130
|
-
'ansi': HLFMT_ANSI,
|
|
131
|
-
'bbcode': HLFMT_BBCODE
|
|
132
|
-
}
|
|
133
|
-
|
|
134
124
|
try:
|
|
135
|
-
print(pys_highlight(file,
|
|
125
|
+
print(pys_highlight(file, FORMAT_HIGHLIGHT_MAP.get(args.highlight, None)))
|
|
136
126
|
except BaseException as e:
|
|
137
|
-
parser.error(f"file {path!r}:
|
|
127
|
+
parser.error(f"file {path!r}: Highlight error: {e}")
|
|
138
128
|
|
|
139
129
|
else:
|
|
140
|
-
symtab = build_symbol_table(file)
|
|
141
|
-
symtab.set('__name__', '__main__')
|
|
142
|
-
|
|
143
130
|
result = pys_runner(
|
|
144
131
|
file=file,
|
|
145
132
|
mode='exec',
|
|
146
|
-
symbol_table=
|
|
133
|
+
symbol_table=new_symbol_table(file=file.name, name='__main__')[0],
|
|
147
134
|
flags=flags
|
|
148
135
|
)
|
|
149
136
|
|
|
150
|
-
code = handle_execute(result)
|
|
151
|
-
|
|
152
137
|
if args.inspect:
|
|
153
|
-
code = pys_shell(
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
)
|
|
138
|
+
code = pys_shell(result.context.symbol_table, result.context.flags)
|
|
139
|
+
else:
|
|
140
|
+
code = result.process()[0]
|
|
157
141
|
|
|
158
142
|
elif args.command is not None:
|
|
159
143
|
file = PysFileBuffer(args.command)
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
file=file,
|
|
167
|
-
mode='exec',
|
|
168
|
-
symbol_table=symtab,
|
|
169
|
-
flags=flags
|
|
170
|
-
)
|
|
171
|
-
)
|
|
144
|
+
code = pys_runner(
|
|
145
|
+
file=file,
|
|
146
|
+
mode='exec',
|
|
147
|
+
symbol_table=new_symbol_table(file=file.name, name='__main__')[0],
|
|
148
|
+
flags=flags
|
|
149
|
+
).process()[0]
|
|
172
150
|
|
|
173
151
|
else:
|
|
174
|
-
code = pys_shell(
|
|
175
|
-
globals=undefined,
|
|
176
|
-
flags=flags
|
|
177
|
-
)
|
|
152
|
+
code = pys_shell(undefined, flags)
|
|
178
153
|
|
|
179
154
|
exit(code)
|
|
@@ -40,7 +40,6 @@ __all__ = (
|
|
|
40
40
|
'exceptions',
|
|
41
41
|
'handlers',
|
|
42
42
|
'highlight',
|
|
43
|
-
'immutables',
|
|
44
43
|
'interpreter',
|
|
45
44
|
'lexer',
|
|
46
45
|
'mapping',
|
|
@@ -51,7 +50,6 @@ __all__ = (
|
|
|
51
50
|
'pysbuiltins',
|
|
52
51
|
'results',
|
|
53
52
|
'runner',
|
|
54
|
-
'singletons',
|
|
55
53
|
'symtab',
|
|
56
54
|
'token',
|
|
57
55
|
'utils',
|
|
@@ -2,7 +2,7 @@ from .bases import Pys
|
|
|
2
2
|
from .checks import is_assign, is_incremental
|
|
3
3
|
from .constants import TOKENS, DEFAULT
|
|
4
4
|
from .context import PysContext
|
|
5
|
-
from .exceptions import
|
|
5
|
+
from .exceptions import PysTraceback
|
|
6
6
|
from .nodes import PysNode, PysKeywordNode, PysIdentifierNode, PysAttributeNode, PysSubscriptNode
|
|
7
7
|
from .position import PysPosition
|
|
8
8
|
from .utils.decorators import typechecked
|
|
@@ -27,7 +27,7 @@ class PysAnalyzer(Pys):
|
|
|
27
27
|
|
|
28
28
|
def throw(self, message, position):
|
|
29
29
|
if self.error is None:
|
|
30
|
-
self.error =
|
|
30
|
+
self.error = PysTraceback(
|
|
31
31
|
SyntaxError(message),
|
|
32
32
|
PysContext(
|
|
33
33
|
file=self.node.position.file,
|
|
@@ -39,17 +39,18 @@ class PysAnalyzer(Pys):
|
|
|
39
39
|
)
|
|
40
40
|
|
|
41
41
|
@typechecked
|
|
42
|
-
def analyze(self) ->
|
|
42
|
+
def analyze(self) -> PysTraceback | None:
|
|
43
43
|
self.in_loop = 0
|
|
44
44
|
self.in_function = 0
|
|
45
45
|
self.in_switch = 0
|
|
46
46
|
self.error = None
|
|
47
|
+
self.parameters = set()
|
|
47
48
|
|
|
48
49
|
self.visit(self.node)
|
|
49
50
|
return self.error
|
|
50
51
|
|
|
51
52
|
def visit(self, node):
|
|
52
|
-
func = getattr(self,
|
|
53
|
+
func = getattr(self, 'visit_' + type(node).__name__.removeprefix('Pys'), None)
|
|
53
54
|
if not self.error and func:
|
|
54
55
|
func(node)
|
|
55
56
|
|
|
@@ -97,7 +98,7 @@ class PysAnalyzer(Pys):
|
|
|
97
98
|
if self.error:
|
|
98
99
|
return
|
|
99
100
|
|
|
100
|
-
|
|
101
|
+
keyword_names = set()
|
|
101
102
|
|
|
102
103
|
for element in node.arguments:
|
|
103
104
|
|
|
@@ -105,11 +106,11 @@ class PysAnalyzer(Pys):
|
|
|
105
106
|
token, value = element
|
|
106
107
|
name = token.value
|
|
107
108
|
|
|
108
|
-
if name in
|
|
109
|
+
if name in keyword_names:
|
|
109
110
|
self.throw(f"duplicate argument {name!r} in call definition", token.position)
|
|
110
111
|
return
|
|
111
112
|
|
|
112
|
-
|
|
113
|
+
keyword_names.add(name)
|
|
113
114
|
|
|
114
115
|
else:
|
|
115
116
|
value = element
|
|
@@ -246,9 +247,10 @@ class PysAnalyzer(Pys):
|
|
|
246
247
|
self.visit(node.finally_body)
|
|
247
248
|
|
|
248
249
|
def visit_WithNode(self, node):
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
250
|
+
for context, _ in node.contexts:
|
|
251
|
+
self.visit(context)
|
|
252
|
+
if self.error:
|
|
253
|
+
return
|
|
252
254
|
|
|
253
255
|
self.visit(node.body)
|
|
254
256
|
|
|
@@ -273,14 +275,13 @@ class PysAnalyzer(Pys):
|
|
|
273
275
|
else:
|
|
274
276
|
raise ValueError(f"unknown header struct {node.header}")
|
|
275
277
|
|
|
276
|
-
|
|
277
|
-
self.in_loop += 1
|
|
278
|
+
self.in_loop += 1
|
|
278
279
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
280
|
+
self.visit(node.body)
|
|
281
|
+
if self.error:
|
|
282
|
+
return
|
|
282
283
|
|
|
283
|
-
|
|
284
|
+
self.in_loop -= 1
|
|
284
285
|
|
|
285
286
|
if node.else_body:
|
|
286
287
|
self.visit(node.else_body)
|
|
@@ -290,27 +291,25 @@ class PysAnalyzer(Pys):
|
|
|
290
291
|
if self.error:
|
|
291
292
|
return
|
|
292
293
|
|
|
293
|
-
|
|
294
|
-
self.in_loop += 1
|
|
294
|
+
self.in_loop += 1
|
|
295
295
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
296
|
+
self.visit(node.body)
|
|
297
|
+
if self.error:
|
|
298
|
+
return
|
|
299
299
|
|
|
300
|
-
|
|
300
|
+
self.in_loop -= 1
|
|
301
301
|
|
|
302
302
|
if node.else_body:
|
|
303
303
|
self.visit(node.else_body)
|
|
304
304
|
|
|
305
305
|
def visit_DoWhileNode(self, node):
|
|
306
|
-
|
|
307
|
-
self.in_loop += 1
|
|
306
|
+
self.in_loop += 1
|
|
308
307
|
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
308
|
+
self.visit(node.body)
|
|
309
|
+
if self.error:
|
|
310
|
+
return
|
|
312
311
|
|
|
313
|
-
|
|
312
|
+
self.in_loop -= 1
|
|
314
313
|
|
|
315
314
|
self.visit(node.condition)
|
|
316
315
|
if self.error:
|
|
@@ -366,18 +365,20 @@ class PysAnalyzer(Pys):
|
|
|
366
365
|
if self.error:
|
|
367
366
|
return
|
|
368
367
|
|
|
369
|
-
in_loop, in_switch = self.in_loop, self.in_switch
|
|
368
|
+
in_loop, in_switch, parameters = self.in_loop, self.in_switch, self.parameters
|
|
370
369
|
|
|
371
370
|
self.in_loop = 0
|
|
372
371
|
self.in_switch = 0
|
|
373
372
|
|
|
374
373
|
self.in_function += 1
|
|
374
|
+
self.parameters = parameter_names
|
|
375
375
|
|
|
376
376
|
self.visit(node.body)
|
|
377
377
|
if self.error:
|
|
378
378
|
return
|
|
379
379
|
|
|
380
380
|
self.in_function -= 1
|
|
381
|
+
self.parameters = parameters
|
|
381
382
|
|
|
382
383
|
self.in_loop = in_loop
|
|
383
384
|
self.in_switch = in_switch
|
|
@@ -386,6 +387,11 @@ class PysAnalyzer(Pys):
|
|
|
386
387
|
if self.in_function == 0:
|
|
387
388
|
self.throw("global outside of function", node.position)
|
|
388
389
|
|
|
390
|
+
for identifier in node.identifiers:
|
|
391
|
+
if identifier.value in self.parameters:
|
|
392
|
+
self.throw("name {!r} is parameter and global".format(identifier.value), identifier.position)
|
|
393
|
+
return
|
|
394
|
+
|
|
389
395
|
def visit_ReturnNode(self, node):
|
|
390
396
|
if self.in_function == 0:
|
|
391
397
|
self.throw("return outside of function", node.position)
|
|
@@ -399,8 +405,8 @@ class PysAnalyzer(Pys):
|
|
|
399
405
|
if self.error:
|
|
400
406
|
return
|
|
401
407
|
|
|
402
|
-
if node.
|
|
403
|
-
self.visit(node.
|
|
408
|
+
if node.cause:
|
|
409
|
+
self.visit(node.cause)
|
|
404
410
|
|
|
405
411
|
def visit_AssertNode(self, node):
|
|
406
412
|
self.visit(node.condition)
|
|
@@ -448,7 +454,7 @@ class PysAnalyzer(Pys):
|
|
|
448
454
|
if self.in_loop == 0 and self.in_switch == 0:
|
|
449
455
|
self.throw("break outside of loop or switch case", node.position)
|
|
450
456
|
|
|
451
|
-
def visit_slice_SubscriptNode(self, nslice
|
|
457
|
+
def visit_slice_SubscriptNode(self, nslice):
|
|
452
458
|
type = nslice.__class__
|
|
453
459
|
|
|
454
460
|
if type is slice:
|
|
@@ -476,7 +482,7 @@ class PysAnalyzer(Pys):
|
|
|
476
482
|
else:
|
|
477
483
|
self.visit(nslice)
|
|
478
484
|
|
|
479
|
-
def visit_declaration_AssignNode(self, node
|
|
485
|
+
def visit_declaration_AssignNode(self, node, message):
|
|
480
486
|
type = node.__class__
|
|
481
487
|
|
|
482
488
|
if type is PysAttributeNode:
|
{pyscript_programming_language-1.6.0a1 → pyscript_programming_language-1.7.0}/pyscript/core/cache.py
RENAMED
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
from .bases import Pys
|
|
2
2
|
from .constants import LIBRARIES_PATH, SITE_PACKAGES_PATH
|
|
3
|
-
from .utils.debug import print_traceback
|
|
4
|
-
from .utils.decorators import
|
|
3
|
+
from .utils.debug import print_display, print_traceback
|
|
4
|
+
from .utils.decorators import inheritable, singleton
|
|
5
5
|
|
|
6
6
|
from threading import RLock
|
|
7
|
-
from re import compile as re_compile
|
|
8
7
|
|
|
9
8
|
loading_modules = set()
|
|
10
9
|
lock = RLock()
|
|
11
10
|
modules = dict()
|
|
12
11
|
path = [SITE_PACKAGES_PATH, LIBRARIES_PATH]
|
|
13
12
|
singletons = dict()
|
|
14
|
-
version_match = re_compile(r'^(\d+)\.(\d+)\.(\d+)((?:a|b|rc)(\d+)|\.(dev|post)(\d+))?$').match
|
|
15
13
|
|
|
16
14
|
@singleton
|
|
17
|
-
@
|
|
15
|
+
@inheritable
|
|
18
16
|
class PysUndefined(Pys):
|
|
19
17
|
|
|
20
18
|
__slots__ = ()
|
|
@@ -31,7 +29,7 @@ class PysUndefined(Pys):
|
|
|
31
29
|
return False
|
|
32
30
|
|
|
33
31
|
@singleton
|
|
34
|
-
@
|
|
32
|
+
@inheritable
|
|
35
33
|
class PysHook(Pys):
|
|
36
34
|
|
|
37
35
|
__slots__ = ()
|
|
@@ -39,7 +37,9 @@ class PysHook(Pys):
|
|
|
39
37
|
def __new_singleton__(cls):
|
|
40
38
|
global hook
|
|
41
39
|
hook = super(cls, cls).__new__(cls)
|
|
42
|
-
hook.
|
|
40
|
+
hook.running_shell = False
|
|
41
|
+
hook.running_breakpoint = False
|
|
42
|
+
hook.display = print_display
|
|
43
43
|
hook.exception = print_traceback
|
|
44
44
|
hook.ps1 = '>>> '
|
|
45
45
|
hook.ps2 = '... '
|
|
@@ -48,6 +48,22 @@ class PysHook(Pys):
|
|
|
48
48
|
def __repr__(self):
|
|
49
49
|
return f'<hook object at {id(self):016X}>'
|
|
50
50
|
|
|
51
|
+
@property
|
|
52
|
+
def running_shell(self):
|
|
53
|
+
return singletons['hook.running_shell']
|
|
54
|
+
|
|
55
|
+
@running_shell.setter
|
|
56
|
+
def running_shell(self, value):
|
|
57
|
+
singletons['hook.running_shell'] = bool(value)
|
|
58
|
+
|
|
59
|
+
@property
|
|
60
|
+
def running_breakpoint(self):
|
|
61
|
+
return singletons['hook.running_breakpoint']
|
|
62
|
+
|
|
63
|
+
@running_breakpoint.setter
|
|
64
|
+
def running_breakpoint(self, value):
|
|
65
|
+
singletons['hook.running_breakpoint'] = bool(value)
|
|
66
|
+
|
|
51
67
|
@property
|
|
52
68
|
def display(self):
|
|
53
69
|
return singletons['hook.display']
|