lizard-lang 0.0.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lizard/__init__.py +3 -0
- lizard/cli.py +27 -0
- lizard/errors.py +2 -0
- lizard/lexer.py +69 -0
- lizard/runner.py +12 -0
- lizard/tokens.py +18 -0
- lizard/transpiler.py +76 -0
- lizard_lang-0.0.2.dist-info/METADATA +198 -0
- lizard_lang-0.0.2.dist-info/RECORD +13 -0
- lizard_lang-0.0.2.dist-info/WHEEL +5 -0
- lizard_lang-0.0.2.dist-info/entry_points.txt +2 -0
- lizard_lang-0.0.2.dist-info/licenses/LICENSE +21 -0
- lizard_lang-0.0.2.dist-info/top_level.txt +1 -0
lizard/__init__.py
ADDED
lizard/cli.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
|
|
4
|
+
from lizard.errors import LizardSyntaxError
|
|
5
|
+
from lizard.transpiler import transpile
|
|
6
|
+
from lizard.runner import run
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def main():
|
|
10
|
+
if len(sys.argv) != 2:
|
|
11
|
+
print("Usage: lizard <file.lz>")
|
|
12
|
+
return 1
|
|
13
|
+
|
|
14
|
+
path = sys.argv[1]
|
|
15
|
+
|
|
16
|
+
try:
|
|
17
|
+
source = Path(path).read_text()
|
|
18
|
+
python_code = transpile(source)
|
|
19
|
+
run(python_code)
|
|
20
|
+
except FileNotFoundError:
|
|
21
|
+
print(f"File not found: {path}")
|
|
22
|
+
return 1
|
|
23
|
+
except LizardSyntaxError as error:
|
|
24
|
+
print(f"Syntax error: {error}")
|
|
25
|
+
return 1
|
|
26
|
+
|
|
27
|
+
return 0
|
lizard/errors.py
ADDED
lizard/lexer.py
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
from lizard.tokens import Token, TokenType
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def lex_line(line: str, line_number: int) -> list[Token]:
|
|
5
|
+
tokens = []
|
|
6
|
+
buffer = []
|
|
7
|
+
buffer_start_col = 1
|
|
8
|
+
|
|
9
|
+
in_string = False
|
|
10
|
+
quote_char = ""
|
|
11
|
+
|
|
12
|
+
i = 0
|
|
13
|
+
|
|
14
|
+
while i < len(line):
|
|
15
|
+
ch = line[i]
|
|
16
|
+
col = i + 1
|
|
17
|
+
|
|
18
|
+
if in_string:
|
|
19
|
+
buffer.append(ch)
|
|
20
|
+
if ch == quote_char:
|
|
21
|
+
tokens.append(Token(TokenType.STRING, "".join(buffer), line_number, buffer_start_col))
|
|
22
|
+
buffer = []
|
|
23
|
+
in_string = False
|
|
24
|
+
quote_char = ""
|
|
25
|
+
i += 1
|
|
26
|
+
continue
|
|
27
|
+
|
|
28
|
+
if ch in ('"', "'"):
|
|
29
|
+
if buffer:
|
|
30
|
+
tokens.append(Token(TokenType.CODE, "".join(buffer), line_number, buffer_start_col))
|
|
31
|
+
buffer = []
|
|
32
|
+
in_string = True
|
|
33
|
+
quote_char = ch
|
|
34
|
+
buffer_start_col = col
|
|
35
|
+
buffer.append(ch)
|
|
36
|
+
i += 1
|
|
37
|
+
continue
|
|
38
|
+
|
|
39
|
+
if ch == "#":
|
|
40
|
+
if buffer:
|
|
41
|
+
tokens.append(Token(TokenType.CODE, "".join(buffer), line_number, buffer_start_col))
|
|
42
|
+
buffer = []
|
|
43
|
+
tokens.append(Token(TokenType.COMMENT, line[i:], line_number, col))
|
|
44
|
+
break
|
|
45
|
+
|
|
46
|
+
if ch in (TokenType.LBRACE.value, TokenType.RBRACE.value, TokenType.SEMICOLON.value):
|
|
47
|
+
if buffer:
|
|
48
|
+
tokens.append(Token(TokenType.CODE, "".join(buffer), line_number, buffer_start_col))
|
|
49
|
+
buffer = []
|
|
50
|
+
if ch == TokenType.LBRACE.value:
|
|
51
|
+
tokens.append(Token(TokenType.LBRACE, ch, line_number, col))
|
|
52
|
+
elif ch == TokenType.RBRACE.value:
|
|
53
|
+
tokens.append(Token(TokenType.RBRACE, ch, line_number, col))
|
|
54
|
+
else:
|
|
55
|
+
tokens.append(Token(TokenType.SEMICOLON, ch, line_number, col))
|
|
56
|
+
i += 1
|
|
57
|
+
continue
|
|
58
|
+
|
|
59
|
+
if not buffer:
|
|
60
|
+
buffer_start_col = col
|
|
61
|
+
buffer.append(ch)
|
|
62
|
+
i += 1
|
|
63
|
+
|
|
64
|
+
if in_string:
|
|
65
|
+
tokens.append(Token(TokenType.STRING, "".join(buffer), line_number, buffer_start_col))
|
|
66
|
+
elif buffer:
|
|
67
|
+
tokens.append(Token(TokenType.CODE, "".join(buffer), line_number, buffer_start_col))
|
|
68
|
+
|
|
69
|
+
return tokens
|
lizard/runner.py
ADDED
lizard/tokens.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from enum import Enum
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class TokenType(Enum):
|
|
5
|
+
CODE = "CODE"
|
|
6
|
+
STRING = "STRING"
|
|
7
|
+
COMMENT = "COMMENT"
|
|
8
|
+
LBRACE = "{"
|
|
9
|
+
RBRACE = "}"
|
|
10
|
+
SEMICOLON = ";"
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class Token:
|
|
14
|
+
def __init__(self, token_type, value, line, col):
|
|
15
|
+
self.type = token_type
|
|
16
|
+
self.value = value
|
|
17
|
+
self.line = line
|
|
18
|
+
self.col = col
|
lizard/transpiler.py
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
from lizard.errors import LizardSyntaxError
|
|
2
|
+
from lizard.lexer import lex_line
|
|
3
|
+
from lizard.tokens import TokenType
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
INDENT = " "
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def transpile_line(line: str, line_number: int) -> tuple[str, bool, bool]:
|
|
10
|
+
result = []
|
|
11
|
+
|
|
12
|
+
opens_block = False
|
|
13
|
+
closes_block = False
|
|
14
|
+
has_comment = False
|
|
15
|
+
|
|
16
|
+
tokens = lex_line(line, line_number)
|
|
17
|
+
|
|
18
|
+
for token in tokens:
|
|
19
|
+
if token.type == TokenType.SEMICOLON:
|
|
20
|
+
continue
|
|
21
|
+
|
|
22
|
+
if token.type == TokenType.COMMENT:
|
|
23
|
+
result.append(token.value)
|
|
24
|
+
has_comment = True
|
|
25
|
+
break
|
|
26
|
+
|
|
27
|
+
if token.type == TokenType.LBRACE:
|
|
28
|
+
result.append(":")
|
|
29
|
+
opens_block = True
|
|
30
|
+
continue
|
|
31
|
+
|
|
32
|
+
if token.type == TokenType.RBRACE:
|
|
33
|
+
closes_block = True
|
|
34
|
+
continue
|
|
35
|
+
|
|
36
|
+
result.append(token.value)
|
|
37
|
+
|
|
38
|
+
transformed = "".join(result)
|
|
39
|
+
if not has_comment:
|
|
40
|
+
transformed = transformed.rstrip()
|
|
41
|
+
|
|
42
|
+
return transformed, opens_block, closes_block
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def transpile(source: str) -> str:
|
|
46
|
+
output = []
|
|
47
|
+
|
|
48
|
+
indent_level = 0
|
|
49
|
+
|
|
50
|
+
for line_number, raw_line in enumerate(source.splitlines(), start=1):
|
|
51
|
+
|
|
52
|
+
stripped = raw_line.strip()
|
|
53
|
+
|
|
54
|
+
if not stripped:
|
|
55
|
+
output.append("")
|
|
56
|
+
continue
|
|
57
|
+
|
|
58
|
+
transformed, opens_block, closes_block = transpile_line(stripped, line_number)
|
|
59
|
+
|
|
60
|
+
if closes_block:
|
|
61
|
+
indent_level -= 1
|
|
62
|
+
|
|
63
|
+
if indent_level < 0:
|
|
64
|
+
raise LizardSyntaxError(f"Unexpected '}}' at line {line_number}")
|
|
65
|
+
|
|
66
|
+
output.append(
|
|
67
|
+
INDENT * indent_level + transformed
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
if opens_block:
|
|
71
|
+
indent_level += 1
|
|
72
|
+
|
|
73
|
+
if indent_level != 0:
|
|
74
|
+
raise LizardSyntaxError("Unclosed block")
|
|
75
|
+
|
|
76
|
+
return "\n".join(output)
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: lizard-lang
|
|
3
|
+
Version: 0.0.2
|
|
4
|
+
Summary: Lizard is a python-based programming language that adds semicolons and curly braces to Python syntax
|
|
5
|
+
Author: Kayk Caputo
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/KaykCaputo/lizard-lang
|
|
8
|
+
Project-URL: Repository, https://github.com/KaykCaputo/lizard-lang.git
|
|
9
|
+
Project-URL: Documentation, https://github.com/KaykCaputo/lizard-lang#readme
|
|
10
|
+
Project-URL: Issues, https://github.com/KaykCaputo/lizard-lang/issues
|
|
11
|
+
Keywords: lizard,programming language,python syntax,interpreter,compiler
|
|
12
|
+
Classifier: Development Status :: 2 - Pre-Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Topic :: Software Development :: Interpreters
|
|
15
|
+
Classifier: Topic :: Software Development :: Compilers
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Operating System :: OS Independent
|
|
23
|
+
Requires-Python: >=3.8
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
License-File: LICENSE
|
|
26
|
+
Dynamic: license-file
|
|
27
|
+
|
|
28
|
+
# Lizard
|
|
29
|
+
|
|
30
|
+
Lizard is a Python-based programming language that adds semicolons and curly braces to Python syntax.
|
|
31
|
+
|
|
32
|
+
It transpiles directly to Python and runs on the Python runtime.
|
|
33
|
+
|
|
34
|
+
```lz
|
|
35
|
+
def hello_world() {
|
|
36
|
+
print("Hello World!");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if True {
|
|
40
|
+
hello_world();
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Transpiled output:
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
def hello_world():
|
|
48
|
+
print("Hello World!")
|
|
49
|
+
|
|
50
|
+
if True:
|
|
51
|
+
hello_world()
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
# Features
|
|
57
|
+
|
|
58
|
+
- Python-compatible syntax
|
|
59
|
+
- Curly brace blocks (`{}`)
|
|
60
|
+
- Optional semicolons (`;`)
|
|
61
|
+
- Direct transpilation to Python
|
|
62
|
+
- Lightweight implementation
|
|
63
|
+
- VSCode syntax highlighting support
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
# Example
|
|
68
|
+
|
|
69
|
+
## Lizard
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
def factorial(n) {
|
|
73
|
+
if n <= 1 {
|
|
74
|
+
return 1;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return n * factorial(n - 1);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
print(factorial(5));
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Generated Python
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
def factorial(n):
|
|
87
|
+
if n <= 1:
|
|
88
|
+
return 1
|
|
89
|
+
|
|
90
|
+
return n * factorial(n - 1)
|
|
91
|
+
|
|
92
|
+
print(factorial(5))
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
# Installation
|
|
98
|
+
|
|
99
|
+
- PyPI: [lizard-lang](https://pypi.org/project/lizard-lang/)
|
|
100
|
+
- VSCode Extension: [Lizard Lang](https://marketplace.visualstudio.com/items?itemName=KaykCaputo.lizard-lang)
|
|
101
|
+
|
|
102
|
+
## Clone repository
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
git clone https://github.com/KaykCaputo/lizard-lang.git
|
|
106
|
+
cd lizard-lang
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Install (CLI)
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
pip install lizard-lang
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Run
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
lizard examples/hello.lz
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
# VSCode Extension
|
|
124
|
+
|
|
125
|
+
Lizard includes a VSCode extension with:
|
|
126
|
+
- syntax highlighting
|
|
127
|
+
- bracket matching
|
|
128
|
+
- `.lz` file support
|
|
129
|
+
|
|
130
|
+
To install locally:
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
vsce package
|
|
134
|
+
code --install-extension lizard-0.0.1.vsix
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
---
|
|
138
|
+
|
|
139
|
+
# Current Status
|
|
140
|
+
|
|
141
|
+
Lizard is currently experimental.
|
|
142
|
+
|
|
143
|
+
Implemented:
|
|
144
|
+
- semicolon removal
|
|
145
|
+
- brace blocks
|
|
146
|
+
- automatic indentation
|
|
147
|
+
- Python transpilation
|
|
148
|
+
|
|
149
|
+
Planned:
|
|
150
|
+
- lexer
|
|
151
|
+
- parser
|
|
152
|
+
- AST
|
|
153
|
+
- formatter
|
|
154
|
+
- LSP support
|
|
155
|
+
- self-hosting experiments
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
# Project Structure
|
|
160
|
+
|
|
161
|
+
```txt
|
|
162
|
+
lizard/
|
|
163
|
+
├── lizard/
|
|
164
|
+
│ ├── transpiler.py
|
|
165
|
+
│ ├── runner.py
|
|
166
|
+
│ └── cli.py
|
|
167
|
+
│
|
|
168
|
+
├── examples/
|
|
169
|
+
├── vscode-extension/
|
|
170
|
+
└── pyproject.toml
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
# Why?
|
|
176
|
+
|
|
177
|
+
Because some developers prefer:
|
|
178
|
+
|
|
179
|
+
```js
|
|
180
|
+
if (condition) {
|
|
181
|
+
doSomething();
|
|
182
|
+
}
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
over:
|
|
186
|
+
|
|
187
|
+
```python
|
|
188
|
+
if condition:
|
|
189
|
+
do_something()
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
Lizard explores whether Python can support both styles while preserving readability and simplicity.
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
# License
|
|
197
|
+
|
|
198
|
+
MIT
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
lizard/__init__.py,sha256=MAMrymk30MNId0w57GfeZuLud9fVeppwclKQrKHs6Tg,48
|
|
2
|
+
lizard/cli.py,sha256=FTCrZPILYoGlRdEz25EfIjr_cSsTbKARtd8averO3zE,586
|
|
3
|
+
lizard/errors.py,sha256=t0S_SV1AUVUUq-1WGoOTi5nIPPeNsDtX-O-93cWky-M,44
|
|
4
|
+
lizard/lexer.py,sha256=Z5fcVshb5t1_NuNKvAwwbI5-sQAH4SuRcJphBQlvuoI,2195
|
|
5
|
+
lizard/runner.py,sha256=HS1EL9lopIERet8_AurUuYinS-rC-3U552X9KYzSxHs,186
|
|
6
|
+
lizard/tokens.py,sha256=HdqJ8g8h1mCeOXB8xTTAZwwc64hBnX9vk-O1VWVpSOo,339
|
|
7
|
+
lizard/transpiler.py,sha256=Q44vId7uAxlNdftgaeKHRUubaYiX-8X9xxIYZTVoRqQ,1747
|
|
8
|
+
lizard_lang-0.0.2.dist-info/licenses/LICENSE,sha256=IGnPcVrTAokIsflrbIxQ_Np0oUakee4Ld8ZxpWzd2sw,1068
|
|
9
|
+
lizard_lang-0.0.2.dist-info/METADATA,sha256=vEkgWUE-yXPtt5-6FzLky9DvsrIJUN1BwtLY_ZaJG2k,3453
|
|
10
|
+
lizard_lang-0.0.2.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
11
|
+
lizard_lang-0.0.2.dist-info/entry_points.txt,sha256=vLC-ZQSanD6FbvVrO7k8KSMqTM7vaXZzk5iInH4sfCk,43
|
|
12
|
+
lizard_lang-0.0.2.dist-info/top_level.txt,sha256=htzoeiYeZQoGDPT6rOaNgWCvXodj5ZyK6Pcg9LN51I8,7
|
|
13
|
+
lizard_lang-0.0.2.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Kayk Caputo
|
|
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.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
lizard
|