pyscript-programming-language 1.2.2__tar.gz → 1.3.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.
Potentially problematic release.
This version of pyscript-programming-language might be problematic. Click here for more details.
- pyscript_programming_language-1.3.0/MANIFEST.in +3 -0
- pyscript_programming_language-1.3.0/PKG-INFO +55 -0
- pyscript_programming_language-1.3.0/README.md +24 -0
- pyscript_programming_language-1.3.0/pyscript/__init__.py +33 -0
- {pyscript_programming_language-1.2.2 → pyscript_programming_language-1.3.0}/pyscript/__init__.pyi +8 -5
- {pyscript_programming_language-1.2.2 → pyscript_programming_language-1.3.0}/pyscript/__main__.py +34 -30
- {pyscript_programming_language-1.2.2 → pyscript_programming_language-1.3.0}/pyscript/core/__init__.py +4 -4
- pyscript_programming_language-1.2.2/pyscript/core/validator.py → pyscript_programming_language-1.3.0/pyscript/core/analyzer.py +31 -12
- pyscript_programming_language-1.3.0/pyscript/core/bases.py +4 -0
- {pyscript_programming_language-1.2.2 → pyscript_programming_language-1.3.0}/pyscript/core/buffer.py +2 -7
- pyscript_programming_language-1.3.0/pyscript/core/cache.py +15 -0
- {pyscript_programming_language-1.2.2 → pyscript_programming_language-1.3.0}/pyscript/core/constants.py +18 -8
- pyscript_programming_language-1.3.0/pyscript/core/context.py +19 -0
- pyscript_programming_language-1.3.0/pyscript/core/exceptions.py +81 -0
- pyscript_programming_language-1.3.0/pyscript/core/handlers.py +62 -0
- {pyscript_programming_language-1.2.2 → pyscript_programming_language-1.3.0}/pyscript/core/highlight.py +51 -46
- pyscript_programming_language-1.3.0/pyscript/core/interpreter.py +1192 -0
- {pyscript_programming_language-1.2.2 → pyscript_programming_language-1.3.0}/pyscript/core/lexer.py +218 -193
- {pyscript_programming_language-1.2.2 → pyscript_programming_language-1.3.0}/pyscript/core/nodes.py +16 -6
- pyscript_programming_language-1.3.0/pyscript/core/objects.py +234 -0
- {pyscript_programming_language-1.2.2 → pyscript_programming_language-1.3.0}/pyscript/core/parser.py +199 -117
- pyscript_programming_language-1.3.0/pyscript/core/position.py +92 -0
- {pyscript_programming_language-1.2.2 → pyscript_programming_language-1.3.0}/pyscript/core/pysbuiltins.py +91 -107
- {pyscript_programming_language-1.2.2 → pyscript_programming_language-1.3.0}/pyscript/core/results.py +32 -18
- {pyscript_programming_language-1.2.2 → pyscript_programming_language-1.3.0}/pyscript/core/runner.py +77 -70
- pyscript_programming_language-1.3.0/pyscript/core/singletons.py +119 -0
- pyscript_programming_language-1.3.0/pyscript/core/symtab.py +92 -0
- pyscript_programming_language-1.3.0/pyscript/core/utils.py +168 -0
- pyscript_programming_language-1.3.0/pyscript/core/version.py +5 -0
- pyscript_programming_language-1.3.0/pyscript/lib/__hello__.pys +5 -0
- {pyscript_programming_language-1.2.2 → pyscript_programming_language-1.3.0}/pyscript/lib/brainfuck.pys +55 -62
- {pyscript_programming_language-1.2.2 → pyscript_programming_language-1.3.0}/pyscript/lib/clock.pys +3 -3
- {pyscript_programming_language-1.2.2 → pyscript_programming_language-1.3.0}/pyscript/lib/getch.pys +2 -1
- pyscript_programming_language-1.3.0/pyscript/lib/jsdict.pys +62 -0
- pyscript_programming_language-1.3.0/pyscript/lib/parser.pys +93 -0
- {pyscript_programming_language-1.2.2 → pyscript_programming_language-1.3.0}/pyscript/lib/sys.pys +5 -3
- pyscript_programming_language-1.3.0/pyscript_programming_language.egg-info/PKG-INFO +55 -0
- {pyscript_programming_language-1.2.2 → pyscript_programming_language-1.3.0}/pyscript_programming_language.egg-info/SOURCES.txt +2 -3
- {pyscript_programming_language-1.2.2 → pyscript_programming_language-1.3.0}/setup.py +1 -1
- pyscript_programming_language-1.2.2/MANIFEST.in +0 -6
- pyscript_programming_language-1.2.2/PKG-INFO +0 -354
- pyscript_programming_language-1.2.2/PyScript.png +0 -0
- pyscript_programming_language-1.2.2/README.md +0 -323
- pyscript_programming_language-1.2.2/changelog.md +0 -12
- pyscript_programming_language-1.2.2/pyscript/__init__.py +0 -26
- pyscript_programming_language-1.2.2/pyscript/core/bases.py +0 -2
- pyscript_programming_language-1.2.2/pyscript/core/cache.py +0 -9
- pyscript_programming_language-1.2.2/pyscript/core/context.py +0 -13
- pyscript_programming_language-1.2.2/pyscript/core/exceptions.py +0 -34
- pyscript_programming_language-1.2.2/pyscript/core/handlers.py +0 -60
- pyscript_programming_language-1.2.2/pyscript/core/interpreter.py +0 -995
- pyscript_programming_language-1.2.2/pyscript/core/objects.py +0 -199
- pyscript_programming_language-1.2.2/pyscript/core/position.py +0 -11
- pyscript_programming_language-1.2.2/pyscript/core/singletons.py +0 -65
- pyscript_programming_language-1.2.2/pyscript/core/symtab.py +0 -76
- pyscript_programming_language-1.2.2/pyscript/core/utils.py +0 -300
- pyscript_programming_language-1.2.2/pyscript/core/version.py +0 -9
- pyscript_programming_language-1.2.2/pyscript/lib/__hello__.pys +0 -5
- pyscript_programming_language-1.2.2/pyscript/lib/parser.pys +0 -81
- pyscript_programming_language-1.2.2/pyscript_programming_language.egg-info/PKG-INFO +0 -354
- {pyscript_programming_language-1.2.2 → pyscript_programming_language-1.3.0}/pyscript/core/token.py +0 -0
- {pyscript_programming_language-1.2.2 → pyscript_programming_language-1.3.0}/pyscript/lib/this.pys +0 -0
- {pyscript_programming_language-1.2.2 → pyscript_programming_language-1.3.0}/pyscript/this.py +0 -0
- {pyscript_programming_language-1.2.2 → pyscript_programming_language-1.3.0}/pyscript_programming_language.egg-info/dependency_links.txt +0 -0
- {pyscript_programming_language-1.2.2 → pyscript_programming_language-1.3.0}/pyscript_programming_language.egg-info/top_level.txt +0 -0
- {pyscript_programming_language-1.2.2 → pyscript_programming_language-1.3.0}/setup.cfg +0 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pyscript-programming-language
|
|
3
|
+
Version: 1.3.0
|
|
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.5
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
Dynamic: author
|
|
21
|
+
Dynamic: author-email
|
|
22
|
+
Dynamic: classifier
|
|
23
|
+
Dynamic: description
|
|
24
|
+
Dynamic: description-content-type
|
|
25
|
+
Dynamic: home-page
|
|
26
|
+
Dynamic: keywords
|
|
27
|
+
Dynamic: license
|
|
28
|
+
Dynamic: project-url
|
|
29
|
+
Dynamic: requires-python
|
|
30
|
+
Dynamic: summary
|
|
31
|
+
|
|
32
|
+
# PyScript
|
|
33
|
+
|
|
34
|
+
<p align="center">
|
|
35
|
+
<img src="https://github.com/azzammuhyala/pyscript/blob/main/PyScript.png?raw=true" alt="PyScript Logo" width="200">
|
|
36
|
+
</p>
|
|
37
|
+
|
|
38
|
+
PyScript is a simple programming language built on top of Python. It combines some syntax from Python and JavaScript,
|
|
39
|
+
so if you're already familiar with Python or JavaScript, or both, it should be quite easy to learn.
|
|
40
|
+
|
|
41
|
+
## Introduction PyScript
|
|
42
|
+
PyScript may not be the language we'll be discussing, but the name PyScript already exists, a flexible and platform for
|
|
43
|
+
running Python in a browser. Since it's inception, the language was inspired by Python and JavaScript, which are
|
|
44
|
+
relatively easy for humans to read. This name was chosen because it wasn't immediately known whether this name was
|
|
45
|
+
already in use.
|
|
46
|
+
|
|
47
|
+
This language wasn't designed to compete with other modern programming languages, but rather as a learning for
|
|
48
|
+
understanding how programming languages work and how human written code can be understood by machines. Furthermore, this
|
|
49
|
+
language was created as a relatively complex project. Using Python as the foundation for PyScript, it's easy to
|
|
50
|
+
understand syntax makes it easy to understand how the language is built without having to understand complex
|
|
51
|
+
instructions like those in C, C++, and other low-level languages.
|
|
52
|
+
|
|
53
|
+
To learn more about PyScript's syntax and packages, you can check out the
|
|
54
|
+
[PyScript documentation here](https://azzammuhyala.github.io/pyscript) or see on
|
|
55
|
+
[PyScript repository](https://github.com/azzammuhyala/pyscript).
|
|
@@ -0,0 +1,24 @@
|
|
|
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's syntax and packages, you can check out the
|
|
23
|
+
[PyScript documentation here](https://azzammuhyala.github.io/pyscript) or see on
|
|
24
|
+
[PyScript repository](https://github.com/azzammuhyala/pyscript).
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
import sys
|
|
7
|
+
|
|
8
|
+
if sys.version_info < (3, 5):
|
|
9
|
+
raise ImportError("Python version 3.5 and above is required to run PyScript")
|
|
10
|
+
|
|
11
|
+
from . import core
|
|
12
|
+
|
|
13
|
+
from .core.constants import DEFAULT, OPTIMIZE, SILENT, RETRES, COMMENT, REVERSE_POW_XOR
|
|
14
|
+
from .core.highlight import HLFMT_HTML, HLFMT_ANSI, pys_highlight
|
|
15
|
+
from .core.runner import pys_exec, pys_eval
|
|
16
|
+
from .core.version import __version__, __date__
|
|
17
|
+
|
|
18
|
+
__all__ = (
|
|
19
|
+
'core',
|
|
20
|
+
'DEFAULT',
|
|
21
|
+
'OPTIMIZE',
|
|
22
|
+
'SILENT',
|
|
23
|
+
'RETRES',
|
|
24
|
+
'COMMENT',
|
|
25
|
+
'REVERSE_POW_XOR',
|
|
26
|
+
'HLFMT_HTML',
|
|
27
|
+
'HLFMT_ANSI',
|
|
28
|
+
'pys_highlight',
|
|
29
|
+
'pys_exec',
|
|
30
|
+
'pys_eval'
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
del sys
|
{pyscript_programming_language-1.2.2 → pyscript_programming_language-1.3.0}/pyscript/__init__.pyi
RENAMED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
from typing import TYPE_CHECKING, Any, Callable, Dict,
|
|
1
|
+
from typing import TYPE_CHECKING, Any, Callable, Dict, Literal, Union, Optional, Tuple
|
|
2
2
|
|
|
3
3
|
if TYPE_CHECKING:
|
|
4
4
|
from .core.buffer import PysFileBuffer
|
|
5
5
|
from .core.highlight import _HighlightFormatter
|
|
6
6
|
from .core.position import PysPosition
|
|
7
|
+
from .core.results import PysExecuteResult
|
|
7
8
|
from .core.symtab import PysSymbolTable
|
|
8
9
|
|
|
9
10
|
from io import IOBase
|
|
@@ -14,6 +15,8 @@ DEFAULT: int
|
|
|
14
15
|
OPTIMIZE: int
|
|
15
16
|
SILENT: int
|
|
16
17
|
RETRES: int
|
|
18
|
+
COMMENT: int
|
|
19
|
+
REVERSE_POW_XOR: int
|
|
17
20
|
|
|
18
21
|
HLFMT_HTML: _HighlightFormatter
|
|
19
22
|
HLFMT_ANSI: _HighlightFormatter
|
|
@@ -31,21 +34,21 @@ def pys_highlight(
|
|
|
31
34
|
'end'
|
|
32
35
|
], PysPosition, str], str]] = None,
|
|
33
36
|
max_parenthesis_level: int = 3,
|
|
34
|
-
flags: int =
|
|
37
|
+
flags: int = COMMENT
|
|
35
38
|
) -> str: ...
|
|
36
39
|
|
|
37
40
|
def pys_exec(
|
|
38
41
|
source: Union[str, bytes, bytearray, IOBase, PysFileBuffer],
|
|
39
42
|
globals: Optional[Union[Dict[str, Any], PysSymbolTable]] = None,
|
|
40
43
|
flags: int = DEFAULT
|
|
41
|
-
) -> None: ...
|
|
44
|
+
) -> Union[None, PysExecuteResult]: ...
|
|
42
45
|
|
|
43
46
|
def pys_eval(
|
|
44
47
|
source: Union[str, bytes, bytearray, IOBase, PysFileBuffer],
|
|
45
48
|
globals: Optional[Union[Dict[str, Any], PysSymbolTable]] = None,
|
|
46
49
|
flags: int = DEFAULT
|
|
47
|
-
) -> Any: ...
|
|
50
|
+
) -> Union[Any, PysExecuteResult]: ...
|
|
48
51
|
|
|
49
52
|
__version__: str
|
|
50
53
|
__date__: str
|
|
51
|
-
__all__:
|
|
54
|
+
__all__: Tuple[str]
|
{pyscript_programming_language-1.2.2 → pyscript_programming_language-1.3.0}/pyscript/__main__.py
RENAMED
|
@@ -3,15 +3,17 @@ from .core.constants import DEFAULT, OPTIMIZE
|
|
|
3
3
|
from .core.handlers import handle_execute
|
|
4
4
|
from .core.highlight import HLFMT_HTML, HLFMT_ANSI, pys_highlight
|
|
5
5
|
from .core.runner import pys_runner, pys_shell
|
|
6
|
-
from .core.
|
|
6
|
+
from .core.symtab import build_symbol_table
|
|
7
|
+
from .core.utils import normalize_path
|
|
7
8
|
from .core.version import __version__
|
|
8
9
|
|
|
9
10
|
from argparse import ArgumentParser
|
|
10
11
|
|
|
11
12
|
import sys
|
|
13
|
+
import os
|
|
12
14
|
|
|
13
15
|
parser = ArgumentParser(
|
|
14
|
-
prog='pyscript',
|
|
16
|
+
prog='{} -m pyscript'.format(os.path.splitext(os.path.basename(sys.executable))[0]),
|
|
15
17
|
description="PyScript Launcher for Python Version {}".format('.'.join(map(str, sys.version_info)))
|
|
16
18
|
)
|
|
17
19
|
|
|
@@ -30,26 +32,26 @@ parser.add_argument(
|
|
|
30
32
|
)
|
|
31
33
|
|
|
32
34
|
parser.add_argument(
|
|
33
|
-
'-c', '--command',
|
|
35
|
+
'-c', '-C', '--command',
|
|
34
36
|
type=str,
|
|
35
37
|
default=None,
|
|
36
38
|
help="execute PyScript from argument",
|
|
37
39
|
)
|
|
38
40
|
|
|
39
41
|
parser.add_argument(
|
|
40
|
-
'-O', '--optimize',
|
|
42
|
+
'-o', '-O', '--optimize',
|
|
41
43
|
action='store_true',
|
|
42
44
|
help="set optimize flag"
|
|
43
45
|
)
|
|
44
46
|
|
|
45
47
|
parser.add_argument(
|
|
46
|
-
'-i', '--inspect',
|
|
48
|
+
'-i', '-I', '--inspect',
|
|
47
49
|
action='store_true',
|
|
48
50
|
help="inspect interactively after running a file",
|
|
49
51
|
)
|
|
50
52
|
|
|
51
53
|
parser.add_argument(
|
|
52
|
-
'-l', '--highlight',
|
|
54
|
+
'-l', '-L', '--highlight',
|
|
53
55
|
choices=('html', 'ansi'),
|
|
54
56
|
default=None,
|
|
55
57
|
help='generate PyScript highlight code from a file'
|
|
@@ -58,46 +60,47 @@ parser.add_argument(
|
|
|
58
60
|
args = parser.parse_args()
|
|
59
61
|
|
|
60
62
|
if args.highlight and args.file is None:
|
|
61
|
-
parser.error("file path require")
|
|
63
|
+
parser.error("-l, -L, --highlight: file path require")
|
|
62
64
|
|
|
65
|
+
code = 0
|
|
63
66
|
flags = DEFAULT
|
|
64
67
|
|
|
65
68
|
if args.optimize:
|
|
66
69
|
flags |= OPTIMIZE
|
|
67
70
|
|
|
68
71
|
if args.file is not None:
|
|
69
|
-
|
|
72
|
+
path = normalize_path(args.file)
|
|
70
73
|
|
|
71
74
|
try:
|
|
72
|
-
with open(
|
|
73
|
-
file = PysFileBuffer(file.read(),
|
|
75
|
+
with open(path, 'r') as file:
|
|
76
|
+
file = PysFileBuffer(file.read(), path)
|
|
74
77
|
|
|
75
78
|
except FileNotFoundError:
|
|
76
|
-
parser.error("can't open file {!r}: No such file or directory".format(
|
|
79
|
+
parser.error("can't open file {!r}: No such file or directory".format(path))
|
|
77
80
|
|
|
78
81
|
except PermissionError:
|
|
79
|
-
parser.error("can't open file {!r}: Permission denied.".format(
|
|
82
|
+
parser.error("can't open file {!r}: Permission denied.".format(path))
|
|
80
83
|
|
|
81
84
|
except IsADirectoryError:
|
|
82
|
-
parser.error("can't open file {!r}: Path is not a file.".format(
|
|
85
|
+
parser.error("can't open file {!r}: Path is not a file.".format(path))
|
|
83
86
|
|
|
84
87
|
except NotADirectoryError:
|
|
85
|
-
parser.error("can't open file {!r}: Attempting to access directory from file.".format(
|
|
88
|
+
parser.error("can't open file {!r}: Attempting to access directory from file.".format(path))
|
|
86
89
|
|
|
87
90
|
except (OSError, IOError):
|
|
88
|
-
parser.error("can't open file {!r}: Attempting to access a system directory or file.".format(
|
|
91
|
+
parser.error("can't open file {!r}: Attempting to access a system directory or file.".format(path))
|
|
89
92
|
|
|
90
93
|
except UnicodeDecodeError:
|
|
91
|
-
parser.error("can't read file {!r}: Bad file.".format(
|
|
94
|
+
parser.error("can't read file {!r}: Bad file.".format(path))
|
|
92
95
|
|
|
93
96
|
except BaseException as e:
|
|
94
|
-
parser.error("file {!r}: Unexpected error: {}".format(
|
|
97
|
+
parser.error("file {!r}: Unexpected error: {}".format(path, e))
|
|
95
98
|
|
|
96
99
|
if args.highlight:
|
|
97
100
|
try:
|
|
98
101
|
print(pys_highlight(file, HLFMT_HTML if args.highlight == 'html' else HLFMT_ANSI))
|
|
99
102
|
except BaseException as e:
|
|
100
|
-
parser.error("file {!r}: Tokenize error: {}".format(
|
|
103
|
+
parser.error("file {!r}: Tokenize error: {}".format(path, e))
|
|
101
104
|
|
|
102
105
|
else:
|
|
103
106
|
symtab = build_symbol_table(file)
|
|
@@ -113,9 +116,10 @@ if args.file is not None:
|
|
|
113
116
|
code = handle_execute(result)
|
|
114
117
|
|
|
115
118
|
if args.inspect:
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
+
code = pys_shell(
|
|
120
|
+
symbol_table=result.context.symbol_table,
|
|
121
|
+
flags=result.context.flags
|
|
122
|
+
)
|
|
119
123
|
|
|
120
124
|
elif args.command is not None:
|
|
121
125
|
file = PysFileBuffer(args.command)
|
|
@@ -123,16 +127,16 @@ elif args.command is not None:
|
|
|
123
127
|
symtab = build_symbol_table(file)
|
|
124
128
|
symtab.set('__name__', '__main__')
|
|
125
129
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
flags=flags
|
|
133
|
-
)
|
|
130
|
+
code = handle_execute(
|
|
131
|
+
pys_runner(
|
|
132
|
+
file=file,
|
|
133
|
+
mode='exec',
|
|
134
|
+
symbol_table=symtab,
|
|
135
|
+
flags=flags
|
|
134
136
|
)
|
|
135
137
|
)
|
|
136
138
|
|
|
137
139
|
else:
|
|
138
|
-
pys_shell(flags=flags)
|
|
140
|
+
code = pys_shell(flags=flags)
|
|
141
|
+
|
|
142
|
+
sys.exit(code)
|
|
@@ -3,6 +3,7 @@ PyScript implementations.
|
|
|
3
3
|
"""
|
|
4
4
|
|
|
5
5
|
from . import (
|
|
6
|
+
analyzer,
|
|
6
7
|
bases,
|
|
7
8
|
buffer,
|
|
8
9
|
cache,
|
|
@@ -24,11 +25,11 @@ from . import (
|
|
|
24
25
|
symtab,
|
|
25
26
|
token,
|
|
26
27
|
utils,
|
|
27
|
-
validator,
|
|
28
28
|
version
|
|
29
29
|
)
|
|
30
30
|
|
|
31
|
-
__all__ =
|
|
31
|
+
__all__ = (
|
|
32
|
+
'analyzer',
|
|
32
33
|
'bases',
|
|
33
34
|
'buffer',
|
|
34
35
|
'cache',
|
|
@@ -50,6 +51,5 @@ __all__ = [
|
|
|
50
51
|
'symtab',
|
|
51
52
|
'token',
|
|
52
53
|
'utils',
|
|
53
|
-
'validator',
|
|
54
54
|
'version'
|
|
55
|
-
|
|
55
|
+
)
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
from .bases import Pys
|
|
2
|
-
from .constants import TOKENS
|
|
2
|
+
from .constants import TOKENS, DEFAULT
|
|
3
3
|
from .context import PysContext
|
|
4
4
|
from .exceptions import PysException
|
|
5
|
-
from .nodes import PysSequenceNode, PysIdentifierNode, PysAttributeNode, PysSubscriptNode
|
|
5
|
+
from .nodes import PysSequenceNode, PysIdentifierNode, PysKeywordNode, PysAttributeNode, PysSubscriptNode
|
|
6
6
|
|
|
7
|
-
class
|
|
7
|
+
class PysAnalyzer(Pys):
|
|
8
8
|
|
|
9
|
-
def __init__(self, file, context_parent=None, context_parent_entry_position=None):
|
|
9
|
+
def __init__(self, file, flags=DEFAULT, context_parent=None, context_parent_entry_position=None):
|
|
10
10
|
self.file = file
|
|
11
|
+
self.flags = flags
|
|
11
12
|
self.context = context_parent
|
|
12
13
|
self.context_parent_entry_position = context_parent_entry_position
|
|
13
14
|
|
|
@@ -22,8 +23,8 @@ class PysValidator(Pys):
|
|
|
22
23
|
self.error = PysException(
|
|
23
24
|
SyntaxError(message),
|
|
24
25
|
PysContext(
|
|
25
|
-
name=None,
|
|
26
26
|
file=self.file,
|
|
27
|
+
flags=self.flags,
|
|
27
28
|
parent=self.context,
|
|
28
29
|
parent_entry_position=self.context_parent_entry_position
|
|
29
30
|
),
|
|
@@ -32,7 +33,6 @@ class PysValidator(Pys):
|
|
|
32
33
|
|
|
33
34
|
def visit(self, node):
|
|
34
35
|
func = getattr(self, 'visit_' + type(node).__name__[3:], None)
|
|
35
|
-
|
|
36
36
|
if not self.error and func:
|
|
37
37
|
func(node)
|
|
38
38
|
|
|
@@ -102,11 +102,14 @@ class PysValidator(Pys):
|
|
|
102
102
|
|
|
103
103
|
def visit_UnaryOperatorNode(self, node):
|
|
104
104
|
if node.operand.type in (TOKENS['INCREMENT'], TOKENS['DECREMENT']):
|
|
105
|
-
if
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
105
|
+
operator = 'increase' if node.operand.type == TOKENS['INCREMENT'] else 'decrease'
|
|
106
|
+
|
|
107
|
+
if isinstance(node.value, PysKeywordNode):
|
|
108
|
+
self.throw("cannot {} {}".format(operator, node.value.token.value), node.value.position)
|
|
109
|
+
return
|
|
110
|
+
|
|
111
|
+
elif not isinstance(node.value, (PysIdentifierNode, PysAttributeNode, PysSubscriptNode)):
|
|
112
|
+
self.throw("cannot {} literal".format(operator), node.value.position)
|
|
110
113
|
return
|
|
111
114
|
|
|
112
115
|
self.visit(node.value)
|
|
@@ -157,6 +160,11 @@ class PysValidator(Pys):
|
|
|
157
160
|
if self.error:
|
|
158
161
|
return
|
|
159
162
|
|
|
163
|
+
if node.else_body:
|
|
164
|
+
self.visit(node.else_body)
|
|
165
|
+
if self.error:
|
|
166
|
+
return
|
|
167
|
+
|
|
160
168
|
if node.finally_body:
|
|
161
169
|
self.visit(node.finally_body)
|
|
162
170
|
|
|
@@ -290,7 +298,7 @@ class PysValidator(Pys):
|
|
|
290
298
|
|
|
291
299
|
names = set()
|
|
292
300
|
|
|
293
|
-
for element in node.
|
|
301
|
+
for element in node.arguments:
|
|
294
302
|
value = element
|
|
295
303
|
|
|
296
304
|
if isinstance(element, tuple):
|
|
@@ -315,6 +323,10 @@ class PysValidator(Pys):
|
|
|
315
323
|
if node.value:
|
|
316
324
|
self.visit(node.value)
|
|
317
325
|
|
|
326
|
+
def visit_GlobalNode(self, node):
|
|
327
|
+
if self.in_function == 0:
|
|
328
|
+
self.throw("global outside of function", node.position)
|
|
329
|
+
|
|
318
330
|
def visit_DeleteNode(self, node):
|
|
319
331
|
for element in node.targets:
|
|
320
332
|
|
|
@@ -332,6 +344,10 @@ class PysValidator(Pys):
|
|
|
332
344
|
if self.error:
|
|
333
345
|
return
|
|
334
346
|
|
|
347
|
+
elif isinstance(element, PysKeywordNode):
|
|
348
|
+
self.throw("cannot delete {}".format(element.token.value), element.position)
|
|
349
|
+
return
|
|
350
|
+
|
|
335
351
|
elif not isinstance(element, PysIdentifierNode):
|
|
336
352
|
self.throw("cannot delete literal", element.position)
|
|
337
353
|
return
|
|
@@ -388,5 +404,8 @@ class PysValidator(Pys):
|
|
|
388
404
|
elif isinstance(node, PysAttributeNode):
|
|
389
405
|
self.visit(node.object)
|
|
390
406
|
|
|
407
|
+
elif isinstance(node, PysKeywordNode):
|
|
408
|
+
self.throw("cannot assign to {}".format(node.token.value), node.position)
|
|
409
|
+
|
|
391
410
|
elif not isinstance(node, PysIdentifierNode):
|
|
392
411
|
self.throw(message, node.position)
|
{pyscript_programming_language-1.2.2 → pyscript_programming_language-1.3.0}/pyscript/core/buffer.py
RENAMED
|
@@ -9,6 +9,7 @@ class PysBuffer(Pys):
|
|
|
9
9
|
class PysFileBuffer(PysBuffer):
|
|
10
10
|
|
|
11
11
|
def __init__(self, text, name=None):
|
|
12
|
+
|
|
12
13
|
if isinstance(text, PysFileBuffer):
|
|
13
14
|
self.text = to_str(text.text)
|
|
14
15
|
self.name = to_str(text.name if name is None else name)
|
|
@@ -22,10 +23,4 @@ class PysFileBuffer(PysBuffer):
|
|
|
22
23
|
self.name = '<string>' if name is None else to_str(name)
|
|
23
24
|
|
|
24
25
|
def __repr__(self):
|
|
25
|
-
return '<FileBuffer from {!r}>'.format(self.name)
|
|
26
|
-
|
|
27
|
-
class PysCode(PysBuffer):
|
|
28
|
-
|
|
29
|
-
def __init__(self, **kwargs):
|
|
30
|
-
for key, value in kwargs.items():
|
|
31
|
-
setattr(self, key, value)
|
|
26
|
+
return '<FileBuffer from {!r}>'.format(self.name)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from .constants import LIBRARY_PATH
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import sys
|
|
5
|
+
|
|
6
|
+
loading_modules = set()
|
|
7
|
+
|
|
8
|
+
try:
|
|
9
|
+
library = set(os.path.splitext(lib)[0] for lib in os.listdir(LIBRARY_PATH))
|
|
10
|
+
except BaseException as e:
|
|
11
|
+
library = set()
|
|
12
|
+
print("Error: can't access directory {!r}: {}".format(LIBRARY_PATH, e), file=sys.stderr)
|
|
13
|
+
|
|
14
|
+
modules = dict()
|
|
15
|
+
hook = None
|
|
@@ -5,7 +5,7 @@ PYSCRIPT_PATH = os.path.sep.join(__file__.split(os.path.sep)[:-2])
|
|
|
5
5
|
LIBRARY_PATH = os.path.join(PYSCRIPT_PATH, 'lib')
|
|
6
6
|
|
|
7
7
|
# tokens offset
|
|
8
|
-
DOUBLE = 0xFF
|
|
8
|
+
DOUBLE = 0xFF * 1
|
|
9
9
|
TRIPLE = 0xFF * 2
|
|
10
10
|
WITH_EQ = 0xFF * 3
|
|
11
11
|
SPECIAL = 0xFF * 4
|
|
@@ -17,6 +17,8 @@ TOKENS = {
|
|
|
17
17
|
'IDENTIFIER': 2,
|
|
18
18
|
'NUMBER': 3,
|
|
19
19
|
'STRING': 4,
|
|
20
|
+
'NOTIN': 5,
|
|
21
|
+
'ISNOT': 6,
|
|
20
22
|
'PLUS': ord('+'),
|
|
21
23
|
'MINUS': ord('-'),
|
|
22
24
|
'MUL': ord('*'),
|
|
@@ -33,6 +35,8 @@ TOKENS = {
|
|
|
33
35
|
'RSHIFT': ord('>') + DOUBLE,
|
|
34
36
|
'INCREMENT': ord('+') + DOUBLE,
|
|
35
37
|
'DECREMENT': ord('-') + DOUBLE,
|
|
38
|
+
'CAND': ord('&') + DOUBLE,
|
|
39
|
+
'COR': ord('|') + DOUBLE,
|
|
36
40
|
'LPAREN': ord('('),
|
|
37
41
|
'RPAREN': ord(')'),
|
|
38
42
|
'LSQUARE': ord('['),
|
|
@@ -69,9 +73,7 @@ TOKENS = {
|
|
|
69
73
|
'ELLIPSIS': ord('.') + TRIPLE,
|
|
70
74
|
'SEMICOLON': ord(';'),
|
|
71
75
|
'NEWLINE': ord('\n'),
|
|
72
|
-
'COMMENT': ord('#')
|
|
73
|
-
'NOTIN': 5,
|
|
74
|
-
'ISNOT': 6
|
|
76
|
+
'COMMENT': ord('#')
|
|
75
77
|
}
|
|
76
78
|
|
|
77
79
|
# keywords
|
|
@@ -79,6 +81,9 @@ KEYWORDS = {
|
|
|
79
81
|
'False': 'False',
|
|
80
82
|
'None': 'None',
|
|
81
83
|
'True': 'True',
|
|
84
|
+
'false': 'false',
|
|
85
|
+
'none': 'none',
|
|
86
|
+
'true': 'true',
|
|
82
87
|
'and': 'and',
|
|
83
88
|
'as': 'as',
|
|
84
89
|
'assert': 'assert',
|
|
@@ -96,6 +101,7 @@ KEYWORDS = {
|
|
|
96
101
|
'for': 'for',
|
|
97
102
|
'from': 'from',
|
|
98
103
|
'func': 'func',
|
|
104
|
+
'global': 'global',
|
|
99
105
|
'if': 'if',
|
|
100
106
|
'import': 'import',
|
|
101
107
|
'in': 'in',
|
|
@@ -128,9 +134,13 @@ HIGHLIGHT = {
|
|
|
128
134
|
'comment': '#549952'
|
|
129
135
|
}
|
|
130
136
|
|
|
137
|
+
# python extensions file
|
|
138
|
+
PYTHON_EXTENSIONS = {'.ipy', '.py', '.pyc', '.pyi', '.pyo', '.pyp', '.pyw', '.pyz', '.pyproj', '.rpy', '.xpy'}
|
|
139
|
+
|
|
131
140
|
# flags
|
|
132
141
|
DEFAULT = 0
|
|
133
|
-
OPTIMIZE = 1 <<
|
|
134
|
-
SILENT = 1 <<
|
|
135
|
-
RETRES = 1 <<
|
|
136
|
-
|
|
142
|
+
OPTIMIZE = 1 << 0
|
|
143
|
+
SILENT = 1 << 1
|
|
144
|
+
RETRES = 1 << 2
|
|
145
|
+
COMMENT = 1 << 3
|
|
146
|
+
REVERSE_POW_XOR = 1 << 10
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
from .bases import Pys
|
|
2
|
+
from .constants import DEFAULT
|
|
3
|
+
|
|
4
|
+
class PysContext(Pys):
|
|
5
|
+
|
|
6
|
+
def __init__(self, file, name=None, qualname=None, flags=None, symbol_table=None, parent=None, parent_entry_position=None):
|
|
7
|
+
if flags is None and parent:
|
|
8
|
+
flags = parent.flags
|
|
9
|
+
|
|
10
|
+
self.file = file
|
|
11
|
+
self.name = name
|
|
12
|
+
self.qualname = qualname
|
|
13
|
+
self.flags = DEFAULT if flags is None else flags
|
|
14
|
+
self.symbol_table = symbol_table
|
|
15
|
+
self.parent = parent
|
|
16
|
+
self.parent_entry_position = parent_entry_position
|
|
17
|
+
|
|
18
|
+
def __repr__(self):
|
|
19
|
+
return '<Context {!r}>'.format(self.name)
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
from .bases import Pys
|
|
2
|
+
from .utils import space_indent
|
|
3
|
+
|
|
4
|
+
class PysException(Pys):
|
|
5
|
+
|
|
6
|
+
def __init__(self, exception, context, position):
|
|
7
|
+
self.exception = exception
|
|
8
|
+
self.context = context
|
|
9
|
+
self.position = position
|
|
10
|
+
|
|
11
|
+
def __str__(self):
|
|
12
|
+
return str(self.exception)
|
|
13
|
+
|
|
14
|
+
def __repr__(self):
|
|
15
|
+
return '<Exception of {!r}>'.format(self.exception)
|
|
16
|
+
|
|
17
|
+
def string_traceback(self):
|
|
18
|
+
context = self.context
|
|
19
|
+
position = self.position
|
|
20
|
+
|
|
21
|
+
frames = []
|
|
22
|
+
|
|
23
|
+
while context:
|
|
24
|
+
is_positionless = position.is_positionless()
|
|
25
|
+
|
|
26
|
+
frames.append(
|
|
27
|
+
' File "{}"{}{}{}'.format(
|
|
28
|
+
position.file.name,
|
|
29
|
+
'' if is_positionless else ', line {}'.format(position.start_line),
|
|
30
|
+
'' if context.name is None else ', in {}'.format(context.name),
|
|
31
|
+
'' if is_positionless else '\n{}'.format(space_indent(position.format_arrow(), 4))
|
|
32
|
+
)
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
position = context.parent_entry_position
|
|
36
|
+
context = context.parent
|
|
37
|
+
|
|
38
|
+
found_duplicated_frame = 0
|
|
39
|
+
strings_traceback = ''
|
|
40
|
+
last_frame = ''
|
|
41
|
+
|
|
42
|
+
for frame in reversed(frames):
|
|
43
|
+
if frame == last_frame:
|
|
44
|
+
found_duplicated_frame += 1
|
|
45
|
+
|
|
46
|
+
else:
|
|
47
|
+
if found_duplicated_frame > 0:
|
|
48
|
+
strings_traceback += ' [Previous line repeated {} more times]\n'.format(found_duplicated_frame)
|
|
49
|
+
found_duplicated_frame = 0
|
|
50
|
+
|
|
51
|
+
strings_traceback += frame + '\n'
|
|
52
|
+
last_frame = frame
|
|
53
|
+
|
|
54
|
+
if found_duplicated_frame > 0:
|
|
55
|
+
strings_traceback += ' [Previous line repeated {} more times]\n'.format(found_duplicated_frame)
|
|
56
|
+
|
|
57
|
+
result = 'Traceback (most recent call last):\n' + strings_traceback
|
|
58
|
+
|
|
59
|
+
if isinstance(self.exception, type):
|
|
60
|
+
return result + self.exception.__name__
|
|
61
|
+
|
|
62
|
+
message = str(self.exception)
|
|
63
|
+
return result + type(self.exception).__name__ + (': ' + message if message else '')
|
|
64
|
+
|
|
65
|
+
class PysShouldReturn(Pys, BaseException):
|
|
66
|
+
|
|
67
|
+
def __init__(self, result):
|
|
68
|
+
super().__init__()
|
|
69
|
+
self.result = result
|
|
70
|
+
|
|
71
|
+
def __str__(self):
|
|
72
|
+
if self.result.error is None:
|
|
73
|
+
return '<signal>'
|
|
74
|
+
|
|
75
|
+
exception = self.result.error.exception
|
|
76
|
+
|
|
77
|
+
if isinstance(exception, type):
|
|
78
|
+
return exception.__name__
|
|
79
|
+
|
|
80
|
+
message = str(exception)
|
|
81
|
+
return type(exception).__name__ + (': ' + message if message else '')
|