Salomos is a Python package that provides a domain-specific language (DSL) processor for executing commands based on sentences stored in a SQLite database.
Project description
Salomos
Salomos is a Python package that provides utilities for processing domain-specific languages (DSLs) and managing associated data.
Installation
To install Salomos, simply run:
pip install salomos
Key Components
DBManager
The DBManager
class (db_manager.py
) handles database operations for the Salomos package. It provides methods to:
- Initialize the database
- Load sentences and objects from the database
- Close the database connection
DSLProcessor
The DSLProcessor
class (dsl_processor.py
) is responsible for processing DSL sentences. It offers functionality to:
- Import modules and resolve class names
- Find matching elements based on a name
- Process a DSL sentence and execute corresponding actions
- Perform operations like print, add, concatenate
Usage Example
Here's a basic example of how to use the Salomos package:
from salomos.db_manager import DBManager
from salomos.dsl_processor import DSLProcessor
from dotenv import load_dotenv
import os
load_dotenv()
# Get the logger level from environment variable
LOGGER_LEVEL = os.getenv("LOGGER_LEVEL", "INFO")
# Initialize the database manager
db = DBManager("path/to/database.db")
db.init_database()
# Create a DSL processor instance
processor = DSLProcessor(db)
# Load a DSL sentence and objects from the database
sentence = db.load_sentence()
objects = db.load_objects()
# Process the DSL sentence
result = processor.process_sentence(sentence, objects)
# Print the result
processor.print(result)
# Close the database connection
db.close()
This example demonstrates the typical workflow of using Salomos:
-
Load environment variables from a
.env
file usingload_dotenv()
. -
Get the logger level from the
LOGGER_LEVEL
environment variable, defaulting to "INFO" if not set. -
Initialize a
DBManager
with the path to your database file and callinit_database()
. -
Create a
DSLProcessor
instance, passing it the database manager. -
Load a DSL sentence and any associated objects from the database using the
load_sentence()
andload_objects()
methods of the database manager. -
Process the loaded sentence using the
process_sentence()
method of the DSL processor, passing the sentence and objects. This returns the result of executing the sentence. -
Use the
print()
method of the DSL processor to display the result. -
Close the database connection when finished using the
close()
method of the database manager.
Running the Example Script
The salomos.py
script provides an example of how to use the Salomos package. It demonstrates:
- Creating instances of
DBManager
andDSLProcessor
- Manually adding example functions and modules to the
imported_elements
of the processor - Populating the database with test data (DSL sentences and objects)
- Running the processor to execute the DSL sentences
- Handling keyboard interrupts and closing the database connection
To run the example script from the command line:
-
Ensure you have installed the Salomos package and its dependencies
-
Open a terminal or command prompt
-
Navigate to the directory containing
salomos.py
-
Run the script using the command:
python salomos.py
Optionally, you can provide the path to a custom database file as a command-line argument:
python salomos.py path/to/custom_database.db
If no database file is specified, it will default to "dsl_database.db" in the current directory.
The script will process the test DSL sentences from the specified database and print the results. You can modify the test data or add your own DSL sentences and objects to experiment with the package.
Press Ctrl+C
to interrupt the script and exit.
Example DSL Sentences and Executed Functions/Methods/Classes
The salomos.py
script populates the database with some test DSL sentences. Here's a table showing the example sentences and the corresponding functions, methods, or classes that are executed:
DSL Sentence | Executed Function/Method/Class |
---|---|
print Hello World | DSLProcessor.print("Hello", "World") |
add 5 10 15 | DSLProcessor.add(5, 10, 15) |
Example Module greet John Doe | ExampleModule.greet("John", "Doe") |
Example Module Math Operations multiply 2 3 4 | ExampleModule.MathOperations.multiply(2, 3, 4) |
example function 10 20 | example_function(10, 20) |
concatenate Welcome to the DSL world | DSLProcessor.concatenate("Welcome", "to", "the", "DSL", "world") |
These example sentences demonstrate how the DSL processor interprets and executes different types of commands, including standalone functions, class methods, and module functions.
Contributing
Contributions are welcome! Please see the contributing guidelines for more details.
License
This project is licensed under the MIT License.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file salomos-0.2.2.tar.gz
.
File metadata
- Download URL: salomos-0.2.2.tar.gz
- Upload date:
- Size: 12.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6b86ff59031c62d74fc5c41c57be1776fbdb0c31239c6558ff377f865630e040 |
|
MD5 | 80cf3496dbca1f26ebcdb71f4d8513b6 |
|
BLAKE2b-256 | 6226bceb91571db59ea6e2c514b20a1d662becaa3e162f507d2da58f19637960 |
File details
Details for the file salomos-0.2.2-py3-none-any.whl
.
File metadata
- Download URL: salomos-0.2.2-py3-none-any.whl
- Upload date:
- Size: 11.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dc28782f2af8236a16aa92be3253e27c21da78e9a347a31b56f788ded6a62073 |
|
MD5 | 81c29d357c8259b0a5a1685eaadc741d |
|
BLAKE2b-256 | 31c97eaee183aa763ba787d2b043b4bf6b2be28dde55e63e8f080178441a4f2b |