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]
)

Well, Kola do not know the exact implementation of a command, so a command set is needed to provide. Just create a subclass of KoiLang and use decorator @kola_command on the command functions. Here is a fast example script.

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.0b1.tar.gz (173.5 kB view details)

Uploaded Source

Built Distributions

KoiLang-0.1.0b1-cp38-cp38-win_amd64.whl (85.1 kB view details)

Uploaded CPython 3.8 Windows x86-64

KoiLang-0.1.0b1-cp36-cp36m-win_amd64.whl (94.6 kB view details)

Uploaded CPython 3.6m Windows x86-64

File details

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

File metadata

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

File hashes

Hashes for KoiLang-0.1.0b1.tar.gz
Algorithm Hash digest
SHA256 c1f609e6efe48c89a6f1512b1184c0ec8c105b49fe1c05425608e15c7284c6a1
MD5 51b856d2392a675388f13f329b70cb92
BLAKE2b-256 6f07d2eda8f994f97ea6956aa9e9a09eebd20a6ff942003821d1b25d51add9cf

See more details on using hashes here.

File details

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

File metadata

  • Download URL: KoiLang-0.1.0b1-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 85.1 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.0b1-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 0c93608d82fd8c08ae212eeaffed5a96693144d823e11c0e73b821788785812f
MD5 5cb9e998932de694bb533ff255f68018
BLAKE2b-256 d0caf4de4e7edb8ab3729a0829cf1c34c6d0c8609508bb7e81ae91dbda341ba2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: KoiLang-0.1.0b1-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 94.6 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.0b1-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 233037895b1dc40deb0c13600671cd0fe699845a740e4ca958f6a4f4cbcbc3df
MD5 98ac6cfd96b24f3a4aa92c05db7cec27
BLAKE2b-256 db51f7acaef2dc5372ede8c81c21b83e8175e046ced08cc7935efe8e310c31f5

See more details on using hashes here.

Supported by

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