rising-sse 0.1.dev0__tar.gz → 0.2.dev0__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.
- {rising_sse-0.1.dev0 → rising_sse-0.2.dev0}/PKG-INFO +1 -1
- {rising_sse-0.1.dev0 → rising_sse-0.2.dev0}/pyproject.toml +1 -1
- rising_sse-0.2.dev0/sse/__init__.py +36 -0
- {rising_sse-0.1.dev0 → rising_sse-0.2.dev0}/sse/engine.py +7 -6
- {rising_sse-0.1.dev0 → rising_sse-0.2.dev0}/sse/mode.py +16 -4
- rising_sse-0.1.dev0/sse/__init__.py +0 -17
- {rising_sse-0.1.dev0 → rising_sse-0.2.dev0}/.gitignore +0 -0
- {rising_sse-0.1.dev0 → rising_sse-0.2.dev0}/sse/parser.py +0 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
from .engine import Engine, run
|
|
2
|
+
from .mode import Mode, GetMode, primitive, prompt, cycle
|
|
3
|
+
from .parser import tokenize
|
|
4
|
+
import os
|
|
5
|
+
|
|
6
|
+
def basic_engine():
|
|
7
|
+
"""
|
|
8
|
+
call this function if you just want to play around with the base form of the engine
|
|
9
|
+
without modifying or extending its functionality or hooking it into an API or game.
|
|
10
|
+
Otherwise, you can create an instance of the engine using Engine(), and start it by calling run()
|
|
11
|
+
on it, or ticking it within your own loop function.
|
|
12
|
+
To retrieve any mode use its modename in GetMode(modename:str).
|
|
13
|
+
To create a mode use Mode(modename:str, available:bool=True), set available to False to hide it
|
|
14
|
+
from GetMode
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
engine = Engine()
|
|
18
|
+
run(engine)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
script_mode = Mode("script")
|
|
22
|
+
@cycle(script_mode)
|
|
23
|
+
def endscript(mode, engine):
|
|
24
|
+
engine.running = False
|
|
25
|
+
|
|
26
|
+
def single_script(filepath:str):
|
|
27
|
+
engine = Engine(script_mode)
|
|
28
|
+
if os.path.exists(filepath):
|
|
29
|
+
with open(filepath) as file:
|
|
30
|
+
code = file.read()
|
|
31
|
+
frame = engine.Frame(script_mode, script_mode['main'], tokenize(code))
|
|
32
|
+
engine.AddFrame(frame)
|
|
33
|
+
else:
|
|
34
|
+
engine.error(f"Could not load script '{filepath}'.", "Missing File")
|
|
35
|
+
|
|
36
|
+
run(engine)
|
|
@@ -3,7 +3,7 @@ from .parser import tokenize
|
|
|
3
3
|
|
|
4
4
|
class Engine:
|
|
5
5
|
__slots__ = ("frame_stack", "running", "engine_globals", "mode")
|
|
6
|
-
def __init__(self, starter = GetMode('
|
|
6
|
+
def __init__(self, starter = GetMode('repl'), engine_globals = default_globals):
|
|
7
7
|
self.frame_stack = []
|
|
8
8
|
self.running = False
|
|
9
9
|
self.mode = starter
|
|
@@ -59,11 +59,12 @@ class Engine:
|
|
|
59
59
|
if 'prompt' in mode:
|
|
60
60
|
mode['prompt'](mode)
|
|
61
61
|
else:
|
|
62
|
-
self.engine_globals[
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
62
|
+
self.engine_globals['prompt'](mode)
|
|
63
|
+
if 'cycle' in mode:
|
|
64
|
+
mode['cycle'](mode, self)
|
|
65
|
+
else:
|
|
66
|
+
self.engine_globals['cycle'](mode, self)
|
|
67
|
+
|
|
67
68
|
|
|
68
69
|
def handle_element(self, current_element, frame, mode, scope, stack):
|
|
69
70
|
element_type, value = current_element
|
|
@@ -34,22 +34,34 @@ def prompt(mode):
|
|
|
34
34
|
def wrap(method):
|
|
35
35
|
mode['prompt'] = method
|
|
36
36
|
return wrap
|
|
37
|
+
def cycle(mode):
|
|
38
|
+
def wrap(method):
|
|
39
|
+
mode['cycle'] = method
|
|
40
|
+
return wrap
|
|
37
41
|
|
|
38
42
|
# the default mode for globals that are accessible in any other mode (can be changed)
|
|
39
43
|
default_globals = Mode('default_globals', False)
|
|
40
|
-
|
|
44
|
+
repl = Mode('repl')
|
|
41
45
|
|
|
46
|
+
@prompt(repl)
|
|
47
|
+
def repl_prompt(self):
|
|
48
|
+
print(">>>", end=" ")
|
|
42
49
|
|
|
43
50
|
@prompt(default_globals)
|
|
44
|
-
def
|
|
51
|
+
def default_prompt(self):
|
|
45
52
|
pass
|
|
46
|
-
|
|
53
|
+
@cycle(default_globals)
|
|
54
|
+
def default_endcycle(mode, engine):
|
|
55
|
+
usertext = input()
|
|
56
|
+
code = tokenize(usertext)
|
|
57
|
+
frame = engine.Frame(mode, mode['main'], code)
|
|
58
|
+
engine.AddFrame(frame)
|
|
47
59
|
|
|
48
60
|
# OUTPUT
|
|
49
61
|
@primitive(default_globals, "print")
|
|
50
62
|
def _print(frame, engine, stack):
|
|
51
63
|
output = " ".join(str(element) for element in stack[::-1])
|
|
52
|
-
print(output)
|
|
64
|
+
print(output, end="")
|
|
53
65
|
if not output.endswith('\n'):
|
|
54
66
|
print()
|
|
55
67
|
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
from .engine import Engine, run
|
|
2
|
-
from .mode import Mode, GetMode, primitive, prompt
|
|
3
|
-
|
|
4
|
-
def basic_engine():
|
|
5
|
-
"""
|
|
6
|
-
call this function if you just want to play around with the base form of the engine
|
|
7
|
-
without modifying or extending its functionality or hooking it into an API or game.
|
|
8
|
-
Otherwise, you can create an instance of the engine using Engine(), and start it by calling run()
|
|
9
|
-
on it, or ticking it within your own loop function.
|
|
10
|
-
To retrieve any mode use its modename in GetMode(modename:str).
|
|
11
|
-
To create a mode use Mode(modename:str, available:bool=True), set available to False to hide it
|
|
12
|
-
from GetMode
|
|
13
|
-
"""
|
|
14
|
-
|
|
15
|
-
semantic_syntax_engine = Engine()
|
|
16
|
-
run(semantic_syntax_engine)
|
|
17
|
-
|
|
File without changes
|
|
File without changes
|