pyscript-programming-language 1.6.0a1__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/MANIFEST.in +3 -0
- pyscript_programming_language-1.6.0a1/PKG-INFO +65 -0
- pyscript_programming_language-1.6.0a1/README.md +31 -0
- pyscript_programming_language-1.6.0a1/pyscript/__init__.py +35 -0
- pyscript_programming_language-1.6.0a1/pyscript/__init__.pyi +74 -0
- pyscript_programming_language-1.6.0a1/pyscript/__main__.py +179 -0
- pyscript_programming_language-1.6.0a1/pyscript/core/__init__.py +59 -0
- pyscript_programming_language-1.6.0a1/pyscript/core/analyzer.py +506 -0
- pyscript_programming_language-1.6.0a1/pyscript/core/bases.py +2 -0
- pyscript_programming_language-1.6.0a1/pyscript/core/buffer.py +33 -0
- pyscript_programming_language-1.6.0a1/pyscript/core/cache.py +92 -0
- pyscript_programming_language-1.6.0a1/pyscript/core/checks.py +46 -0
- pyscript_programming_language-1.6.0a1/pyscript/core/constants.py +145 -0
- pyscript_programming_language-1.6.0a1/pyscript/core/context.py +54 -0
- pyscript_programming_language-1.6.0a1/pyscript/core/exceptions.py +113 -0
- pyscript_programming_language-1.6.0a1/pyscript/core/handlers.py +111 -0
- pyscript_programming_language-1.6.0a1/pyscript/core/highlight.py +218 -0
- pyscript_programming_language-1.6.0a1/pyscript/core/interpreter.py +1381 -0
- pyscript_programming_language-1.6.0a1/pyscript/core/lexer.py +827 -0
- pyscript_programming_language-1.6.0a1/pyscript/core/mapping.py +128 -0
- pyscript_programming_language-1.6.0a1/pyscript/core/nodes.py +583 -0
- pyscript_programming_language-1.6.0a1/pyscript/core/objects.py +235 -0
- pyscript_programming_language-1.6.0a1/pyscript/core/parser.py +2265 -0
- pyscript_programming_language-1.6.0a1/pyscript/core/position.py +99 -0
- pyscript_programming_language-1.6.0a1/pyscript/core/pysbuiltins.py +354 -0
- pyscript_programming_language-1.6.0a1/pyscript/core/results.py +119 -0
- pyscript_programming_language-1.6.0a1/pyscript/core/runner.py +368 -0
- pyscript_programming_language-1.6.0a1/pyscript/core/symtab.py +104 -0
- pyscript_programming_language-1.6.0a1/pyscript/core/token.py +39 -0
- pyscript_programming_language-1.6.0a1/pyscript/core/utils/__init__.py +11 -0
- pyscript_programming_language-1.6.0a1/pyscript/core/utils/debug.py +29 -0
- pyscript_programming_language-1.6.0a1/pyscript/core/utils/decorators.py +44 -0
- pyscript_programming_language-1.6.0a1/pyscript/core/utils/generic.py +152 -0
- pyscript_programming_language-1.6.0a1/pyscript/core/version.py +92 -0
- pyscript_programming_language-1.6.0a1/pyscript/lib/__hello__.pys +7 -0
- pyscript_programming_language-1.6.0a1/pyscript/lib/ast/__init__.pys +28 -0
- pyscript_programming_language-1.6.0a1/pyscript/lib/ast/pysast.py +670 -0
- pyscript_programming_language-1.6.0a1/pyscript/lib/brainfuck.pys +200 -0
- pyscript_programming_language-1.6.0a1/pyscript/lib/dis.pys +11 -0
- pyscript_programming_language-1.6.0a1/pyscript/lib/explorer.pys +224 -0
- pyscript_programming_language-1.6.0a1/pyscript/lib/fpstimer.pys +70 -0
- pyscript_programming_language-1.6.0a1/pyscript/lib/getch.pys +28 -0
- pyscript_programming_language-1.6.0a1/pyscript/lib/inspect.pys +34 -0
- pyscript_programming_language-1.6.0a1/pyscript/lib/jsdict.pys +28 -0
- pyscript_programming_language-1.6.0a1/pyscript/lib/keyword.pys +2 -0
- pyscript_programming_language-1.6.0a1/pyscript/lib/parser.pys +168 -0
- pyscript_programming_language-1.6.0a1/pyscript/lib/site.pys +34 -0
- pyscript_programming_language-1.6.0a1/pyscript/lib/symtable.pys +1 -0
- pyscript_programming_language-1.6.0a1/pyscript/lib/sys.pys +24 -0
- pyscript_programming_language-1.6.0a1/pyscript/lib/this.pys +19 -0
- pyscript_programming_language-1.6.0a1/pyscript/lib/token.pys +1 -0
- pyscript_programming_language-1.6.0a1/pyscript/lib/tokenize.pys +4 -0
- pyscript_programming_language-1.6.0a1/pyscript/site-packages/67.pys +1 -0
- pyscript_programming_language-1.6.0a1/pyscript/this.py +8 -0
- pyscript_programming_language-1.6.0a1/pyscript_programming_language.egg-info/PKG-INFO +65 -0
- pyscript_programming_language-1.6.0a1/pyscript_programming_language.egg-info/SOURCES.txt +59 -0
- pyscript_programming_language-1.6.0a1/pyscript_programming_language.egg-info/dependency_links.txt +1 -0
- pyscript_programming_language-1.6.0a1/pyscript_programming_language.egg-info/requires.txt +3 -0
- pyscript_programming_language-1.6.0a1/pyscript_programming_language.egg-info/top_level.txt +1 -0
- pyscript_programming_language-1.6.0a1/setup.cfg +4 -0
- pyscript_programming_language-1.6.0a1/setup.py +35 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pyscript-programming-language
|
|
3
|
+
Version: 1.6.0a1
|
|
4
|
+
Summary: PyScript Programming Language
|
|
5
|
+
Home-page: https://github.com/azzammuhyala/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,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: typecheck
|
|
21
|
+
Requires-Dist: beartype; extra == "typecheck"
|
|
22
|
+
Dynamic: author
|
|
23
|
+
Dynamic: author-email
|
|
24
|
+
Dynamic: classifier
|
|
25
|
+
Dynamic: description
|
|
26
|
+
Dynamic: description-content-type
|
|
27
|
+
Dynamic: home-page
|
|
28
|
+
Dynamic: keywords
|
|
29
|
+
Dynamic: license
|
|
30
|
+
Dynamic: project-url
|
|
31
|
+
Dynamic: provides-extra
|
|
32
|
+
Dynamic: requires-python
|
|
33
|
+
Dynamic: summary
|
|
34
|
+
|
|
35
|
+
# PyScript
|
|
36
|
+
|
|
37
|
+
<p align="center">
|
|
38
|
+
<img src="https://github.com/azzammuhyala/pyscript/blob/main/PyScript.png?raw=true" alt="PyScript Logo" width="200">
|
|
39
|
+
</p>
|
|
40
|
+
|
|
41
|
+
PyScript is a simple programming language built on top of Python. It combines some syntax from Python and JavaScript,
|
|
42
|
+
so if you're already familiar with Python or JavaScript, or both, it should be quite easy to learn.
|
|
43
|
+
|
|
44
|
+
## Introduction PyScript
|
|
45
|
+
PyScript may not be the language we'll be discussing, but the name PyScript already exists, a flexible and platform for
|
|
46
|
+
running Python in a browser. Since it's inception, the language was inspired by Python and JavaScript, which are
|
|
47
|
+
relatively easy for humans to read. This name was chosen because it wasn't immediately known whether this name was
|
|
48
|
+
already in use.
|
|
49
|
+
|
|
50
|
+
This language wasn't designed to compete with other modern programming languages, but rather as a learning for
|
|
51
|
+
understanding how programming languages work and how human written code can be understood by machines. Furthermore, this
|
|
52
|
+
language was created as a relatively complex project. Using Python as the foundation for PyScript, it's easy to
|
|
53
|
+
understand syntax makes it easy to understand how the language is built without having to understand complex
|
|
54
|
+
instructions like those in C, C++, and other low-level languages.
|
|
55
|
+
|
|
56
|
+
To learn more about PyScript, you can see on [PyScript documentation here](https://azzammuhyala.github.io/pyscript) or
|
|
57
|
+
[PyScript repository](https://github.com/azzammuhyala/pyscript).
|
|
58
|
+
|
|
59
|
+
## Syntax
|
|
60
|
+
<pre class="pyscript-code"><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:#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">"Azzam"</span><span style="color:#FFD705">)</span></pre>
|
|
61
|
+
|
|
62
|
+
## Behind it
|
|
63
|
+
This language created from based up on a
|
|
64
|
+
[YouTube tutorial](https://www.youtube.com/playlist?list=PLZQftyCk7_SdoVexSmwy_tBgs7P0b97yD). At least, it takes
|
|
65
|
+
about 6 months to learn it, and also need to learn general things that exist in other programming languages.
|
|
@@ -0,0 +1,31 @@
|
|
|
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 here](https://azzammuhyala.github.io/pyscript) or
|
|
23
|
+
[PyScript repository](https://github.com/azzammuhyala/pyscript).
|
|
24
|
+
|
|
25
|
+
## Syntax
|
|
26
|
+
<pre class="pyscript-code"><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:#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">"Azzam"</span><span style="color:#FFD705">)</span></pre>
|
|
27
|
+
|
|
28
|
+
## Behind it
|
|
29
|
+
This language created from based up on a
|
|
30
|
+
[YouTube tutorial](https://www.youtube.com/playlist?list=PLZQftyCk7_SdoVexSmwy_tBgs7P0b97yD). At least, it takes
|
|
31
|
+
about 6 months to learn it, and also need to learn general things that exist in other programming languages.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"""
|
|
2
|
+
PyScript is a programming language written in Python. \
|
|
3
|
+
This language is not isolated and is directly integrated with the Python's library and namespace levels.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
if __import__('sys').version_info < (3, 10):
|
|
7
|
+
raise ImportError("Python version 3.10 and above is required to run PyScript")
|
|
8
|
+
|
|
9
|
+
from . import core
|
|
10
|
+
|
|
11
|
+
from .core.constants import DEFAULT, DEBUG, SILENT, RETRES, COMMENT, NO_COLOR, REVERSE_POW_XOR
|
|
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
|
|
15
|
+
from .core.version import version_info, __version__, __date__
|
|
16
|
+
|
|
17
|
+
__all__ = (
|
|
18
|
+
'core',
|
|
19
|
+
'DEFAULT',
|
|
20
|
+
'DEBUG',
|
|
21
|
+
'SILENT',
|
|
22
|
+
'RETRES',
|
|
23
|
+
'COMMENT',
|
|
24
|
+
'NO_COLOR',
|
|
25
|
+
'REVERSE_POW_XOR',
|
|
26
|
+
'HLFMT_HTML',
|
|
27
|
+
'HLFMT_ANSI',
|
|
28
|
+
'HLFMT_BBCODE',
|
|
29
|
+
'undefined',
|
|
30
|
+
'version_info',
|
|
31
|
+
'pys_highlight',
|
|
32
|
+
'pys_exec',
|
|
33
|
+
'pys_eval',
|
|
34
|
+
'pys_shell'
|
|
35
|
+
)
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
from typing import TYPE_CHECKING, Any, Callable, Iterator, Literal, Optional
|
|
2
|
+
|
|
3
|
+
if TYPE_CHECKING:
|
|
4
|
+
from .core.buffer import PysFileBuffer
|
|
5
|
+
from .core.cache import PysUndefined
|
|
6
|
+
from .core.highlight import _HighlightFormatter
|
|
7
|
+
from .core.position import PysPosition
|
|
8
|
+
from .core.results import PysExecuteResult
|
|
9
|
+
from .core.symtab import PysSymbolTable
|
|
10
|
+
from .core.version import PysVersionInfo
|
|
11
|
+
|
|
12
|
+
from io import IOBase
|
|
13
|
+
|
|
14
|
+
from . import core as core
|
|
15
|
+
|
|
16
|
+
DEFAULT: int
|
|
17
|
+
DEBUG: int
|
|
18
|
+
SILENT: int
|
|
19
|
+
RETRES: int
|
|
20
|
+
COMMENT: int
|
|
21
|
+
NO_COLOR: int
|
|
22
|
+
REVERSE_POW_XOR: int
|
|
23
|
+
|
|
24
|
+
HLFMT_HTML: _HighlightFormatter
|
|
25
|
+
HLFMT_ANSI: _HighlightFormatter
|
|
26
|
+
HLFMT_BBCODE: _HighlightFormatter
|
|
27
|
+
|
|
28
|
+
undefined: PysUndefined
|
|
29
|
+
version_info: PysVersionInfo
|
|
30
|
+
|
|
31
|
+
def pys_highlight(
|
|
32
|
+
source: str | bytes | bytearray | Iterator | Callable | IOBase | PysFileBuffer,
|
|
33
|
+
format: Optional[
|
|
34
|
+
Callable[
|
|
35
|
+
[
|
|
36
|
+
str | Literal[
|
|
37
|
+
'start',
|
|
38
|
+
'bracket-unmatch',
|
|
39
|
+
'identifier', 'identifier-const', 'identifier-call', 'identifier-class',
|
|
40
|
+
'keyword', 'keyword-identifier',
|
|
41
|
+
'number', 'string', 'comment', 'newline',
|
|
42
|
+
'default',
|
|
43
|
+
'end'
|
|
44
|
+
],
|
|
45
|
+
PysPosition,
|
|
46
|
+
str
|
|
47
|
+
],
|
|
48
|
+
str
|
|
49
|
+
]
|
|
50
|
+
] = None,
|
|
51
|
+
max_parenthesis_level: int = 3,
|
|
52
|
+
flags: int = DEFAULT
|
|
53
|
+
) -> str: ...
|
|
54
|
+
|
|
55
|
+
def pys_exec(
|
|
56
|
+
source: str | bytes | bytearray | Iterator | Callable | IOBase | PysFileBuffer,
|
|
57
|
+
globals: Optional[dict[str, Any] | PysSymbolTable | PysUndefined] = None,
|
|
58
|
+
flags: int = DEFAULT
|
|
59
|
+
) -> None | PysExecuteResult: ...
|
|
60
|
+
|
|
61
|
+
def pys_eval(
|
|
62
|
+
source: str | bytes | bytearray | Iterator | Callable | IOBase | PysFileBuffer,
|
|
63
|
+
globals: Optional[dict[str, Any] | PysSymbolTable | PysUndefined] = None,
|
|
64
|
+
flags: int = DEFAULT
|
|
65
|
+
) -> Any | PysExecuteResult: ...
|
|
66
|
+
|
|
67
|
+
def pys_shell(
|
|
68
|
+
globals: Optional[dict[str, Any] | PysSymbolTable | PysUndefined] = None,
|
|
69
|
+
flags: int = DEFAULT
|
|
70
|
+
) -> int | Any: ...
|
|
71
|
+
|
|
72
|
+
__version__: str
|
|
73
|
+
__date__: str
|
|
74
|
+
__all__: tuple[str]
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
from .core.buffer import PysFileBuffer
|
|
2
|
+
from .core.cache import path, undefined
|
|
3
|
+
from .core.constants import DEFAULT, DEBUG, NO_COLOR
|
|
4
|
+
from .core.handlers import handle_execute
|
|
5
|
+
from .core.highlight import HLFMT_HTML, HLFMT_ANSI, HLFMT_BBCODE, pys_highlight
|
|
6
|
+
from .core.runner import pys_runner, pys_shell
|
|
7
|
+
from .core.symtab import build_symbol_table
|
|
8
|
+
from .core.utils.generic import normpath, get_package_name, set_python_path
|
|
9
|
+
from .core.version import __version__
|
|
10
|
+
|
|
11
|
+
from argparse import ArgumentParser
|
|
12
|
+
|
|
13
|
+
from sys import executable, stderr, version_info, exit, setrecursionlimit
|
|
14
|
+
from os import getcwd
|
|
15
|
+
|
|
16
|
+
parser = ArgumentParser(
|
|
17
|
+
prog=get_package_name(executable) + ' -m pyscript',
|
|
18
|
+
description='PyScript Launcher for Python Version ' + '.'.join(map(str, version_info))
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
parser.add_argument(
|
|
22
|
+
'file',
|
|
23
|
+
type=str,
|
|
24
|
+
nargs='?',
|
|
25
|
+
default=None,
|
|
26
|
+
help="file path"
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
parser.add_argument(
|
|
30
|
+
'-v', '--version',
|
|
31
|
+
action='version',
|
|
32
|
+
version=f"PyScript {__version__}",
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
parser.add_argument(
|
|
36
|
+
'-c', '--command',
|
|
37
|
+
type=str,
|
|
38
|
+
default=None,
|
|
39
|
+
help="execute PyScript from argument",
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
parser.add_argument(
|
|
43
|
+
'-d', '--debug',
|
|
44
|
+
action='store_true',
|
|
45
|
+
help="set a debug flag, this will remove the assert statement"
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
parser.add_argument(
|
|
49
|
+
'-i', '--inspect',
|
|
50
|
+
action='store_true',
|
|
51
|
+
help="inspect interactively after running a file",
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
parser.add_argument(
|
|
55
|
+
'-l', '--highlight',
|
|
56
|
+
choices=('html', 'ansi', 'bbcode'),
|
|
57
|
+
default=None,
|
|
58
|
+
help='generate PyScript highlight code from a file'
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
parser.add_argument(
|
|
62
|
+
'-n', '--no-color',
|
|
63
|
+
action='store_true',
|
|
64
|
+
help="no colorful traceback"
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
parser.add_argument(
|
|
68
|
+
'-r', '--py-recursion',
|
|
69
|
+
type=int,
|
|
70
|
+
default=None,
|
|
71
|
+
help="set a python recursion limit"
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
def argument_error(argument, message):
|
|
75
|
+
parser.print_usage(stderr)
|
|
76
|
+
parser.exit(2, f"{parser.prog}: error: argument {argument}: {message}\n")
|
|
77
|
+
|
|
78
|
+
args = parser.parse_args()
|
|
79
|
+
|
|
80
|
+
if args.highlight and args.file is None:
|
|
81
|
+
argument_error("-l/--highlight", "file path require")
|
|
82
|
+
|
|
83
|
+
if args.py_recursion is not None:
|
|
84
|
+
try:
|
|
85
|
+
setrecursionlimit(args.py_recursion)
|
|
86
|
+
except BaseException as e:
|
|
87
|
+
argument_error("-r/--py-recursion", e)
|
|
88
|
+
|
|
89
|
+
code = 0
|
|
90
|
+
flags = DEFAULT
|
|
91
|
+
|
|
92
|
+
if args.debug:
|
|
93
|
+
flags |= DEBUG
|
|
94
|
+
if args.no_color:
|
|
95
|
+
flags |= NO_COLOR
|
|
96
|
+
|
|
97
|
+
set_python_path(getcwd())
|
|
98
|
+
|
|
99
|
+
if args.file is not None:
|
|
100
|
+
path = normpath(args.file)
|
|
101
|
+
|
|
102
|
+
try:
|
|
103
|
+
with open(path, 'r', encoding='utf-8') as file:
|
|
104
|
+
file = PysFileBuffer(file, path)
|
|
105
|
+
|
|
106
|
+
except FileNotFoundError:
|
|
107
|
+
parser.error(f"can't open file {path!r}: No such file or directory")
|
|
108
|
+
|
|
109
|
+
except PermissionError:
|
|
110
|
+
parser.error(f"can't open file {path!r}: Permission denied.")
|
|
111
|
+
|
|
112
|
+
except IsADirectoryError:
|
|
113
|
+
parser.error(f"can't open file {path!r}: Path is not a file.")
|
|
114
|
+
|
|
115
|
+
except NotADirectoryError:
|
|
116
|
+
parser.error(f"can't open file {path!r}: Attempting to access directory from file.")
|
|
117
|
+
|
|
118
|
+
except (OSError, IOError):
|
|
119
|
+
parser.error(f"can't open file {path!r}: Attempting to access a system directory or file.")
|
|
120
|
+
|
|
121
|
+
except UnicodeDecodeError:
|
|
122
|
+
parser.error(f"can't read file {path!r}: Bad file.")
|
|
123
|
+
|
|
124
|
+
except BaseException as e:
|
|
125
|
+
parser.error(f"file {path!r}: Unexpected error: {e}")
|
|
126
|
+
|
|
127
|
+
if args.highlight:
|
|
128
|
+
format_map = {
|
|
129
|
+
'html': HLFMT_HTML,
|
|
130
|
+
'ansi': HLFMT_ANSI,
|
|
131
|
+
'bbcode': HLFMT_BBCODE
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
try:
|
|
135
|
+
print(pys_highlight(file, format_map[args.highlight]))
|
|
136
|
+
except BaseException as e:
|
|
137
|
+
parser.error(f"file {path!r}: Tokenize error: {e}")
|
|
138
|
+
|
|
139
|
+
else:
|
|
140
|
+
symtab = build_symbol_table(file)
|
|
141
|
+
symtab.set('__name__', '__main__')
|
|
142
|
+
|
|
143
|
+
result = pys_runner(
|
|
144
|
+
file=file,
|
|
145
|
+
mode='exec',
|
|
146
|
+
symbol_table=symtab,
|
|
147
|
+
flags=flags
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
code = handle_execute(result)
|
|
151
|
+
|
|
152
|
+
if args.inspect:
|
|
153
|
+
code = pys_shell(
|
|
154
|
+
globals=result.context.symbol_table,
|
|
155
|
+
flags=result.context.flags
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
elif args.command is not None:
|
|
159
|
+
file = PysFileBuffer(args.command)
|
|
160
|
+
|
|
161
|
+
symtab = build_symbol_table(file)
|
|
162
|
+
symtab.set('__name__', '__main__')
|
|
163
|
+
|
|
164
|
+
code = handle_execute(
|
|
165
|
+
pys_runner(
|
|
166
|
+
file=file,
|
|
167
|
+
mode='exec',
|
|
168
|
+
symbol_table=symtab,
|
|
169
|
+
flags=flags
|
|
170
|
+
)
|
|
171
|
+
)
|
|
172
|
+
|
|
173
|
+
else:
|
|
174
|
+
code = pys_shell(
|
|
175
|
+
globals=undefined,
|
|
176
|
+
flags=flags
|
|
177
|
+
)
|
|
178
|
+
|
|
179
|
+
exit(code)
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"""
|
|
2
|
+
PyScript implementations.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from . import (
|
|
6
|
+
analyzer,
|
|
7
|
+
bases,
|
|
8
|
+
buffer,
|
|
9
|
+
cache,
|
|
10
|
+
checks,
|
|
11
|
+
constants,
|
|
12
|
+
context,
|
|
13
|
+
exceptions,
|
|
14
|
+
handlers,
|
|
15
|
+
highlight,
|
|
16
|
+
interpreter,
|
|
17
|
+
lexer,
|
|
18
|
+
mapping,
|
|
19
|
+
nodes,
|
|
20
|
+
objects,
|
|
21
|
+
parser,
|
|
22
|
+
position,
|
|
23
|
+
pysbuiltins,
|
|
24
|
+
results,
|
|
25
|
+
runner,
|
|
26
|
+
symtab,
|
|
27
|
+
token,
|
|
28
|
+
utils,
|
|
29
|
+
version
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
__all__ = (
|
|
33
|
+
'analyzer',
|
|
34
|
+
'bases',
|
|
35
|
+
'buffer',
|
|
36
|
+
'cache',
|
|
37
|
+
'checks',
|
|
38
|
+
'constants',
|
|
39
|
+
'context',
|
|
40
|
+
'exceptions',
|
|
41
|
+
'handlers',
|
|
42
|
+
'highlight',
|
|
43
|
+
'immutables',
|
|
44
|
+
'interpreter',
|
|
45
|
+
'lexer',
|
|
46
|
+
'mapping',
|
|
47
|
+
'nodes',
|
|
48
|
+
'objects',
|
|
49
|
+
'parser',
|
|
50
|
+
'position',
|
|
51
|
+
'pysbuiltins',
|
|
52
|
+
'results',
|
|
53
|
+
'runner',
|
|
54
|
+
'singletons',
|
|
55
|
+
'symtab',
|
|
56
|
+
'token',
|
|
57
|
+
'utils',
|
|
58
|
+
'version'
|
|
59
|
+
)
|