pyscript-programming-language 1.2.3__tar.gz → 1.3.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.
Potentially problematic release.
This version of pyscript-programming-language might be problematic. Click here for more details.
- pyscript_programming_language-1.3.1/MANIFEST.in +3 -0
- pyscript_programming_language-1.3.1/PKG-INFO +59 -0
- pyscript_programming_language-1.3.1/README.md +28 -0
- {pyscript_programming_language-1.2.3 → pyscript_programming_language-1.3.1}/pyscript/__init__.py +2 -2
- {pyscript_programming_language-1.2.3 → pyscript_programming_language-1.3.1}/pyscript/__init__.pyi +3 -3
- {pyscript_programming_language-1.2.3 → pyscript_programming_language-1.3.1}/pyscript/__main__.py +21 -19
- {pyscript_programming_language-1.2.3 → pyscript_programming_language-1.3.1}/pyscript/core/__init__.py +4 -4
- pyscript_programming_language-1.2.3/pyscript/core/validator.py → pyscript_programming_language-1.3.1/pyscript/core/analyzer.py +30 -10
- pyscript_programming_language-1.3.1/pyscript/core/bases.py +4 -0
- {pyscript_programming_language-1.2.3 → pyscript_programming_language-1.3.1}/pyscript/core/buffer.py +1 -0
- pyscript_programming_language-1.3.1/pyscript/core/cache.py +15 -0
- {pyscript_programming_language-1.2.3 → pyscript_programming_language-1.3.1}/pyscript/core/constants.py +15 -9
- pyscript_programming_language-1.3.1/pyscript/core/context.py +19 -0
- {pyscript_programming_language-1.2.3 → pyscript_programming_language-1.3.1}/pyscript/core/exceptions.py +13 -11
- {pyscript_programming_language-1.2.3 → pyscript_programming_language-1.3.1}/pyscript/core/handlers.py +17 -16
- {pyscript_programming_language-1.2.3 → pyscript_programming_language-1.3.1}/pyscript/core/highlight.py +41 -38
- {pyscript_programming_language-1.2.3 → pyscript_programming_language-1.3.1}/pyscript/core/interpreter.py +457 -297
- {pyscript_programming_language-1.2.3 → pyscript_programming_language-1.3.1}/pyscript/core/lexer.py +87 -43
- {pyscript_programming_language-1.2.3 → pyscript_programming_language-1.3.1}/pyscript/core/nodes.py +13 -3
- pyscript_programming_language-1.3.1/pyscript/core/objects.py +234 -0
- {pyscript_programming_language-1.2.3 → pyscript_programming_language-1.3.1}/pyscript/core/parser.py +276 -231
- pyscript_programming_language-1.3.1/pyscript/core/position.py +92 -0
- {pyscript_programming_language-1.2.3 → pyscript_programming_language-1.3.1}/pyscript/core/pysbuiltins.py +58 -68
- {pyscript_programming_language-1.2.3 → pyscript_programming_language-1.3.1}/pyscript/core/results.py +21 -17
- {pyscript_programming_language-1.2.3 → pyscript_programming_language-1.3.1}/pyscript/core/runner.py +29 -27
- pyscript_programming_language-1.3.1/pyscript/core/singletons.py +119 -0
- {pyscript_programming_language-1.2.3 → pyscript_programming_language-1.3.1}/pyscript/core/symtab.py +38 -10
- {pyscript_programming_language-1.2.3 → pyscript_programming_language-1.3.1}/pyscript/core/utils.py +46 -74
- pyscript_programming_language-1.3.1/pyscript/core/version.py +5 -0
- pyscript_programming_language-1.3.1/pyscript/lib/__hello__.pys +5 -0
- {pyscript_programming_language-1.2.3 → pyscript_programming_language-1.3.1}/pyscript/lib/brainfuck.pys +55 -62
- {pyscript_programming_language-1.2.3 → pyscript_programming_language-1.3.1}/pyscript/lib/clock.pys +3 -3
- {pyscript_programming_language-1.2.3 → pyscript_programming_language-1.3.1}/pyscript/lib/getch.pys +2 -1
- pyscript_programming_language-1.3.1/pyscript/lib/jsdict.pys +62 -0
- {pyscript_programming_language-1.2.3 → pyscript_programming_language-1.3.1}/pyscript/lib/parser.pys +11 -8
- {pyscript_programming_language-1.2.3 → pyscript_programming_language-1.3.1}/pyscript/lib/sys.pys +4 -2
- pyscript_programming_language-1.3.1/pyscript_programming_language.egg-info/PKG-INFO +59 -0
- {pyscript_programming_language-1.2.3 → pyscript_programming_language-1.3.1}/pyscript_programming_language.egg-info/SOURCES.txt +2 -3
- {pyscript_programming_language-1.2.3 → pyscript_programming_language-1.3.1}/setup.py +1 -1
- pyscript_programming_language-1.2.3/MANIFEST.in +0 -6
- pyscript_programming_language-1.2.3/PKG-INFO +0 -354
- pyscript_programming_language-1.2.3/PyScript.png +0 -0
- pyscript_programming_language-1.2.3/README.md +0 -323
- pyscript_programming_language-1.2.3/changelog.md +0 -28
- pyscript_programming_language-1.2.3/pyscript/core/bases.py +0 -2
- pyscript_programming_language-1.2.3/pyscript/core/cache.py +0 -8
- pyscript_programming_language-1.2.3/pyscript/core/context.py +0 -14
- pyscript_programming_language-1.2.3/pyscript/core/objects.py +0 -200
- pyscript_programming_language-1.2.3/pyscript/core/position.py +0 -85
- pyscript_programming_language-1.2.3/pyscript/core/singletons.py +0 -63
- pyscript_programming_language-1.2.3/pyscript/core/version.py +0 -9
- pyscript_programming_language-1.2.3/pyscript/lib/__hello__.pys +0 -5
- pyscript_programming_language-1.2.3/pyscript_programming_language.egg-info/PKG-INFO +0 -354
- {pyscript_programming_language-1.2.3 → pyscript_programming_language-1.3.1}/pyscript/core/token.py +0 -0
- {pyscript_programming_language-1.2.3 → pyscript_programming_language-1.3.1}/pyscript/lib/this.pys +0 -0
- {pyscript_programming_language-1.2.3 → pyscript_programming_language-1.3.1}/pyscript/this.py +0 -0
- {pyscript_programming_language-1.2.3 → pyscript_programming_language-1.3.1}/pyscript_programming_language.egg-info/dependency_links.txt +0 -0
- {pyscript_programming_language-1.2.3 → pyscript_programming_language-1.3.1}/pyscript_programming_language.egg-info/top_level.txt +0 -0
- {pyscript_programming_language-1.2.3 → pyscript_programming_language-1.3.1}/setup.cfg +0 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pyscript-programming-language
|
|
3
|
+
Version: 1.3.1
|
|
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, you can see on [PyScript documentation here](https://azzammuhyala.github.io/pyscript) or
|
|
54
|
+
[PyScript repository](https://github.com/azzammuhyala/pyscript).
|
|
55
|
+
|
|
56
|
+
## Behind it
|
|
57
|
+
This language created from based up on a
|
|
58
|
+
[YouTube tutorial](https://www.youtube.com/playlist?list=PLZQftyCk7_SdoVexSmwy_tBgs7P0b97yD). At least, it takes
|
|
59
|
+
about 6 months to learn it, and also need to learn general things that exist in other programming languages.
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
## Behind it
|
|
26
|
+
This language created from based up on a
|
|
27
|
+
[YouTube tutorial](https://www.youtube.com/playlist?list=PLZQftyCk7_SdoVexSmwy_tBgs7P0b97yD). At least, it takes
|
|
28
|
+
about 6 months to learn it, and also need to learn general things that exist in other programming languages.
|
{pyscript_programming_language-1.2.3 → pyscript_programming_language-1.3.1}/pyscript/__init__.py
RENAMED
|
@@ -15,7 +15,7 @@ from .core.highlight import HLFMT_HTML, HLFMT_ANSI, pys_highlight
|
|
|
15
15
|
from .core.runner import pys_exec, pys_eval
|
|
16
16
|
from .core.version import __version__, __date__
|
|
17
17
|
|
|
18
|
-
__all__ =
|
|
18
|
+
__all__ = (
|
|
19
19
|
'core',
|
|
20
20
|
'DEFAULT',
|
|
21
21
|
'OPTIMIZE',
|
|
@@ -28,6 +28,6 @@ __all__ = [
|
|
|
28
28
|
'pys_highlight',
|
|
29
29
|
'pys_exec',
|
|
30
30
|
'pys_eval'
|
|
31
|
-
|
|
31
|
+
)
|
|
32
32
|
|
|
33
33
|
del sys
|
{pyscript_programming_language-1.2.3 → pyscript_programming_language-1.3.1}/pyscript/__init__.pyi
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
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
|
|
@@ -34,7 +34,7 @@ def pys_highlight(
|
|
|
34
34
|
'end'
|
|
35
35
|
], PysPosition, str], str]] = None,
|
|
36
36
|
max_parenthesis_level: int = 3,
|
|
37
|
-
flags: int =
|
|
37
|
+
flags: int = COMMENT
|
|
38
38
|
) -> str: ...
|
|
39
39
|
|
|
40
40
|
def pys_exec(
|
|
@@ -51,4 +51,4 @@ def pys_eval(
|
|
|
51
51
|
|
|
52
52
|
__version__: str
|
|
53
53
|
__date__: str
|
|
54
|
-
__all__:
|
|
54
|
+
__all__: Tuple[str]
|
{pyscript_programming_language-1.2.3 → pyscript_programming_language-1.3.1}/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,7 +60,7 @@ 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
|
|
|
63
65
|
code = 0
|
|
64
66
|
flags = DEFAULT
|
|
@@ -67,38 +69,38 @@ if args.optimize:
|
|
|
67
69
|
flags |= OPTIMIZE
|
|
68
70
|
|
|
69
71
|
if args.file is not None:
|
|
70
|
-
|
|
72
|
+
path = normalize_path(args.file)
|
|
71
73
|
|
|
72
74
|
try:
|
|
73
|
-
with open(
|
|
74
|
-
file = PysFileBuffer(file.read(),
|
|
75
|
+
with open(path, 'r') as file:
|
|
76
|
+
file = PysFileBuffer(file.read(), path)
|
|
75
77
|
|
|
76
78
|
except FileNotFoundError:
|
|
77
|
-
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))
|
|
78
80
|
|
|
79
81
|
except PermissionError:
|
|
80
|
-
parser.error("can't open file {!r}: Permission denied.".format(
|
|
82
|
+
parser.error("can't open file {!r}: Permission denied.".format(path))
|
|
81
83
|
|
|
82
84
|
except IsADirectoryError:
|
|
83
|
-
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))
|
|
84
86
|
|
|
85
87
|
except NotADirectoryError:
|
|
86
|
-
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))
|
|
87
89
|
|
|
88
90
|
except (OSError, IOError):
|
|
89
|
-
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))
|
|
90
92
|
|
|
91
93
|
except UnicodeDecodeError:
|
|
92
|
-
parser.error("can't read file {!r}: Bad file.".format(
|
|
94
|
+
parser.error("can't read file {!r}: Bad file.".format(path))
|
|
93
95
|
|
|
94
96
|
except BaseException as e:
|
|
95
|
-
parser.error("file {!r}: Unexpected error: {}".format(
|
|
97
|
+
parser.error("file {!r}: Unexpected error: {}".format(path, e))
|
|
96
98
|
|
|
97
99
|
if args.highlight:
|
|
98
100
|
try:
|
|
99
101
|
print(pys_highlight(file, HLFMT_HTML if args.highlight == 'html' else HLFMT_ANSI))
|
|
100
102
|
except BaseException as e:
|
|
101
|
-
parser.error("file {!r}: Tokenize error: {}".format(
|
|
103
|
+
parser.error("file {!r}: Tokenize error: {}".format(path, e))
|
|
102
104
|
|
|
103
105
|
else:
|
|
104
106
|
symtab = build_symbol_table(file)
|
|
@@ -116,7 +118,7 @@ if args.file is not None:
|
|
|
116
118
|
if args.inspect:
|
|
117
119
|
code = pys_shell(
|
|
118
120
|
symbol_table=result.context.symbol_table,
|
|
119
|
-
flags=result.flags
|
|
121
|
+
flags=result.context.flags
|
|
120
122
|
)
|
|
121
123
|
|
|
122
124
|
elif args.command is not None:
|
|
@@ -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
|
|
|
@@ -23,6 +24,7 @@ class PysValidator(Pys):
|
|
|
23
24
|
SyntaxError(message),
|
|
24
25
|
PysContext(
|
|
25
26
|
file=self.file,
|
|
27
|
+
flags=self.flags,
|
|
26
28
|
parent=self.context,
|
|
27
29
|
parent_entry_position=self.context_parent_entry_position
|
|
28
30
|
),
|
|
@@ -31,7 +33,6 @@ class PysValidator(Pys):
|
|
|
31
33
|
|
|
32
34
|
def visit(self, node):
|
|
33
35
|
func = getattr(self, 'visit_' + type(node).__name__[3:], None)
|
|
34
|
-
|
|
35
36
|
if not self.error and func:
|
|
36
37
|
func(node)
|
|
37
38
|
|
|
@@ -101,11 +102,14 @@ class PysValidator(Pys):
|
|
|
101
102
|
|
|
102
103
|
def visit_UnaryOperatorNode(self, node):
|
|
103
104
|
if node.operand.type in (TOKENS['INCREMENT'], TOKENS['DECREMENT']):
|
|
104
|
-
if
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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)
|
|
109
113
|
return
|
|
110
114
|
|
|
111
115
|
self.visit(node.value)
|
|
@@ -156,6 +160,11 @@ class PysValidator(Pys):
|
|
|
156
160
|
if self.error:
|
|
157
161
|
return
|
|
158
162
|
|
|
163
|
+
if node.else_body:
|
|
164
|
+
self.visit(node.else_body)
|
|
165
|
+
if self.error:
|
|
166
|
+
return
|
|
167
|
+
|
|
159
168
|
if node.finally_body:
|
|
160
169
|
self.visit(node.finally_body)
|
|
161
170
|
|
|
@@ -314,6 +323,10 @@ class PysValidator(Pys):
|
|
|
314
323
|
if node.value:
|
|
315
324
|
self.visit(node.value)
|
|
316
325
|
|
|
326
|
+
def visit_GlobalNode(self, node):
|
|
327
|
+
if self.in_function == 0:
|
|
328
|
+
self.throw("global outside of function", node.position)
|
|
329
|
+
|
|
317
330
|
def visit_DeleteNode(self, node):
|
|
318
331
|
for element in node.targets:
|
|
319
332
|
|
|
@@ -331,6 +344,10 @@ class PysValidator(Pys):
|
|
|
331
344
|
if self.error:
|
|
332
345
|
return
|
|
333
346
|
|
|
347
|
+
elif isinstance(element, PysKeywordNode):
|
|
348
|
+
self.throw("cannot delete {}".format(element.token.value), element.position)
|
|
349
|
+
return
|
|
350
|
+
|
|
334
351
|
elif not isinstance(element, PysIdentifierNode):
|
|
335
352
|
self.throw("cannot delete literal", element.position)
|
|
336
353
|
return
|
|
@@ -387,5 +404,8 @@ class PysValidator(Pys):
|
|
|
387
404
|
elif isinstance(node, PysAttributeNode):
|
|
388
405
|
self.visit(node.object)
|
|
389
406
|
|
|
407
|
+
elif isinstance(node, PysKeywordNode):
|
|
408
|
+
self.throw("cannot assign to {}".format(node.token.value), node.position)
|
|
409
|
+
|
|
390
410
|
elif not isinstance(node, PysIdentifierNode):
|
|
391
411
|
self.throw(message, node.position)
|
|
@@ -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',
|
|
@@ -133,8 +139,8 @@ PYTHON_EXTENSIONS = {'.ipy', '.py', '.pyc', '.pyi', '.pyo', '.pyp', '.pyw', '.py
|
|
|
133
139
|
|
|
134
140
|
# flags
|
|
135
141
|
DEFAULT = 0
|
|
136
|
-
OPTIMIZE = 1 <<
|
|
137
|
-
SILENT = 1 <<
|
|
138
|
-
RETRES = 1 <<
|
|
139
|
-
COMMENT = 1 <<
|
|
140
|
-
REVERSE_POW_XOR = 1 <<
|
|
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)
|
|
@@ -15,18 +15,20 @@ class PysException(Pys):
|
|
|
15
15
|
return '<Exception of {!r}>'.format(self.exception)
|
|
16
16
|
|
|
17
17
|
def string_traceback(self):
|
|
18
|
-
frames = []
|
|
19
|
-
|
|
20
18
|
context = self.context
|
|
21
19
|
position = self.position
|
|
22
20
|
|
|
21
|
+
frames = []
|
|
22
|
+
|
|
23
23
|
while context:
|
|
24
|
+
is_positionless = position.is_positionless()
|
|
25
|
+
|
|
24
26
|
frames.append(
|
|
25
|
-
' File "{}"
|
|
27
|
+
' File "{}"{}{}{}'.format(
|
|
26
28
|
position.file.name,
|
|
27
|
-
position.start_line,
|
|
29
|
+
'' if is_positionless else ', line {}'.format(position.start_line),
|
|
28
30
|
'' if context.name is None else ', in {}'.format(context.name),
|
|
29
|
-
space_indent(position.format_arrow(), 4)
|
|
31
|
+
'' if is_positionless else '\n{}'.format(space_indent(position.format_arrow(), 4))
|
|
30
32
|
)
|
|
31
33
|
)
|
|
32
34
|
|
|
@@ -56,9 +58,9 @@ class PysException(Pys):
|
|
|
56
58
|
|
|
57
59
|
if isinstance(self.exception, type):
|
|
58
60
|
return result + self.exception.__name__
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
61
|
+
|
|
62
|
+
message = str(self.exception)
|
|
63
|
+
return result + type(self.exception).__name__ + (': ' + message if message else '')
|
|
62
64
|
|
|
63
65
|
class PysShouldReturn(Pys, BaseException):
|
|
64
66
|
|
|
@@ -74,6 +76,6 @@ class PysShouldReturn(Pys, BaseException):
|
|
|
74
76
|
|
|
75
77
|
if isinstance(exception, type):
|
|
76
78
|
return exception.__name__
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
79
|
+
|
|
80
|
+
message = str(exception)
|
|
81
|
+
return type(exception).__name__ + (': ' + message if message else '')
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
from .cache import hook
|
|
2
1
|
from .exceptions import PysException, PysShouldReturn
|
|
3
2
|
from .objects import PysPythonFunction, PysFunction
|
|
4
3
|
from .position import PysPosition
|
|
5
4
|
from .results import PysRunTimeResult
|
|
6
5
|
from .utils import is_object_of, print_traceback
|
|
7
6
|
|
|
7
|
+
from . import cache
|
|
8
|
+
|
|
8
9
|
from contextlib import contextmanager
|
|
9
10
|
from types import MethodType
|
|
10
11
|
|
|
@@ -17,41 +18,41 @@ def handle_exception(result, context, position):
|
|
|
17
18
|
except BaseException as e:
|
|
18
19
|
result.failure(PysException(e, context, position))
|
|
19
20
|
|
|
20
|
-
def handle_call(object, context, position
|
|
21
|
+
def handle_call(object, context, position):
|
|
21
22
|
if isinstance(object, PysFunction):
|
|
22
|
-
object.__code__
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
code = object.__code__
|
|
24
|
+
code.call_context = context
|
|
25
|
+
code.position = position
|
|
25
26
|
|
|
26
27
|
elif isinstance(object, PysPythonFunction):
|
|
27
|
-
object.__code__
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
code = object.__code__
|
|
29
|
+
code.context = context
|
|
30
|
+
code.position = position
|
|
30
31
|
|
|
31
32
|
elif isinstance(object, type):
|
|
32
33
|
for call in ('__new__', '__init__'):
|
|
33
|
-
handle_call(getattr(object, call, None), context, position
|
|
34
|
+
handle_call(getattr(object, call, None), context, position)
|
|
34
35
|
|
|
35
36
|
elif isinstance(object, MethodType):
|
|
36
|
-
handle_call(object.__func__, context, position
|
|
37
|
+
handle_call(object.__func__, context, position)
|
|
37
38
|
|
|
38
39
|
def handle_execute(result):
|
|
39
40
|
result_runtime = PysRunTimeResult()
|
|
40
41
|
|
|
41
|
-
with handle_exception(result_runtime, result.context, PysPosition(result.context.file,
|
|
42
|
+
with handle_exception(result_runtime, result.context, PysPosition(result.context.file, -1, -1)):
|
|
42
43
|
|
|
43
44
|
if result.error:
|
|
44
45
|
if is_object_of(result.error.exception, SystemExit):
|
|
45
46
|
return result.error.exception.code
|
|
46
|
-
if hook.exception is not None:
|
|
47
|
-
hook.exception(result.error)
|
|
47
|
+
if cache.hook.exception is not None:
|
|
48
|
+
cache.hook.exception(result.error)
|
|
48
49
|
return 1
|
|
49
50
|
|
|
50
|
-
elif hook.display is not None:
|
|
51
|
+
elif cache.hook.display is not None:
|
|
51
52
|
if result.mode == 'exec' and len(result.value) == 1:
|
|
52
|
-
hook.display(result.value[0])
|
|
53
|
+
cache.hook.display(result.value[0])
|
|
53
54
|
elif result.mode == 'eval':
|
|
54
|
-
hook.display(result.value)
|
|
55
|
+
cache.hook.display(result.value)
|
|
55
56
|
|
|
56
57
|
if result_runtime.should_return():
|
|
57
58
|
if result_runtime.error:
|