-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bugs in setup.py. Add main runner.
- Loading branch information
Showing
9 changed files
with
115 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
from argparse import ArgumentParser | ||
import sys | ||
from typing import Any, Callable, Dict, List, Optional, Tuple, Union | ||
from types import MethodType | ||
from .lexer import BaseLexer, StringLexer, FileLexer | ||
from .parser import Parser | ||
|
||
|
||
class KoiLangCommand(object): | ||
__slots__ = ["__name__", "__func__"] | ||
|
||
def __init__(self, name: str, func: Callable) -> None: | ||
self.__name__ = name | ||
self.__func__ = func | ||
|
||
def __get__(self, instance: Any, owner: type) -> Callable: | ||
return self.__func__.__get__(instance, owner) | ||
|
||
def __call__(self, *args: Any, **kwds: Any) -> Any: | ||
return self.__func__(*args, **kwds) | ||
|
||
|
||
class KoiLangMeta(type): | ||
""" | ||
Metaclass for KoiLang class | ||
""" | ||
__command_field__: List[KoiLangCommand] | ||
|
||
def __new__(cls, name: str, base: Tuple[type, ...], attr: Dict[str, Any]): | ||
__command_field__ = [i for i in attr.values() if isinstance(i, KoiLangCommand)] | ||
attr["__command_field__"] = __command_field__ | ||
|
||
return super().__new__(cls, name, base, attr) | ||
|
||
def get_command_set(self, instance: Any) -> Dict[str, MethodType]: | ||
return {i.__name__: MethodType(i.__func__, instance) for i in self.__command_field__} | ||
|
||
|
||
class KoiLang(metaclass=KoiLangMeta): | ||
""" | ||
Main class for KoiLang parsing. | ||
""" | ||
__slots__ = ["command_set"] | ||
|
||
def __init__(self) -> None: | ||
self.command_set = self.__class__.get_command_set(self) | ||
|
||
def __getitem__(self, key: str) -> Callable: | ||
return self.command_set[key] | ||
|
||
def parse(self, text: Optional[str] = None) -> None: | ||
if text is None: | ||
lexer = BaseLexer() | ||
else: | ||
lexer = StringLexer(text) | ||
Parser(lexer, self.command_set).exec_() | ||
|
||
def parse_file(self, path: str) -> None: | ||
Parser(FileLexer(path), self.command_set).exec_() | ||
|
||
|
||
def kola_command(func: Callable) -> KoiLangCommand: | ||
return KoiLangCommand(func.__name__, func) | ||
|
||
def kola_text(func: Callable) -> KoiLangCommand: | ||
return KoiLangCommand("@text", func) | ||
|
||
def kola_number(func: Callable) -> KoiLangCommand: | ||
return KoiLangCommand("@number", func) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
__version__ = "0.1.0a2" | ||
version_info = (0, 1, 0, "alpha", 2) | ||
__version__ = "0.1.0b0" | ||
version_info = (0, 1, 0, "beta", 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,7 @@ | |
_home = os.path.dirname(__file__) | ||
|
||
extensions = [ | ||
Extension("kola.lexer", ["kola/lexer" + FILE_SUFFIX]), | ||
Extension("kola.lexer", ["kola/lexer" + FILE_SUFFIX, "kola/lex.yy.c"]), | ||
Extension("kola.parser", ["kola/parser" + FILE_SUFFIX]) | ||
] | ||
if USE_CYTHON: | ||
|
@@ -59,6 +59,7 @@ | |
maintainer_email="[email protected]", | ||
license="Apache 2.0", | ||
|
||
url="https://github.com/Ovizro/Kola", | ||
packages=["kola"], | ||
python_requires=">=3.6", | ||
package_data={'':["*.pyi", "*.pxd", "*.h"]}, | ||
|