aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author简律纯 <i@jyunko.cn>2023-11-05 02:39:00 +0800
committer简律纯 <i@jyunko.cn>2023-11-05 02:39:00 +0800
commit57188fca203643f18409b0fa71d730d771faffed (patch)
treecb0e0990ac030f5f0012640fd7c1707b5bde1156
parentf5e118d18af7f11854ddc34d1f6f07b48b125acd (diff)
downloadTRPGNivis-57188fca203643f18409b0fa71d730d771faffed.tar.gz
TRPGNivis-57188fca203643f18409b0fa71d730d771faffed.zip
chore: add Token
-rw-r--r--pdm.lock50
-rw-r--r--psi/Grammar/Token7
-rw-r--r--psi/__init__.py73
-rw-r--r--psi/psi.py69
-rw-r--r--pyproject.toml1
-rw-r--r--tests/__init__.py23
-rw-r--r--tests/get_next_token.py2
7 files changed, 156 insertions, 69 deletions
diff --git a/pdm.lock b/pdm.lock
index 31140f2..736ebb1 100644
--- a/pdm.lock
+++ b/pdm.lock
@@ -6,7 +6,7 @@ groups = ["default"]
cross_platform = true
static_urls = false
lock_version = "4.3"
-content_hash = "sha256:b629d4cd8e8585cf1128e9dd7f1a585746bc3e94bb588794250bf99dd80d00b3"
+content_hash = "sha256:3ff8281ca1b68fe781cdb20ad83bc38ecc74aab23b6382b6d5c92f063123b18c"
[[package]]
name = "anyio"
@@ -286,6 +286,16 @@ files = [
]
[[package]]
+name = "iniconfig"
+version = "2.0.0"
+requires_python = ">=3.7"
+summary = "brain-dead simple config-ini parsing"
+files = [
+ {file = "iniconfig-2.0.0-py3-none-any.whl", hash = "sha256:b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374"},
+ {file = "iniconfig-2.0.0.tar.gz", hash = "sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3"},
+]
+
+[[package]]
name = "jinja2"
version = "3.1.2"
requires_python = ">=3.7"
@@ -556,6 +566,16 @@ files = [
]
[[package]]
+name = "pluggy"
+version = "1.3.0"
+requires_python = ">=3.8"
+summary = "plugin and hook calling mechanisms for python"
+files = [
+ {file = "pluggy-1.3.0-py3-none-any.whl", hash = "sha256:d89c696a773f8bd377d18e5ecda92b7a3793cbe66c87060a6fb58c7b6e1061f7"},
+ {file = "pluggy-1.3.0.tar.gz", hash = "sha256:cf61ae8f126ac6f7c451172cf30e3e43d3ca77615509771b3a984a0730651e12"},
+]
+
+[[package]]
name = "pygments"
version = "2.16.1"
requires_python = ">=3.7"
@@ -580,6 +600,24 @@ files = [
]
[[package]]
+name = "pytest"
+version = "7.4.2"
+requires_python = ">=3.7"
+summary = "pytest: simple powerful testing with Python"
+dependencies = [
+ "colorama; sys_platform == \"win32\"",
+ "exceptiongroup>=1.0.0rc8; python_version < \"3.11\"",
+ "iniconfig",
+ "packaging",
+ "pluggy<2.0,>=0.12",
+ "tomli>=1.0.0; python_version < \"3.11\"",
+]
+files = [
+ {file = "pytest-7.4.2-py3-none-any.whl", hash = "sha256:1d881c6124e08ff0a1bb75ba3ec0bfd8b5354a01c194ddd5a0a870a48d99b002"},
+ {file = "pytest-7.4.2.tar.gz", hash = "sha256:a766259cfab564a2ad52cb1aae1b881a75c3eb7e34ca3779697c23ed47c47069"},
+]
+
+[[package]]
name = "python-dateutil"
version = "2.8.2"
requires_python = "!=3.0.*,!=3.1.*,!=3.2.*,>=2.7"
@@ -790,6 +828,16 @@ files = [
]
[[package]]
+name = "tomli"
+version = "2.0.1"
+requires_python = ">=3.7"
+summary = "A lil' TOML parser"
+files = [
+ {file = "tomli-2.0.1-py3-none-any.whl", hash = "sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc"},
+ {file = "tomli-2.0.1.tar.gz", hash = "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"},
+]
+
+[[package]]
name = "typing-extensions"
version = "4.8.0"
requires_python = ">=3.8"
diff --git a/psi/Grammar/Token b/psi/Grammar/Token
index 61dd757..0de3014 100644
--- a/psi/Grammar/Token
+++ b/psi/Grammar/Token
@@ -47,4 +47,9 @@ ELLIPSIS '...'
COLONEQUAL ':='
EXCLAMATION '!'
INTEGER 'INTEGER'
-EOF 'EOF' \ No newline at end of file
+EOF 'EOF'
+SPACE ' '
+
+
+AWAIT
+ASYNC
diff --git a/psi/__init__.py b/psi/__init__.py
index 330fcd3..b3e08df 100644
--- a/psi/__init__.py
+++ b/psi/__init__.py
@@ -3,71 +3,10 @@
@BODY 似乎要写的还蛮多的,所以先写几个TODO List
"""
-__all__ = ['psi']
-
-from psi.execution import Execution
-
-class psi:
- """
- A class representing a Psi object.
-
- Args:
- input: The input value for the Psi object.
-
- Returns:
- None
-
- Example:
- ```python
- obj = Psi("example")
- ```
- """
-
- def __init__(self, input):
- """
- Initializes a Psi object.
-
- Args:
- input: The input value for the Psi object.
-
- Returns:
- None
- """
- self.input = input
- self.execution = Execution(input)
- self.result = None
-
- def execute(self):
- """
- Executes the Psi object.
-
- Returns:
- The result of the execution.
- """
- self.result = self.execution.execute()
- return self.result
-
- def get_result(self):
- """
- Retrieves the result of the Psi object.
-
- Returns:
- The result of the execution.
- """
- return self.result
-
- def set_input(self, input):
- """
- Sets the input value for the Psi object.
-
- Args:
- input: The new input value.
-
- Returns:
- None
- """
- self.input = input
- self.execution = Execution(input)
- self.result = None
-
+__all__ = ['psi', 'Exception', 'interpreter', 'lexer', 'Parser']
+from .psi import psi
+from .execution import Execution
+from .interpreter import Interpreter
+from .lexer import Lexer
+from .parsers import Parser \ No newline at end of file
diff --git a/psi/psi.py b/psi/psi.py
new file mode 100644
index 0000000..8df0acd
--- /dev/null
+++ b/psi/psi.py
@@ -0,0 +1,69 @@
+
+from psi.execution import Execution
+
+__all__ = ['psi']
+
+class psi:
+ """
+ A class representing a Psi object.
+
+ Args:
+ input: The input value for the Psi object.
+
+ Returns:
+ None
+
+ Example:
+ ```python
+ obj = Psi("example")
+ ```
+ """
+
+ def __init__(self, input):
+ """
+ Initializes a Psi object.
+
+ Args:
+ input: The input value for the Psi object.
+
+ Returns:
+ None
+ """
+ self.input = input
+ self.execution = Execution(input)
+ self.result = None
+
+ def execute(self):
+ """
+ Executes the Psi object.
+
+ Returns:
+ The result of the execution.
+ """
+ self.result = self.execution.execute()
+ return self.result
+
+ def get_result(self):
+ """
+ Retrieves the result of the Psi object.
+
+ Returns:
+ The result of the execution.
+ """
+ return self.result
+
+ def set_input(self, input):
+ """
+ Sets the input value for the Psi object.
+
+ Args:
+ input: The new input value.
+
+ Returns:
+ None
+ """
+ self.input = input
+ self.execution = Execution(input)
+ self.result = None
+
+
diff --git a/pyproject.toml b/pyproject.toml
index bc5709d..a815413 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -13,6 +13,7 @@ dependencies = [
"mkdocs-material-extensions>=1.2",
"neoteroi-mkdocs>=1.0.4",
"docutils>=0.20.1",
+ "pytest>=7.4.2",
]
requires-python = ">=3.8"
readme = "README.md"
diff --git a/tests/__init__.py b/tests/__init__.py
index e69de29..c9a0e8f 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -0,0 +1,23 @@
+from os.path import join, abspath, dirname
+
+DIR = dirname(abspath(__file__))
+
+token_dict = {} # 创建一个空字典
+
+with open(join(DIR, '..', 'psi', 'Grammar', 'Token'), 'r') as file:
+ for line in file:
+ if line := line.strip():
+ values = line.split() # 使用空格分割行,得到值列表
+ code = values[0] # 第一个值为代码
+ symbol = values[1] if len(values) > 1 else None # 第二个值为符号,如果没有第二个值,则设置为None
+ token_dict[code] = symbol # 将代码和符号添加到字典中
+
+# 将字典中的键值对转换为多个变量及其对应的值
+for code, symbol in token_dict.items():
+ globals()[code] = symbol
+
+# 打印变量及其对应的值
+print(LPAR)
+print(RPAR)
+print(AWAIT)
+# 其他变量... \ No newline at end of file
diff --git a/tests/get_next_token.py b/tests/get_next_token.py
new file mode 100644
index 0000000..2801337
--- /dev/null
+++ b/tests/get_next_token.py
@@ -0,0 +1,2 @@
+class ABC:
+ ... \ No newline at end of file