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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rising-sse
3
- Version: 0.1.dev0
3
+ Version: 0.2.dev0
4
4
  Summary: The base interpreter and mode system for semantic syntax
5
5
  Author-email: rising <risingwanabe@gmail.com>
6
6
  Maintainer-email: rising <risingwanabe@gmail.com>
@@ -5,7 +5,7 @@ build-backend = "hatchling.build"
5
5
 
6
6
  [project]
7
7
  name = "rising-sse"
8
- version = "0.1dev"
8
+ version = "0.2dev"
9
9
  description = "The base interpreter and mode system for semantic syntax"
10
10
  authors = [
11
11
  { name = "rising", email = "risingwanabe@gmail.com" },
@@ -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('main'), engine_globals = default_globals):
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["prompt"](mode)
63
- usertext = input()
64
- code = tokenize(self.structure_input(usertext))
65
- frame = self.Frame(mode, mode['main'], code)
66
- self.AddFrame(frame)
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
- main = Mode('main')
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 _prompt(self):
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