Skip to main content

simple python module for KoiLang parsing

Project description

Kola

Simple python module for KoiLang parsing.

License PyPI Python Version

Installation

From pip:

pip install KoiLang

From source code:

python setup.py build_ext --inplace
python setup.py install

What is KoiLang

KoiLang is a markup language while is easy to read for people. There is an simple example.

#hello KoiLang
I am glad to meet you!

In KoiLang, file is divided into 'command' part and 'text' part. The formation of command part is like C preprocessor directive, using '#' as starting. And text is surrounding commands.

#command "This is a command"
This is a text.

Each command can have several arguments behind the command name. Valid argument type include integer, float, literal and string.

#arg_int    1 0b101 0x6CF
#arg_float  1.0 2e-2
#arg_literal __name__
#arg_string "A string"

Here "literal" is a valid python variety name containing letter,digit, underline and not starting with digit. Usually it is same as a string.

There is another kind of arguments -- keyword arguments which formation is as this:

#kwargs key(value)

And another format:
#keyargs_list key(item0, item1)

And the third:
#kwargs_dict key(x: 11, y: 45, z: 14)

All the arguments can be put together

#draw Line 2 pos0(x: 0, y: 0) pos1(x: 16, y: 16) \
    thickness(2) color(255, 255, 255)

What can Kola module do

Kola module provides a fast way to translate KoiLang command into a python function call.

Above command #draw will convert to function call below:

draw(
    "Line", 2,
    pos0={"x": 0, "y": 0},
    pos1={"x": 16, "y": 16},
    thickness=2,
    color=[255, 255, 255]
)

Kola mudule just create a bridge from kola file to Python script. The bridge, the main class of Kola module, is KoiLang class. There is a simple example.

Example

Let's

import os
from kola import KoiLang, kola_command, kola_text


class MultiFileManager(KoiLang):
    def __init__(self) -> None:
        self._file = None
        super().__init__()
    
    def __del__(self) -> None:
        if self._file:
            self._file.close()
    
    @kola_command
    def file(self, path: str, encoding: str = "utf-8") -> None:
        if self._file:
            self._file.close()
        path_dir = os.path.dirname(path)
        if path_dir:
            os.makedirs(path_dir, exist_ok=True)
        self._file = open(path, "w", encoding=encoding)
    
    @kola_command
    def close(self) -> None:
        if self._file:
            self._file.close()
            self._file = None
    
    @kola_text
    def text(self, text: str) -> None:
        if not self._file:
            raise OSError("write texts before the file open")
        self._file.write(text)

Then make a simple kola file.

#file "hello.txt"
Hello world!

#file "test.txt"
This is a text.
#close

And input this in terminal:

python -m kola kolafile.kola -s script.py

Or directly add in script:

if __name__ = "__main__":
    FMultiFileManager().parse_file("kolafile.kola")

You will see new files in your work dir.

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

KoiLang-0.1.0b2.tar.gz (171.9 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

KoiLang-0.1.0b2-cp38-cp38-win_amd64.whl (86.4 kB view details)

Uploaded CPython 3.8Windows x86-64

KoiLang-0.1.0b2-cp36-cp36m-win_amd64.whl (95.7 kB view details)

Uploaded CPython 3.6mWindows x86-64

File details

Details for the file KoiLang-0.1.0b2.tar.gz.

File metadata

  • Download URL: KoiLang-0.1.0b2.tar.gz
  • Upload date:
  • Size: 171.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.12

File hashes

Hashes for KoiLang-0.1.0b2.tar.gz
Algorithm Hash digest
SHA256 fdd3e37a8a0c8117744da5f7a087f24e857252950eaeeff923e92303def0ea46
MD5 e8ca923a9849d19c22cd6a6513236ea2
BLAKE2b-256 5f74c3d095e8e377969715ebee4dd1d2a57211536ec7a1bcc69930bfa2c4885c

See more details on using hashes here.

File details

Details for the file KoiLang-0.1.0b2-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: KoiLang-0.1.0b2-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 86.4 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.12

File hashes

Hashes for KoiLang-0.1.0b2-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 2749def8b57d10b91b916a24fa249ad1f0c7c1f42faadc39e9e7bcd7373d820c
MD5 02b9f7794297b06cbc41ca39c262b10a
BLAKE2b-256 637144b28112c02ea0c21e0e49dfb61062a72c8de321dfd37dd89d9d34f254eb

See more details on using hashes here.

File details

Details for the file KoiLang-0.1.0b2-cp36-cp36m-win_amd64.whl.

File metadata

  • Download URL: KoiLang-0.1.0b2-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 95.7 kB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.12

File hashes

Hashes for KoiLang-0.1.0b2-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 c9cae1aa3bc15363ea1dea9c846eb437a173d2f6ebbc2aff65f48b272a45b2d6
MD5 d19e87cd48610886b3810e46f6cc3bd5
BLAKE2b-256 207d7f38266d41f3b662e784fb63b90bde7e48acc0ea8e397f5503ab6f637926

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page