stack-lang-engine 0.0.1__py3-none-any.whl

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.
@@ -0,0 +1 @@
1
+ from .main import StackEngine
@@ -0,0 +1,46 @@
1
+ import re
2
+
3
+ class StackEngine:
4
+ def __init__(self, words={}, stack=[]):
5
+ self.words = words
6
+ self.stack = stack
7
+
8
+ def add_word(self, name, func):
9
+ self.words[name] = func
10
+ def del_word(self, name):
11
+ del self.words[name]
12
+
13
+ def new_stack(self, name, content=[]):
14
+ self.__dict__[name] = content
15
+
16
+ @staticmethod
17
+ def _parse(text):
18
+ tokens = []
19
+ token_spec = [
20
+ ("STR", r'"[^"]*"'),
21
+ ("NUM", r'\d+(\.\d+)?'),
22
+ ("IDENT", r'[a-zA-Z_][a-zA-Z0-9_]*'),
23
+ ("SKIP", r'[ \n\t]')
24
+ ]
25
+ tok_regex = "|".join(f"(?P<{pair[0]}>{pair[1]})" for pair in token_spec)
26
+
27
+ for mo in re.finditer(tok_regex, text):
28
+ kind, val = mo.lastgroup, mo.group()
29
+
30
+ if kind == "SKIP": continue
31
+ elif kind == "STR": val = val[1:-1]
32
+ elif kind == "NUM": val = int(val)
33
+ tokens.append((kind, val))
34
+
35
+ return tokens
36
+
37
+ def exec(self, text):
38
+ words = self._parse(text)
39
+
40
+ for word in words:
41
+ kind, val = word
42
+ if kind == "IDENT":
43
+ if val in self.words:
44
+ self.words[val]()
45
+ else:
46
+ self.stack.append(val)
@@ -0,0 +1,23 @@
1
+ Metadata-Version: 2.4
2
+ Name: stack_lang_engine
3
+ Version: 0.0.1
4
+ Summary: Simple engine for building stack-oriented languages
5
+ Requires-Python: >=3.8
6
+ Description-Content-Type: text/markdown
7
+
8
+ # About
9
+ SLE (Stack Lang Engine) is a simple tool for creating
10
+ stack-oriented DSL or even small programming languages
11
+
12
+ # Example of usage
13
+ ```py
14
+ import stack_lang_engine as sle
15
+
16
+ eng = sle.StackEngine()
17
+
18
+ eng.add_word("print", lambda: print(eng.stack.pop()))
19
+
20
+ eng.exec('"test" print') # Will print "test"
21
+ ```
22
+ # License
23
+ SLE is licensed under MIT License
@@ -0,0 +1,6 @@
1
+ stack_lang_engine/__init__.py,sha256=WRHV-pgzbz9p0yEkFiSO_VHohaZIpPX-rtAhB_y5Wzk,29
2
+ stack_lang_engine/main.py,sha256=7RnUwiWD6tjHa0qWyau8cgaGfow3HY1-R3Y-v1uIcNw,1244
3
+ stack_lang_engine-0.0.1.dist-info/METADATA,sha256=e48lZpCX-EXyedYQxeXMW1Jy-xbzKzI5EkHMuOCx8cY,536
4
+ stack_lang_engine-0.0.1.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
5
+ stack_lang_engine-0.0.1.dist-info/top_level.txt,sha256=1mTtj5fRSZBkUl3jLMPJPT6HaMi-ZXon-jGiKphV7KY,18
6
+ stack_lang_engine-0.0.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.0.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ stack_lang_engine