Skip to content

Commit 800b93d

Browse files
authored
Merge branch 'main' into irish
2 parents 9c4ad07 + 8da9fe7 commit 800b93d

10 files changed

Lines changed: 109 additions & 12 deletions

File tree

README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<div align="center">
77

8-
📖 [Documentation](https://universalpython.github.io/) | 🎯 [Examples](./urdupython/samples/) | 📄 [Research Paper](./paper/conference_101719.pdf) | 🔥 [Live demo (online)](https://universalpython.github.io/)
8+
📖 [Documentation](https://universalpython.github.io/) | 🎯 [Examples](./test/samples/) | 📄 [Research Paper](./static/paper/conference_101719.pdf) | 🔥 [Live demo (online)](https://universalpython.github.io/)
99

1010
**UniversalPython** is a transpiler that lets you write Python code in your own language. It translates your code into Python while keeping the syntax familiar.
1111

@@ -53,6 +53,25 @@ You can also try out UniversalPython in our [live online demo](https://universal
5353
### UniversalPython in Jupyter
5454
Install our Jupyter Kernel to easily use UniversalPython in Jupyter Notebook or Jupyter Lab. Instructions are here: https://github.com/UniversalPython/universalpython_kernel
5555

56+
### Want to add your language? Or edit one?
57+
Follow the documentation [here](./universalpython/languages/README.md) to add a new human language, or edit an existing one.
58+
59+
### Build and release
60+
Install packaging dependencies:
61+
```bash
62+
pip install -U packaging
63+
```
64+
65+
To build:
66+
```bash
67+
python setup.py sdist bdist_wheel
68+
```
69+
70+
To release on PyPI:
71+
```bash
72+
twine upload --repository testpypi dist/* --verbose
73+
```
74+
5675
### Learn More
5776

5877
Check out the [documentation](https://universalpython.github.io/docs/intro).

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
setup(
1717
name='universalpython',
18-
version='0.1.0',
18+
version='0.1.3',
1919
author='Saad Bazaz',
2020
author_email='saadbazaz@hotmail.com',
2121
url='https://github.com/UniversalPython/UniversalPython',

test/samples/fr/hello.fr.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
imprimer("hello world")

test/samples/ga/loop.ga.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# language:ga
2+
rudaí = [
3+
'💻',
4+
'📷',
5+
'🧸'
6+
]
7+
8+
ag_gach rud sa rudaí:
9+
priontáil(rud)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
## Adding a new language
2+
3+
- Simply make a new folder here with the **two-letter** language code of your language.
4+
For example, German is `de`, Korean is `ko`. You can find yours [here](https://www.iban.com/country-codes).
5+
6+
Make sure it's in lowercase!
7+
8+
- In that folder, add two files:
9+
- An empty `__init__.py` (this makes it packageable with the rest of the languages). You don't need to add anything inside!
10+
- A `default.yaml` file which contains the mappings of the language. You can take [this one](./de/default.yaml) as a base template.
11+
12+
## Editing an existing language
13+
14+
Simply edit the `default.yaml` of your preferred language. We currently don't have versioning or automated-human-testing involved, so it's more of an honor system.

universalpython/languages/de/default.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ reserved:
2020
"8" : "8"
2121
"9" : "9"
2222
"0" : "0"
23-
"drucken" : "print"
23+
"ausgeben" : "print"
2424
"sonstwenn" : "elif"
2525
"wenn" : "if"
2626
"sonst" : "else"
@@ -30,22 +30,22 @@ reserved:
3030
"eingabe" : "input"
3131
"abbrechen" : "break"
3232
"weiter" : "continue"
33-
"nichts" : "pass"
33+
"überspringen": "pass"
3434
"wahr" : "True"
3535
"falsch" : "False"
3636
"ist" : "is"
3737
"klasse" : "class"
3838
"funktion" : "def"
3939
"__anfang__" : "__init__"
4040
"selbst" : "self"
41-
"zurück" : "return"
41+
"zurückgeben" : "return"
4242
"zeichenkette": "string"
4343
"str" : "str"
44-
"hinzufügen" : "append"
44+
"anhängen" : "append"
4545
"entfernen" : "pop"
4646
"und" : "and"
4747
"oder" : "or"
4848
"alle" : "all"
49-
"irgendwas" : "any"
50-
"nichts_wert" : "None"
51-
"zahl" : "int"
49+
"irgendein" : "any"
50+
"kein_wert" : "None"
51+
"ganzzahl" : "int"

universalpython/languages/ko/__init__.py

Whitespace-only changes.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
letters:
2+
start : ""
3+
end : ""
4+
extra : ""
5+
6+
numbers:
7+
start : "0"
8+
end : "9"
9+
10+
reserved:
11+
"." : "."
12+
"," : ","
13+
"1" : "1"
14+
"2" : "2"
15+
"3" : "3"
16+
"4" : "4"
17+
"5" : "5"
18+
"6" : "6"
19+
"7" : "7"
20+
"8" : "8"
21+
"9" : "9"
22+
"0" : "0"
23+
"출력" : "print"
24+
"아니면만약" : "elif"
25+
"만약" : "if"
26+
"그렇지않으면" : "else"
27+
"동안" : "while"
28+
"각각" : "for"
29+
"안에" : "in"
30+
"입력" : "input"
31+
"중단" : "break"
32+
"계속" : "continue"
33+
"건너뛰기": "pass"
34+
"" : "True"
35+
"거짓" : "False"
36+
"이다" : "is"
37+
"클래스" : "class"
38+
"함수" : "def"
39+
"__초기화__" : "__init__"
40+
"자기자신" : "self"
41+
"반환" : "return"
42+
"문자열모듈": "string"
43+
"문자열" : "str"
44+
"추가" : "append"
45+
"제거" : "pop"
46+
"그리고" : "and"
47+
"또는" : "or"
48+
"모두" : "all"
49+
"어떤" : "any"
50+
"값없음" : "None"
51+
"정수" : "int"

universalpython/modes/lex.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ def t_error(t):
140140

141141
# Punctuation translation
142142
punctuation_map = {
143-
"۔": ".",
144-
"،": ",",
143+
".": language_dict.get("reserved", {}).get(".", "."),
144+
",": language_dict.get("reserved", {}).get(",", ","),
145145
}
146146
if args["reverse"]:
147147
punctuation_map = {v: k for k, v in punctuation_map.items()}
@@ -164,7 +164,7 @@ def t_error(t):
164164
break
165165

166166
if tok.value in reserved:
167-
compiled_code += tok.type if tok.type != 'NUMBER' else tok.value
167+
compiled_code += tok.type if (tok.type != 'NUMBER' and tok.value not in punctuation_map and tok.type not in punctuation_map) else tok.value
168168
else:
169169
compiled_code += tok.value
170170

universalpython/universalpython.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ def main():
174174
with open(filename) as code_pyfile:
175175
code = code_pyfile.read()
176176

177+
# Default mode is 'lex' if not specified
178+
mode = args.get('mode', 'lex')
179+
177180
return run_module(mode, code, args)
178181

179182
if __name__ == "__main__":

0 commit comments

Comments
 (0)