Compare commits
5 Commits
53260b1168
...
v0.1.0
| Author | SHA1 | Date | |
|---|---|---|---|
| 72d02e0a8d | |||
| 74e62a2b0d | |||
| 2604331c7a | |||
| 666657926b | |||
| 8734e1eba9 |
146
poetry.lock
generated
146
poetry.lock
generated
@ -1,147 +1,7 @@
|
|||||||
# This file is automatically @generated by Poetry 2.1.1 and should not be changed by hand.
|
# This file is automatically @generated by Poetry 2.0.1 and should not be changed by hand.
|
||||||
|
package = []
|
||||||
[[package]]
|
|
||||||
name = "click"
|
|
||||||
version = "8.1.8"
|
|
||||||
description = "Composable command line interface toolkit"
|
|
||||||
optional = false
|
|
||||||
python-versions = ">=3.7"
|
|
||||||
groups = ["main"]
|
|
||||||
files = [
|
|
||||||
{file = "click-8.1.8-py3-none-any.whl", hash = "sha256:63c132bbbed01578a06712a2d1f497bb62d9c1c0d329b7903a866228027263b2"},
|
|
||||||
{file = "click-8.1.8.tar.gz", hash = "sha256:ed53c9d8990d83c2a27deae68e4ee337473f6330c040a31d4225c9574d16096a"},
|
|
||||||
]
|
|
||||||
|
|
||||||
[package.dependencies]
|
|
||||||
colorama = {version = "*", markers = "platform_system == \"Windows\""}
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "colorama"
|
|
||||||
version = "0.4.6"
|
|
||||||
description = "Cross-platform colored terminal text."
|
|
||||||
optional = false
|
|
||||||
python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7"
|
|
||||||
groups = ["main"]
|
|
||||||
markers = "platform_system == \"Windows\""
|
|
||||||
files = [
|
|
||||||
{file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"},
|
|
||||||
{file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"},
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "markdown-it-py"
|
|
||||||
version = "3.0.0"
|
|
||||||
description = "Python port of markdown-it. Markdown parsing, done right!"
|
|
||||||
optional = false
|
|
||||||
python-versions = ">=3.8"
|
|
||||||
groups = ["main"]
|
|
||||||
files = [
|
|
||||||
{file = "markdown-it-py-3.0.0.tar.gz", hash = "sha256:e3f60a94fa066dc52ec76661e37c851cb232d92f9886b15cb560aaada2df8feb"},
|
|
||||||
{file = "markdown_it_py-3.0.0-py3-none-any.whl", hash = "sha256:355216845c60bd96232cd8d8c40e8f9765cc86f46880e43a8fd22dc1a1a8cab1"},
|
|
||||||
]
|
|
||||||
|
|
||||||
[package.dependencies]
|
|
||||||
mdurl = ">=0.1,<1.0"
|
|
||||||
|
|
||||||
[package.extras]
|
|
||||||
benchmarking = ["psutil", "pytest", "pytest-benchmark"]
|
|
||||||
code-style = ["pre-commit (>=3.0,<4.0)"]
|
|
||||||
compare = ["commonmark (>=0.9,<1.0)", "markdown (>=3.4,<4.0)", "mistletoe (>=1.0,<2.0)", "mistune (>=2.0,<3.0)", "panflute (>=2.3,<3.0)"]
|
|
||||||
linkify = ["linkify-it-py (>=1,<3)"]
|
|
||||||
plugins = ["mdit-py-plugins"]
|
|
||||||
profiling = ["gprof2dot"]
|
|
||||||
rtd = ["jupyter_sphinx", "mdit-py-plugins", "myst-parser", "pyyaml", "sphinx", "sphinx-copybutton", "sphinx-design", "sphinx_book_theme"]
|
|
||||||
testing = ["coverage", "pytest", "pytest-cov", "pytest-regressions"]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "mdurl"
|
|
||||||
version = "0.1.2"
|
|
||||||
description = "Markdown URL utilities"
|
|
||||||
optional = false
|
|
||||||
python-versions = ">=3.7"
|
|
||||||
groups = ["main"]
|
|
||||||
files = [
|
|
||||||
{file = "mdurl-0.1.2-py3-none-any.whl", hash = "sha256:84008a41e51615a49fc9966191ff91509e3c40b939176e643fd50a5c2196b8f8"},
|
|
||||||
{file = "mdurl-0.1.2.tar.gz", hash = "sha256:bb413d29f5eea38f31dd4754dd7377d4465116fb207585f97bf925588687c1ba"},
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "pygments"
|
|
||||||
version = "2.19.1"
|
|
||||||
description = "Pygments is a syntax highlighting package written in Python."
|
|
||||||
optional = false
|
|
||||||
python-versions = ">=3.8"
|
|
||||||
groups = ["main"]
|
|
||||||
files = [
|
|
||||||
{file = "pygments-2.19.1-py3-none-any.whl", hash = "sha256:9ea1544ad55cecf4b8242fab6dd35a93bbce657034b0611ee383099054ab6d8c"},
|
|
||||||
{file = "pygments-2.19.1.tar.gz", hash = "sha256:61c16d2a8576dc0649d9f39e089b5f02bcd27fba10d8fb4dcc28173f7a45151f"},
|
|
||||||
]
|
|
||||||
|
|
||||||
[package.extras]
|
|
||||||
windows-terminal = ["colorama (>=0.4.6)"]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rich"
|
|
||||||
version = "13.9.4"
|
|
||||||
description = "Render rich text, tables, progress bars, syntax highlighting, markdown and more to the terminal"
|
|
||||||
optional = false
|
|
||||||
python-versions = ">=3.8.0"
|
|
||||||
groups = ["main"]
|
|
||||||
files = [
|
|
||||||
{file = "rich-13.9.4-py3-none-any.whl", hash = "sha256:6049d5e6ec054bf2779ab3358186963bac2ea89175919d699e378b99738c2a90"},
|
|
||||||
{file = "rich-13.9.4.tar.gz", hash = "sha256:439594978a49a09530cff7ebc4b5c7103ef57baf48d5ea3184f21d9a2befa098"},
|
|
||||||
]
|
|
||||||
|
|
||||||
[package.dependencies]
|
|
||||||
markdown-it-py = ">=2.2.0"
|
|
||||||
pygments = ">=2.13.0,<3.0.0"
|
|
||||||
|
|
||||||
[package.extras]
|
|
||||||
jupyter = ["ipywidgets (>=7.5.1,<9)"]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "shellingham"
|
|
||||||
version = "1.5.4"
|
|
||||||
description = "Tool to Detect Surrounding Shell"
|
|
||||||
optional = false
|
|
||||||
python-versions = ">=3.7"
|
|
||||||
groups = ["main"]
|
|
||||||
files = [
|
|
||||||
{file = "shellingham-1.5.4-py2.py3-none-any.whl", hash = "sha256:7ecfff8f2fd72616f7481040475a65b2bf8af90a56c89140852d1120324e8686"},
|
|
||||||
{file = "shellingham-1.5.4.tar.gz", hash = "sha256:8dbca0739d487e5bd35ab3ca4b36e11c4078f3a234bfce294b0a0291363404de"},
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "typer"
|
|
||||||
version = "0.15.2"
|
|
||||||
description = "Typer, build great CLIs. Easy to code. Based on Python type hints."
|
|
||||||
optional = false
|
|
||||||
python-versions = ">=3.7"
|
|
||||||
groups = ["main"]
|
|
||||||
files = [
|
|
||||||
{file = "typer-0.15.2-py3-none-any.whl", hash = "sha256:46a499c6107d645a9c13f7ee46c5d5096cae6f5fc57dd11eccbbb9ae3e44ddfc"},
|
|
||||||
{file = "typer-0.15.2.tar.gz", hash = "sha256:ab2fab47533a813c49fe1f16b1a370fd5819099c00b119e0633df65f22144ba5"},
|
|
||||||
]
|
|
||||||
|
|
||||||
[package.dependencies]
|
|
||||||
click = ">=8.0.0"
|
|
||||||
rich = ">=10.11.0"
|
|
||||||
shellingham = ">=1.3.0"
|
|
||||||
typing-extensions = ">=3.7.4.3"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "typing-extensions"
|
|
||||||
version = "4.12.2"
|
|
||||||
description = "Backported and Experimental Type Hints for Python 3.8+"
|
|
||||||
optional = false
|
|
||||||
python-versions = ">=3.8"
|
|
||||||
groups = ["main"]
|
|
||||||
files = [
|
|
||||||
{file = "typing_extensions-4.12.2-py3-none-any.whl", hash = "sha256:04e5ca0351e0f3f85c6853954072df659d0d13fac324d0072316b67d7794700d"},
|
|
||||||
{file = "typing_extensions-4.12.2.tar.gz", hash = "sha256:1a7ead55c7e559dd4dee8856e3a88b41225abfe1ce8df57b7c13915fe121ffb8"},
|
|
||||||
]
|
|
||||||
|
|
||||||
[metadata]
|
[metadata]
|
||||||
lock-version = "2.1"
|
lock-version = "2.1"
|
||||||
python-versions = ">=3.11"
|
python-versions = ">=3.11"
|
||||||
content-hash = "4c9c3660ca9c9584e6ecaba05818854acf7c3aae30908e7804d0c9d7f4fa67f8"
|
content-hash = "f5666f5625d676c506924a57dc0520a1f3ed2b2c774baed3dc85353594f8473d"
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "markov"
|
name = "markov"
|
||||||
version = "0.0.1"
|
version = "0.1.0"
|
||||||
description = ""
|
description = ""
|
||||||
authors = [
|
authors = [
|
||||||
{name = "ElectronixTM"}
|
{name = "ElectronixTM"}
|
||||||
@ -8,7 +8,6 @@ authors = [
|
|||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">=3.11"
|
requires-python = ">=3.11"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"typer (>=0.15.2,<0.16.0)"
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
48
src/interactive.py
Normal file
48
src/interactive.py
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
from rulebook import Rulebook
|
||||||
|
from rule import Rule
|
||||||
|
|
||||||
|
def format_rule(rule: Rule) -> str:
|
||||||
|
"""
|
||||||
|
Just like CLI defined conversion from Rule to str
|
||||||
|
"""
|
||||||
|
arrow = "->|" if rule.is_blocking else "->"
|
||||||
|
return f"{rule.operand} {arrow} {rule.target}"
|
||||||
|
|
||||||
|
def interactve_mode(rulebook: Rulebook):
|
||||||
|
"""
|
||||||
|
Handles interactive mode of the program
|
||||||
|
"""
|
||||||
|
print("To get help type \"h:\" in prompt")
|
||||||
|
_print_rules(rulebook.rules)
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
user_input = input("#> ")
|
||||||
|
except EOFError:
|
||||||
|
return
|
||||||
|
if user_input.startswith("h:"):
|
||||||
|
print_help()
|
||||||
|
elif user_input.startswith("r:"):
|
||||||
|
_print_rules(rulebook.rules)
|
||||||
|
elif user_input.startswith("v:"):
|
||||||
|
user_input = user_input[2:].strip(" \t")
|
||||||
|
_, log = rulebook.logged_transform(user_input)
|
||||||
|
print(log)
|
||||||
|
elif user_input.startswith("e:"):
|
||||||
|
return
|
||||||
|
elif user_input.startswith(":"):
|
||||||
|
print(rulebook.transform(user_input[1:]))
|
||||||
|
else:
|
||||||
|
print(rulebook.transform(user_input))
|
||||||
|
|
||||||
|
def print_help():
|
||||||
|
print("you can type expressions right after prompt. However there is some "
|
||||||
|
'reserved chars: "h:" to print help, "v:" to run next expression in '
|
||||||
|
'verbose mode, "r:" to view rules, "e:" to exit, and ":" to imidiately '
|
||||||
|
'start prompt.Can be omited if your prompt doesn\'t start from'
|
||||||
|
'reserved sequence. Note that your input after "h:", "e:" and "r:" will '
|
||||||
|
'be ignored')
|
||||||
|
|
||||||
|
def _print_rules(rules: list[Rule]) -> None:
|
||||||
|
for num, rule in enumerate(rules, start=1):
|
||||||
|
print(" " * 4 + str(num) + " : " + format_rule(rule))
|
||||||
|
|
||||||
@ -1,5 +1,39 @@
|
|||||||
|
from rulesparser import RulesParser
|
||||||
|
from rulebook import Rulebook
|
||||||
|
from interactive import interactve_mode
|
||||||
|
import argparse
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
raise NotImplementedError("Sorry, this project is WIP and didn't implement user functionality yet")
|
parser = argparse.ArgumentParser(
|
||||||
|
prog = "Markov",
|
||||||
|
description = "Simple tool to apply Markov's normal algorithms"
|
||||||
|
)
|
||||||
|
parser.add_argument("rulebook", type=str, help="File with the rules for algorithm")
|
||||||
|
parser.add_argument("-c", "--command-line-input",
|
||||||
|
help="Takes input from user via command line "
|
||||||
|
"arguments. There should be only one string. "
|
||||||
|
"Please, use quotation marks")
|
||||||
|
parser.add_argument("-v", "--verbose", action="store_true",
|
||||||
|
help="If set, verbose output will be produced. "
|
||||||
|
"It'll contain all intermediate transformations, "
|
||||||
|
"reason of stop etc.")
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
rules = RulesParser().parse(args.rulebook)
|
||||||
|
rulebook = Rulebook(rules)
|
||||||
|
print(args.command_line_input)
|
||||||
|
if not args.command_line_input:
|
||||||
|
interactve_mode(rulebook)
|
||||||
|
return
|
||||||
|
|
||||||
|
transformer = (rulebook.logged_transform if args.verbose
|
||||||
|
else rulebook.transform)
|
||||||
|
if args.verbose:
|
||||||
|
_, log = transformer(args.command_line_input)
|
||||||
|
print(log)
|
||||||
|
else:
|
||||||
|
print(transformer(args.command_line_input))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
@ -61,10 +61,9 @@ class Rulebook:
|
|||||||
log += string + '\n'
|
log += string + '\n'
|
||||||
log += "FINAL_RULE".center(CENTER_WIDTH, "_") + '\n'
|
log += "FINAL_RULE".center(CENTER_WIDTH, "_") + '\n'
|
||||||
return string, log
|
return string, log
|
||||||
# raise ValueError("The amount of transformations exceeded "
|
|
||||||
# f"{self.MAX_DEPTH}. You can change maximum "
|
log += "OVERFLOW".center(CENTER_WIDTH, "_") + '\n'
|
||||||
# "amount by setting class variable MAX_DEPTH,"
|
return None, log
|
||||||
# " but may be something wrong with your input")
|
|
||||||
|
|
||||||
def _log_rule(self, rule) -> str:
|
def _log_rule(self, rule) -> str:
|
||||||
arrow = "->|" if rule.is_blocking else "->"
|
arrow = "->|" if rule.is_blocking else "->"
|
||||||
|
|||||||
Reference in New Issue
Block a user