Sarvar


NameSarvar JSON
Version 2.0.0 PyPI version JSON
download
home_pageNone
SummaryA simple assembly like interpreter implementation. Good for programs which need command shortcuts or command lines for their programs. Not good in speed but good in simplicity.
upload_time2025-02-15 22:08:09
maintainerNone
docs_urlNone
authorSasan Salehi
requires_python>=3.10
licenseNone
keywords assembly like interpreter in python python interpreter sarvar sarvar interpreter sarvar interpreter python simple interpreter for programs
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Sarvar
A simple assembly like interpreter implementation. 
Good for programs which need command shortcuts or command lines for their programs.\
Not good in speed but good in simplicity.
## Installation
(REQUIRES PYTHON>=3.10)\
How to install on windows:\
    `py -m pip install Sarvar`\
How to install on mac, linux, ... : (PIP HAS TO BE INSTALLED)\
`python3 -m pip install Sarvar`\
or\
`pip3 install Sarvar`
## How does it work?
Engine(`cmd: dict[str, EngineCommandFunction]`, `logger: Logger = Logger()`)\
`cmd` keyword argument: `List of all commands`
* Structure
  - `{"Command": Callable of type EngineCommandFunction}`
Each Command function is defined by the `@Engine.engine_command decorator factory`
* Each function gets these arguments
    - `CommandFunction(token: Token)`\
Example:
```python
@Engine.engine_command(bigger_than=0, lesser_than=float("inf"), macro_immutable=False)
def printContent(token: Token) :
    token.args.append("Print")
    token.args.append(" ".join(token.privatevars))
```
#### `Engine.engine_command` arguments
```macro_immutable: bool``` -> Whether macro expansion should be allowed on command's `token.privatevar`\
\
```bigger_than: int|float``` CLI Arguments should be bigger than `number` for infinite say float("inf")\
\
```lesser_than: int|float``` CLI arguments should be lesser than `number` for infinite say float("inf")
### Tokens
Each token is consisted of:
```
globalvars (dict[str, str]): Global variables accessible throughout execution
privatevars (list[str]): Private variables for current scope
args (list[str]): List of command arguments
macros (dict[str, str]): Defined macro replacements
current_line (int): Current line being executed
all_lines (int): Total number of lines in program
````
`privatevars` is the command line arguments for the specified or detected command\
\
`args` push or append or insert a command to be handeled in the debug list\
\
`macros` list of all macros\
\
`current_line` Current line this command being executed on\
\
`all_lines` All of the lines that is in the current command's execution scope\
\
`globalvars` All of the variables defined by other commands
### Debug list
Commands:
```python
{
    "Warn": self._warn_attr,
    "Error": self._error_attr,
    "Debug": self._debug_attr,
    "Print": self._print_attr,
    "MakeCall": self._make_call_attr,
}
```
Insert a command or key into the `token.args` list to be handeled in the `_handle_debug_list` function
- Structure
  * `["Command-Key from commands", "Arguments for the specified commands"]`
  * Example:
    - ["Warn", "hello!", "Error", "This"]
    - Executes "Warn" function from dict with arguments - argument `"hello!"`
    - Executes "Error" function from dict with arguments - argument `"This"`
### General functions and instance setup
To setup an instance first import the "Sarvar" package
```python
>>> import Sarvar as sr
>>> # Then make an instance by the following structure: Engine (cmd: dict[str, EngineCommandFunction], logger: Logger = Logger() #Optional# )
>>> myInstance = sr.Engine({}) # Meaning no commands by default
```
#### Logger class
    Logger class is a class designed for outputing "Engine" outputs
    Such as 'Errors-Warnings and ...'
    How to setup class:
        def_debug = stdout, def_warn = stderr, def_print = stdout, def_err = stderr
        Your output files such as stdout - stderr - ...
        Prints using rich into specified files by specific functions
            def log_error(self, it): rich.print("[red]"+ "ERROR:\t" +str(it)+"[/red]", file=self.error_file)
            def log_warning(self, it): rich.print("[yellow]" + "WARNING:\t" +str(it)+"[/yellow]", file=self.warn_file)
            def log_debug(self, it): rich.print("[blue]"+ "DEBUG:\t" + str(it)+"[/blue]", file=self.debug_file)
            def log_print(self, it): rich.print("[cyan]OUTPUT:\t"+str(it)+"[/cyan]", file =self.print_file)

* `add_cmd` -> Adds a new command `(Args: str, callable)`

* `remove_cmd` -> Removes a command `(Args: str)`

* `push_to_stack` -> Pushes a command to execution stack (`self.commands`) and adds one to the len of execution stack (`self.all_lines`) `(Args: str)`

* `interpret` -> interprets the current line (`self.current_line`) `(Args: None)`

* `HELPER_InterepetAll` -> interprets until the current line becomes bigger or equal than all of the lines (`self.current_line < self.all_lines`) `(Args: None)`

* `set_flag` -> Sets a specific flag to the specified value `(Args: str, bool)`

* `unset_flag` -> Unsets a specific flag `(like the 'not' keyword)` `(Args: str)`

* `Flags` -> `[PROPERTY]` Returns the `self.readView`

* `get_cmd` -> `[PROPERTY]` Returns the `self.cmd` dictionary

#### Flags
Flags for the `self.interpret` function
* `"_attributename_stop"` -> Raises an error when the attributename gets called `(attributes are functions starting with '_' such as '_error_attr')`
* `"PRN_ShowEvents"` -> Show events for every function with `DebugFunctionIfEnabled` decorator
* `"BOL_HNDLE_DBGLST"` Handle debug list?
* `"SHW_OUTPUT"` Show output `(Do not execute functions marked with ExecuteIfEnabled("SHW_OUTPUT") decorator)`
* `"INTERP_EXEC_EVEN_IF_ERROR"` Execute even If there is a problem with command line arguments or current_line
* `"INTERP_EXEC_EVEN_IF_RAISED"` Do not Raise error If there was an error with command execution (`True = Do not raise error, False = Raise error`)
## Links
Homepage: https://github.com/ProgrammEverything/Sarvar \
Issues: https://github.com/ProgrammEverything/Sarvar/issues

## License

[MIT](https://choosealicense.com/licenses/mit/)


## Authors

- [@programmeverything](https://github.com/ProgrammEverything)

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "Sarvar",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": "Sasan salehi <sasanxcoder@gmail.com>",
    "keywords": "Assembly like interpreter in python, Python interpreter, Sarvar, Sarvar interpreter, Sarvar interpreter python, Simple interpreter for programs",
    "author": "Sasan Salehi",
    "author_email": "Sasan Salehi <sasanxcoder@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/19/4a/ba3a2dc7b4936eaa5992cfe2bfcef1870325c69055c3dd0e608bf580604c/sarvar-2.0.0.tar.gz",
    "platform": null,
    "description": "# Sarvar\nA simple assembly like interpreter implementation. \nGood for programs which need command shortcuts or command lines for their programs.\\\nNot good in speed but good in simplicity.\n## Installation\n(REQUIRES PYTHON>=3.10)\\\nHow to install on windows:\\\n    `py -m pip install Sarvar`\\\nHow to install on mac, linux, ... : (PIP HAS TO BE INSTALLED)\\\n`python3 -m pip install Sarvar`\\\nor\\\n`pip3 install Sarvar`\n## How does it work?\nEngine(`cmd: dict[str, EngineCommandFunction]`, `logger: Logger = Logger()`)\\\n`cmd` keyword argument: `List of all commands`\n* Structure\n  - `{\"Command\": Callable of type EngineCommandFunction}`\nEach Command function is defined by the `@Engine.engine_command decorator factory`\n* Each function gets these arguments\n    - `CommandFunction(token: Token)`\\\nExample:\n```python\n@Engine.engine_command(bigger_than=0, lesser_than=float(\"inf\"), macro_immutable=False)\ndef printContent(token: Token) :\n    token.args.append(\"Print\")\n    token.args.append(\" \".join(token.privatevars))\n```\n#### `Engine.engine_command` arguments\n```macro_immutable: bool``` -> Whether macro expansion should be allowed on command's `token.privatevar`\\\n\\\n```bigger_than: int|float``` CLI Arguments should be bigger than `number` for infinite say float(\"inf\")\\\n\\\n```lesser_than: int|float``` CLI arguments should be lesser than `number` for infinite say float(\"inf\")\n### Tokens\nEach token is consisted of:\n```\nglobalvars (dict[str, str]): Global variables accessible throughout execution\nprivatevars (list[str]): Private variables for current scope\nargs (list[str]): List of command arguments\nmacros (dict[str, str]): Defined macro replacements\ncurrent_line (int): Current line being executed\nall_lines (int): Total number of lines in program\n````\n`privatevars` is the command line arguments for the specified or detected command\\\n\\\n`args` push or append or insert a command to be handeled in the debug list\\\n\\\n`macros` list of all macros\\\n\\\n`current_line` Current line this command being executed on\\\n\\\n`all_lines` All of the lines that is in the current command's execution scope\\\n\\\n`globalvars` All of the variables defined by other commands\n### Debug list\nCommands:\n```python\n{\n    \"Warn\": self._warn_attr,\n    \"Error\": self._error_attr,\n    \"Debug\": self._debug_attr,\n    \"Print\": self._print_attr,\n    \"MakeCall\": self._make_call_attr,\n}\n```\nInsert a command or key into the `token.args` list to be handeled in the `_handle_debug_list` function\n- Structure\n  * `[\"Command-Key from commands\", \"Arguments for the specified commands\"]`\n  * Example:\n    - [\"Warn\", \"hello!\", \"Error\", \"This\"]\n    - Executes \"Warn\" function from dict with arguments - argument `\"hello!\"`\n    - Executes \"Error\" function from dict with arguments - argument `\"This\"`\n### General functions and instance setup\nTo setup an instance first import the \"Sarvar\" package\n```python\n>>> import Sarvar as sr\n>>> # Then make an instance by the following structure: Engine (cmd: dict[str, EngineCommandFunction], logger: Logger = Logger() #Optional# )\n>>> myInstance = sr.Engine({}) # Meaning no commands by default\n```\n#### Logger class\n    Logger class is a class designed for outputing \"Engine\" outputs\n    Such as 'Errors-Warnings and ...'\n    How to setup class:\n        def_debug = stdout, def_warn = stderr, def_print = stdout, def_err = stderr\n        Your output files such as stdout - stderr - ...\n        Prints using rich into specified files by specific functions\n            def log_error(self, it): rich.print(\"[red]\"+ \"ERROR:\\t\" +str(it)+\"[/red]\", file=self.error_file)\n            def log_warning(self, it): rich.print(\"[yellow]\" + \"WARNING:\\t\" +str(it)+\"[/yellow]\", file=self.warn_file)\n            def log_debug(self, it): rich.print(\"[blue]\"+ \"DEBUG:\\t\" + str(it)+\"[/blue]\", file=self.debug_file)\n            def log_print(self, it): rich.print(\"[cyan]OUTPUT:\\t\"+str(it)+\"[/cyan]\", file =self.print_file)\n\n* `add_cmd` -> Adds a new command `(Args: str, callable)`\n\n* `remove_cmd` -> Removes a command `(Args: str)`\n\n* `push_to_stack` -> Pushes a command to execution stack (`self.commands`) and adds one to the len of execution stack (`self.all_lines`) `(Args: str)`\n\n* `interpret` -> interprets the current line (`self.current_line`) `(Args: None)`\n\n* `HELPER_InterepetAll` -> interprets until the current line becomes bigger or equal than all of the lines (`self.current_line < self.all_lines`) `(Args: None)`\n\n* `set_flag` -> Sets a specific flag to the specified value `(Args: str, bool)`\n\n* `unset_flag` -> Unsets a specific flag `(like the 'not' keyword)` `(Args: str)`\n\n* `Flags` -> `[PROPERTY]` Returns the `self.readView`\n\n* `get_cmd` -> `[PROPERTY]` Returns the `self.cmd` dictionary\n\n#### Flags\nFlags for the `self.interpret` function\n* `\"_attributename_stop\"` -> Raises an error when the attributename gets called `(attributes are functions starting with '_' such as '_error_attr')`\n* `\"PRN_ShowEvents\"` -> Show events for every function with `DebugFunctionIfEnabled` decorator\n* `\"BOL_HNDLE_DBGLST\"` Handle debug list?\n* `\"SHW_OUTPUT\"` Show output `(Do not execute functions marked with ExecuteIfEnabled(\"SHW_OUTPUT\") decorator)`\n* `\"INTERP_EXEC_EVEN_IF_ERROR\"` Execute even If there is a problem with command line arguments or current_line\n* `\"INTERP_EXEC_EVEN_IF_RAISED\"` Do not Raise error If there was an error with command execution (`True = Do not raise error, False = Raise error`)\n## Links\nHomepage: https://github.com/ProgrammEverything/Sarvar \\\nIssues: https://github.com/ProgrammEverything/Sarvar/issues\n\n## License\n\n[MIT](https://choosealicense.com/licenses/mit/)\n\n\n## Authors\n\n- [@programmeverything](https://github.com/ProgrammEverything)\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A simple assembly like interpreter implementation. Good for programs which need command shortcuts or command lines for their programs. Not good in speed but good in simplicity.",
    "version": "2.0.0",
    "project_urls": {
        "documentation": "https://github.com/ProgrammEverything/Sarvar",
        "homepage": "https://github.com/ProgrammEverything/Sarvar",
        "issues": "https://github.com/ProgrammEverything/Sarvar/issues",
        "repository": "https://github.com/ProgrammEverything/Sarvar"
    },
    "split_keywords": [
        "assembly like interpreter in python",
        " python interpreter",
        " sarvar",
        " sarvar interpreter",
        " sarvar interpreter python",
        " simple interpreter for programs"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "4f645a07637d92232d2350e1d36d4fb6e592d86a82d6698c27cddcbafaeca04c",
                "md5": "4212e36d1de056fcc7b1bfd4e74440ba",
                "sha256": "61ca37b3bb5c8378e5a3d38e2a8e75807472b7de98b5bec78c7d6c3842a5542b"
            },
            "downloads": -1,
            "filename": "sarvar-2.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4212e36d1de056fcc7b1bfd4e74440ba",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 10645,
            "upload_time": "2025-02-15T22:08:07",
            "upload_time_iso_8601": "2025-02-15T22:08:07.831273Z",
            "url": "https://files.pythonhosted.org/packages/4f/64/5a07637d92232d2350e1d36d4fb6e592d86a82d6698c27cddcbafaeca04c/sarvar-2.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "194aba3a2dc7b4936eaa5992cfe2bfcef1870325c69055c3dd0e608bf580604c",
                "md5": "b12cbac46d0ad613128f0b6e320c88cd",
                "sha256": "46b809bc1ffc860c63ae6c3a73bf73969f657e16b991942d86c5c2f54ae125fb"
            },
            "downloads": -1,
            "filename": "sarvar-2.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "b12cbac46d0ad613128f0b6e320c88cd",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 8839,
            "upload_time": "2025-02-15T22:08:09",
            "upload_time_iso_8601": "2025-02-15T22:08:09.760043Z",
            "url": "https://files.pythonhosted.org/packages/19/4a/ba3a2dc7b4936eaa5992cfe2bfcef1870325c69055c3dd0e608bf580604c/sarvar-2.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-02-15 22:08:09",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ProgrammEverything",
    "github_project": "Sarvar",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "sarvar"
}
        
Elapsed time: 1.77377s