lizard-lang 0.1.0__tar.gz
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_lang-0.1.0/PKG-INFO +4 -0
- lizard_lang-0.1.0/README.md +162 -0
- lizard_lang-0.1.0/lizard/__init__.py +0 -0
- lizard_lang-0.1.0/lizard/cli.py +27 -0
- lizard_lang-0.1.0/lizard/errors.py +2 -0
- lizard_lang-0.1.0/lizard/lexer.py +69 -0
- lizard_lang-0.1.0/lizard/runner.py +12 -0
- lizard_lang-0.1.0/lizard/tokens.py +18 -0
- lizard_lang-0.1.0/lizard/transpiler.py +76 -0
- lizard_lang-0.1.0/lizard_lang.egg-info/PKG-INFO +4 -0
- lizard_lang-0.1.0/lizard_lang.egg-info/SOURCES.txt +14 -0
- lizard_lang-0.1.0/lizard_lang.egg-info/dependency_links.txt +1 -0
- lizard_lang-0.1.0/lizard_lang.egg-info/entry_points.txt +2 -0
- lizard_lang-0.1.0/lizard_lang.egg-info/top_level.txt +1 -0
- lizard_lang-0.1.0/pyproject.toml +11 -0
- lizard_lang-0.1.0/setup.cfg +4 -0
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
# Lizard
|
|
2
|
+
|
|
3
|
+
Lizard is a Python-based programming language that adds semicolons and curly braces to Python syntax.
|
|
4
|
+
|
|
5
|
+
It transpiles directly to Python and runs on the Python runtime.
|
|
6
|
+
|
|
7
|
+
```lz
|
|
8
|
+
def hello_world() {
|
|
9
|
+
print("Hello World!");
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
if True {
|
|
13
|
+
hello_world();
|
|
14
|
+
}
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Transpiled output:
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
def hello_world():
|
|
21
|
+
print("Hello World!")
|
|
22
|
+
|
|
23
|
+
if True:
|
|
24
|
+
hello_world()
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
# Features
|
|
30
|
+
|
|
31
|
+
- Python-compatible syntax
|
|
32
|
+
- Curly brace blocks (`{}`)
|
|
33
|
+
- Optional semicolons (`;`)
|
|
34
|
+
- Direct transpilation to Python
|
|
35
|
+
- Lightweight implementation
|
|
36
|
+
- VSCode syntax highlighting support
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
# Example
|
|
41
|
+
|
|
42
|
+
## Lizard
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
def factorial(n) {
|
|
46
|
+
if n <= 1 {
|
|
47
|
+
return 1;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return n * factorial(n - 1);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
print(factorial(5));
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Generated Python
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
def factorial(n):
|
|
60
|
+
if n <= 1:
|
|
61
|
+
return 1
|
|
62
|
+
|
|
63
|
+
return n * factorial(n - 1)
|
|
64
|
+
|
|
65
|
+
print(factorial(5))
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
# Installation
|
|
71
|
+
|
|
72
|
+
## Clone repository
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
git clone https://github.com/yourusername/lizard.git
|
|
76
|
+
cd lizard
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Run
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
python main.py examples/hello.lz
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
# VSCode Extension
|
|
88
|
+
|
|
89
|
+
Lizard includes a VSCode extension with:
|
|
90
|
+
- syntax highlighting
|
|
91
|
+
- bracket matching
|
|
92
|
+
- `.lz` file support
|
|
93
|
+
|
|
94
|
+
To install locally:
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
vsce package
|
|
98
|
+
code --install-extension lizard-0.0.1.vsix
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
# Current Status
|
|
104
|
+
|
|
105
|
+
Lizard is currently experimental.
|
|
106
|
+
|
|
107
|
+
Implemented:
|
|
108
|
+
- semicolon removal
|
|
109
|
+
- brace blocks
|
|
110
|
+
- automatic indentation
|
|
111
|
+
- Python transpilation
|
|
112
|
+
|
|
113
|
+
Planned:
|
|
114
|
+
- lexer
|
|
115
|
+
- parser
|
|
116
|
+
- AST
|
|
117
|
+
- formatter
|
|
118
|
+
- LSP support
|
|
119
|
+
- self-hosting experiments
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
# Project Structure
|
|
124
|
+
|
|
125
|
+
```txt
|
|
126
|
+
lizard/
|
|
127
|
+
├── lizard/
|
|
128
|
+
│ ├── transpiler.py
|
|
129
|
+
│ ├── runner.py
|
|
130
|
+
│ └── cli.py
|
|
131
|
+
│
|
|
132
|
+
├── examples/
|
|
133
|
+
├── vscode-extension/
|
|
134
|
+
└── main.py
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
---
|
|
138
|
+
|
|
139
|
+
# Why?
|
|
140
|
+
|
|
141
|
+
Because some developers prefer:
|
|
142
|
+
|
|
143
|
+
```js
|
|
144
|
+
if (condition) {
|
|
145
|
+
doSomething();
|
|
146
|
+
}
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
over:
|
|
150
|
+
|
|
151
|
+
```python
|
|
152
|
+
if condition:
|
|
153
|
+
do_something()
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Lizard explores whether Python can support both styles while preserving readability and simplicity.
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
# License
|
|
161
|
+
|
|
162
|
+
MIT
|
|
File without changes
|
|
@@ -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
|
|
@@ -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
|
|
@@ -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
|
|
@@ -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,14 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
lizard/__init__.py
|
|
4
|
+
lizard/cli.py
|
|
5
|
+
lizard/errors.py
|
|
6
|
+
lizard/lexer.py
|
|
7
|
+
lizard/runner.py
|
|
8
|
+
lizard/tokens.py
|
|
9
|
+
lizard/transpiler.py
|
|
10
|
+
lizard_lang.egg-info/PKG-INFO
|
|
11
|
+
lizard_lang.egg-info/SOURCES.txt
|
|
12
|
+
lizard_lang.egg-info/dependency_links.txt
|
|
13
|
+
lizard_lang.egg-info/entry_points.txt
|
|
14
|
+
lizard_lang.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
lizard
|