├── _config.yml ├── setup.cfg ├── .gitignore ├── .github ├── FUNDING.yml └── workflows │ ├── python-publish.yml │ └── python-package.yml ├── tests ├── __init__.py ├── testscripts │ ├── factorial.my │ └── quadratic_roots.my └── tests.py ├── mynathon ├── __init__.py ├── __main__.py └── mynathon.py ├── bin └── mynathon ├── mynathon.py ├── LICENSE ├── setup.py └── README.md /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-dinky -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [install] 2 | install-scripts=/usr/sbin 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | __pycache__ 3 | .pytest_cache 4 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: yalishanda42 2 | ko_fi: yalishanda42 3 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- 1 | """Mynathon tests.""" 2 | 3 | __all__ = ["tests"] 4 | -------------------------------------------------------------------------------- /mynathon/__init__.py: -------------------------------------------------------------------------------- 1 | """Mynathon language parser.""" 2 | 3 | from .mynathon import MynathonParser 4 | -------------------------------------------------------------------------------- /bin/mynathon: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from mynathon import __main__ 4 | __main__.entry_point() 5 | -------------------------------------------------------------------------------- /mynathon.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | """In-repo entry point.""" 4 | 5 | from mynathon import __main__ 6 | __main__.entry_point() 7 | -------------------------------------------------------------------------------- /mynathon/__main__.py: -------------------------------------------------------------------------------- 1 | """Entry point for the parser executable.""" 2 | 3 | import sys 4 | import pathlib 5 | from .mynathon import MynathonParser 6 | 7 | 8 | def entry_point(): 9 | if len(sys.argv) < 2: 10 | print("USAGE:\n\t$ {0} file_name".format(sys.argv[0])) 11 | exit(1) 12 | 13 | filepath = pathlib.Path(sys.argv[-1]).as_posix() 14 | MynathonParser.execute_script_from_file(filepath) 15 | 16 | 17 | if __name__ == "__main__": 18 | entry_point() 19 | -------------------------------------------------------------------------------- /tests/testscripts/factorial.my: -------------------------------------------------------------------------------- 1 | нека факториел(число): 2 | ако майна число < 0: 3 | маняк искаш да ме направиш ValueError("Е не може с отрицателно число") 4 | ако пък число == 0 или число == 1: 5 | готоо майна 1 6 | иначе: 7 | готоо майна факториел(число - 1) * число 8 | 9 | print("Факториелът на 3 е {0}, а на нула е {1}".format(факториел(3), факториел(0))) 10 | 11 | пробвай майна: 12 | променлива = факториел(-1) 13 | яба гръмна ми Exception като нещо: 14 | print(нещо) 15 | кат цяло: 16 | print("Готов си") 17 | -------------------------------------------------------------------------------- /tests/testscripts/quadratic_roots.my: -------------------------------------------------------------------------------- 1 | от math дай ми sqrt като корен 2 | 3 | нека корените_на_квадратно_уравнение(a, b, c): 4 | ако майна a == 0: 5 | маняк искаш да ме направиш ValueError("Уравнението не е квадратно!") 6 | 7 | дискриминантата = b*b - 4*a*c 8 | корен_от_дискриминантата = корен(дискриминантата) ако майна дискриминантата >= 0 иначе корен(-дискриминантата)*1j 9 | 10 | корен1 = (-b - корен_от_дискриминантата) / (2 * a) 11 | корен2 = (-b + корен_от_дискриминантата) / (2 * a) 12 | 13 | готоо майна корен1, корен2 14 | 15 | кор1 = корените_на_квадратно_уравнение(1, -3, 2) 16 | print("x^2 - 3x + 2 = 0 <=> x1 == {0}; x2 == {1}".format(*кор1)) 17 | 18 | кор2 = корените_на_квадратно_уравнение(1, 2, 5) 19 | print("x^2 + 2x + 5 = 0 <=> x1 == {0}; x2 == {1}".format(*кор2)) 20 | -------------------------------------------------------------------------------- /.github/workflows/python-publish.yml: -------------------------------------------------------------------------------- 1 | # This workflows will upload a Python Package using Twine when a release is created 2 | # For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries 3 | 4 | name: Upload Python Package 5 | 6 | on: 7 | release: 8 | types: [created] 9 | 10 | jobs: 11 | deploy: 12 | 13 | runs-on: ubuntu-latest 14 | 15 | steps: 16 | - uses: actions/checkout@v2 17 | - name: Set up Python 18 | uses: actions/setup-python@v2 19 | with: 20 | python-version: '3.x' 21 | - name: Install dependencies 22 | run: | 23 | python3 -m venv myenv 24 | . myenv/bin/activate 25 | python3 -m pip install --upgrade pip 26 | pip3 install setuptools wheel twine 27 | - name: Build and publish 28 | env: 29 | TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} 30 | TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} 31 | run: | 32 | . myenv/bin/activate 33 | python3 setup.py sdist bdist_wheel 34 | twine upload dist/* 35 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Alexander Ignatov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | """Setup script.""" 2 | 3 | import pathlib 4 | from setuptools import setup, find_packages 5 | 6 | HERE = pathlib.Path(__file__).parent 7 | README = (HERE / "README.md").read_text() 8 | 9 | REPO_URL = 'https://github.com/allexks/mynathon' 10 | VERSION = '0.1.2' 11 | 12 | setup( 13 | name='mynathon', 14 | packages=find_packages(exclude=("tests",)), 15 | version=VERSION, 16 | license='MIT', 17 | description='Mynathon - Езикът за майни и маняци.', 18 | long_description=README, 19 | long_description_content_type="text/markdown", 20 | author='Alexander Ignatov', 21 | author_email='yalishanda@abv.bg', 22 | url=REPO_URL, 23 | download_url='{0}/archive/{1}.tar.gz'.format(REPO_URL, VERSION), 24 | scripts=["bin/mynathon"], 25 | entry_points={ 26 | "entry_points": [ 27 | "mynathon = mynathon:entry_point" 28 | ], 29 | }, 30 | keywords=[ 31 | 'maina', 32 | 'manqk', 33 | 'bg', 34 | 'stoyan kolev', 35 | 'jargon', 36 | ], 37 | install_requires=[], 38 | classifiers=[ 39 | 'Intended Audience :: Developers', 40 | 'Topic :: Software Development :: Build Tools', 41 | 'License :: OSI Approved :: MIT License', 42 | 'Programming Language :: Python :: 3', 43 | 'Programming Language :: Python :: 3.4', 44 | 'Programming Language :: Python :: 3.5', 45 | 'Programming Language :: Python :: 3.6', 46 | 'Programming Language :: Python :: 3.7', 47 | 'Programming Language :: Python :: 3.8', 48 | ], 49 | ) 50 | -------------------------------------------------------------------------------- /.github/workflows/python-package.yml: -------------------------------------------------------------------------------- 1 | # This workflow will install Python dependencies, run tests and lint with a variety of Python versions 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions 3 | 4 | name: Python package 5 | 6 | on: 7 | push: 8 | branches: [ master ] 9 | pull_request: 10 | branches: [ master ] 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | strategy: 17 | matrix: 18 | python-version: [3.7, 3.8, 3.9, "3.10"] 19 | 20 | steps: 21 | - uses: actions/checkout@v2 22 | - name: Set up Python ${{ matrix.python-version }} 23 | uses: actions/setup-python@v2 24 | with: 25 | python-version: ${{ matrix.python-version }} 26 | - name: Install dependencies 27 | run: | 28 | python3 -m venv myenv 29 | . myenv/bin/activate 30 | python3 -m pip install --upgrade pip 31 | pip3 install flake8 pytest 32 | if [ -f requirements.txt ]; then pip install -r requirements.txt; fi 33 | - name: Lint with flake8 34 | run: | 35 | . myenv/bin/activate 36 | # stop the build if there are Python syntax errors or undefined names 37 | flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --exclude .git,__pycache__,build,dis,myenv,tests 38 | # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide 39 | flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics --exclude .git,__pycache__,build,dis,myenv,tests 40 | - name: Test with pytest 41 | run: | 42 | . myenv/bin/activate 43 | pytest tests/tests.py 44 | -------------------------------------------------------------------------------- /tests/tests.py: -------------------------------------------------------------------------------- 1 | #!python3 2 | 3 | """Mynathon tests.""" 4 | 5 | from mynathon import MynathonParser 6 | import unittest 7 | import pathlib 8 | 9 | 10 | class TestMynathonParser(unittest.TestCase): 11 | """Class defining test cases for the mynathon parser.""" 12 | 13 | def _test_script_from_file(self, testcase, expected_output): 14 | directory = pathlib.Path(__file__).parent 15 | filepath = directory / "testscripts/{0}.my".format(testcase) 16 | filepath_str = filepath.as_posix() 17 | output = MynathonParser.execute_script_from_file(filepath_str, True) 18 | self.assertEqual(expected_output, output) 19 | 20 | def test_factorial(self): 21 | """Run the factorial.my test case.""" 22 | expected_output = "Факториелът на 3 е 6, а на нула е 1\n"\ 23 | "Е не може с отрицателно число\n"\ 24 | "Готов си\n" 25 | 26 | self._test_script_from_file("factorial", expected_output) 27 | 28 | def test_quadratic_roots(self): 29 | """Run the quadratic_roots.my test case.""" 30 | expected_output = "x^2 - 3x + 2 = 0 <=> x1 == 1.0; x2 == 2.0\n"\ 31 | "x^2 + 2x + 5 = 0 <=> x1 == (-1-2j); x2 == (-1+2j)\n" 32 | 33 | self._test_script_from_file("quadratic_roots", expected_output) 34 | 35 | def test_keywords_are_valid(self): 36 | """Test that the mynathon keywords are not ambiguous.""" 37 | keywords = MynathonParser.KEYWORDS.keys() 38 | 39 | for keyword in keywords: 40 | for keyword2 in filter(lambda k: k != keyword, keywords): 41 | if keyword in keyword2.split(): 42 | self.fail("Keyword '{0}' is contained in '{1}'; " 43 | "this may cause unpredictable behaviour." 44 | .format(keyword, keyword2)) 45 | 46 | self.assertTrue(True) 47 | 48 | 49 | if __name__ == '__main__': 50 | unittest.main() 51 | -------------------------------------------------------------------------------- /mynathon/mynathon.py: -------------------------------------------------------------------------------- 1 | #!python3 2 | 3 | """Mynathon. 4 | 5 | The universal language of mainas and manqks. 6 | 7 | (c) 2020 AJ & MC Ton4ou 8 | """ 9 | 10 | import os 11 | from io import BytesIO 12 | from tokenize import tokenize, untokenize, NAME 13 | 14 | 15 | class MynathonParser: 16 | """The class that is capable of converting mynathon to python.""" 17 | 18 | KEYWORDS = { 19 | "харабия": "True", 20 | "бомбок": "False", 21 | "и": "and", 22 | "или": "or", 23 | "не": "not", 24 | "е": "is", 25 | "нищо": "None", 26 | "ако майна": "if", 27 | "ако пък": "elif", 28 | "иначе": "else", 29 | "начи за": "for", 30 | "пробягващо": "in", 31 | "начи майна": "while", 32 | "скандал": "break", 33 | "дайму още": "continue", 34 | "маняк искаш да ме направиш": "raise", 35 | "маняк ти иеш ли са": "assert", 36 | "пробвай майна": "try", 37 | "яба гръмна ми": "except", 38 | "кат цяло": "finally", 39 | "пас": "pass", 40 | "клас": "class", 41 | "нека": "def", 42 | "готоо майна": "return", 43 | "метни му": "yield", 44 | "гърция": "lambda", 45 | "от": "from", 46 | "дай ми": "import", 47 | "като": "as", 48 | "праскай": "with", 49 | "мани го тоа бе майна": "del", 50 | "софия": "nonlocal", 51 | "кичука": "global", 52 | "изчакай": "await", 53 | "многонишково": "async", 54 | } 55 | 56 | TEMPFILE = "/tmp/mynathontempfile" 57 | 58 | @staticmethod 59 | def to_python_string(contents): 60 | """Transform a mynathon code string into a python code string.""" 61 | keyword_dict = MynathonParser.KEYWORDS 62 | keywords = keyword_dict.keys() 63 | result = [] 64 | token_stack = [] 65 | tokens_gen = tokenize(BytesIO(contents.encode('utf-8')).readline) 66 | for toktype, tokval, _, _, _ in tokens_gen: 67 | if toktype != NAME: # all keywords are names so ignore other types 68 | result.append((toktype, tokval)) 69 | continue 70 | 71 | # Mynathon keywords can consist of more than one 'word' 72 | # so use a stack to persist words of possible detected keywords 73 | # between the generator iterations 74 | token_stack.append((toktype, tokval)) 75 | stack_stmt = " ".join(map(lambda t: t[1], token_stack)) 76 | 77 | if tokval in keywords: 78 | result.append((NAME, keyword_dict[tokval])) 79 | token_stack = [] 80 | elif stack_stmt in keywords: 81 | result.append((NAME, keyword_dict[stack_stmt])) 82 | token_stack = [] 83 | elif len(list(filter(lambda k: stack_stmt in k, keywords))) == 0: 84 | result.extend(token_stack) 85 | token_stack = [] 86 | 87 | return untokenize(result).decode('utf-8') 88 | 89 | @staticmethod 90 | def execute_script_from_file(filename, return_output=False): 91 | """Parse a mynathon script from a file and execute it.""" 92 | with open(filename, "r") as fread: 93 | contents = fread.read() 94 | 95 | contents = MynathonParser.to_python_string(contents) 96 | 97 | with open(MynathonParser.TEMPFILE, "w+") as fwrite: 98 | fwrite.write(contents) 99 | 100 | command = "cat {0} | python3".format(MynathonParser.TEMPFILE) 101 | 102 | result = None 103 | if return_output: 104 | result = os.popen(command).read() 105 | else: 106 | os.system(command) 107 | 108 | os.remove(MynathonParser.TEMPFILE) 109 | return result 110 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Mynathon - Универсалният програмен език за майни и маняци. 2 | 3 | ![Build](https://github.com/allexks/mython/workflows/Python%20package/badge.svg) 4 | [![Downloads](https://static.pepy.tech/personalized-badge/mynathon?period=total&units=international_system&left_color=black&right_color=blue&left_text=%D0%A2%D0%B5%D0%B3%D0%BB%D0%B5%D0%BD%D0%B8%D1%8F)](https://pepy.tech/project/mynathon) 5 | 6 | ![Моля](https://media.tenor.com/images/139208d8296e1e01a6e3fc41a14d624d/tenor.gif) 7 | 8 | ## Ключови думи 9 | * `True` => `харабия` 10 | * `False` => `бомбок` 11 | * `and` => `и` 12 | * `or` => `или` 13 | * `not` => `не` 14 | * `is` => `е` 15 | * `None` => `нищо` 16 | * `if` => `ако майна` 17 | * `elif` => `ако пък` 18 | * `else` => `иначе` 19 | * `for` => `начи за` 20 | * `in` => `пробягващо` 21 | * `while` => `начи майна` 22 | * `break` => `скандал` 23 | * `continue` => `дайму още` 24 | * `raise` => `маняк искаш да ме направиш` 25 | * `assert` => `маняк ти иеш ли са` 26 | * `try` => `пробвай майна` 27 | * `except` => `яба гръмна ми` 28 | * `finally` => `кат цяло` 29 | * `pass` => `пас` 30 | * `class` => `клас` 31 | * `def` => `нека` 32 | * `return` => `готоо майна` 33 | * `yield` => `метни му` 34 | * `lambda` => `гърция` 35 | * `from` => `от` 36 | * `import` => `дай ми` 37 | * `as` => `като` 38 | * `with` => `праскай` 39 | * `del` => `мани го тоа бе майна` 40 | * `nonlocal` => `софия` 41 | * `global` => `кичука` 42 | * `await` => `изчакай` 43 | * `async` => `многонишково` 44 | 45 | ## Инсталация 46 | 47 | `pip install mynathon` 48 | 49 | ## Инструкции 50 | 51 | Пиши на майнатън все едно си пишеш на питоня, обаче като се наложи да ползваш някоя ключова дума я замени така както горе е показано. Можеш да си ползваш кирилица даже като си кръщаваш нещата, няма проблеми. 52 | 53 | ## Употреба 54 | 55 | ### Изпълнение на файл с майнатън код 56 | 57 | `mynathon {име_на_файла}` 58 | 59 | ### Използване на майнатън парсъра в питонски код 60 | 61 | ```python 62 | from mynathon import MynathonParser 63 | # Повече информация за методите е достъпна в mynathon.py 64 | ``` 65 | 66 | ## Примери 67 | ### Пример 1 68 | ``` mynathon 69 | нека факториел(число): 70 | ако майна число < 0: 71 | маняк искаш да ме направиш ValueError("Е не може с отрицателно число") 72 | ако пък число == 0 или число == 1: 73 | готоо майна 1 74 | иначе: 75 | готоо майна факториел(число - 1) * число 76 | 77 | print(f"Факториелът на 3 е {факториел(3)}, а на нула е {факториел(0)}") 78 | 79 | пробвай майна: 80 | променлива = факториел(-1) 81 | яба гръмна ми Exception като нещо: 82 | print(нещо) 83 | кат цяло: 84 | print("Готов си") 85 | ``` 86 | Кодът е еквивалентен на: 87 | ``` python 88 | def factorial(number): 89 | if number < 0: 90 | raise ValueError("Е не може с отрицателно число") 91 | elif number == 0 or number == 1: 92 | return 1 93 | else: 94 | return factorial(number - 1) * number 95 | 96 | print(f"Факториелът на 3 е {factorial(3)}, а на нула е {factorial(0)}") 97 | 98 | try: 99 | var = factorial(-1) 100 | except Exception e: 101 | print(e) 102 | finally: 103 | print("Готов си") 104 | ``` 105 | ### Пример 2 106 | ``` mynathon 107 | от math дай ми sqrt като корен 108 | 109 | нека корените_на_квадратно_уравнение(a, b, c): 110 | ако майна a == 0: 111 | маняк искаш да ме направиш ValueError("Уравнението не е квадратно!") 112 | 113 | дискриминантата = b*b - 4*a*c 114 | корен_от_дискриминантата = корен(дискриминантата) ако майна дискриминантата >= 0 иначе корен(-дискриминантата)*1j 115 | 116 | корен1 = (-b - корен_от_дискриминантата) / (2 * a) 117 | корен2 = (-b + корен_от_дискриминантата) / (2 * a) 118 | 119 | готоо майна корен1, корен2 120 | 121 | кор1 = корените_на_квадратно_уравнение(1, -3, 2) 122 | print("x^2 - 3x + 2 = 0 <=> x1 == {0}; x2 == {1}".format(*кор1)) 123 | 124 | кор2 = корените_на_квадратно_уравнение(1, 2, 5) 125 | print("x^2 + 2x + 5 = 0 <=> x1 == {0}; x2 == {1}".format(*кор2)) 126 | ``` 127 | Кодът е еквивалентен на: 128 | ``` python 129 | from math import sqrt as root 130 | 131 | def quadratic_roots(a, b, c): 132 | if a == 0: 133 | raise ValueError("Уравнението не е квадратно!") 134 | 135 | discriminant = b*b = 4*a*c 136 | sqrt_discriminant = root(discriminant) if discriminant >= 0 else root(-discriminant)*1j 137 | 138 | root1 = (-b - sqrt_discriminant) / (2 * a) 139 | root2 = (-b + sqrt_discriminant) / (2 * a) 140 | 141 | return root1, root2 142 | 143 | roots1 = quadratic_roots(1, -3, 2) 144 | print("x^2 - 3x + 2 = 0 <=> x1 == {0}; x2 == {1}".format(*roots1)) 145 | 146 | roots2 = quadratic_roots(1, 2, 5) 147 | print("x^2 + 2x + 5 = 0 <=> x1 == {0}; x2 == {1}".format(*roots2)) 148 | ``` 149 | 150 | ## Нещо не бачка? 151 | 152 | Отвори ново issue и си излей душата. 153 | 154 | Ако отвориш пък pull request с готово решение/добавка/предложение, ще се псуваме по-малко. 155 | 156 | ## Лиценз 157 | 158 | [От скъпото](LICENSE) 159 | --------------------------------------------------------------------------------