0x-lang 0.1.0
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.
- package/LICENSE +15 -0
- package/README.md +357 -0
- package/dist/ast.d.ts +905 -0
- package/dist/ast.js +3 -0
- package/dist/ast.js.map +1 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +190 -0
- package/dist/cli.js.map +1 -0
- package/dist/compiler.d.ts +6 -0
- package/dist/compiler.js +28 -0
- package/dist/compiler.js.map +1 -0
- package/dist/generators/react.d.ts +4 -0
- package/dist/generators/react.js +2304 -0
- package/dist/generators/react.js.map +1 -0
- package/dist/generators/shared.d.ts +3 -0
- package/dist/generators/shared.js +15 -0
- package/dist/generators/shared.js.map +1 -0
- package/dist/generators/svelte.d.ts +2 -0
- package/dist/generators/svelte.js +607 -0
- package/dist/generators/svelte.js.map +1 -0
- package/dist/generators/vue.d.ts +2 -0
- package/dist/generators/vue.js +660 -0
- package/dist/generators/vue.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/init.d.ts +1 -0
- package/dist/init.js +101 -0
- package/dist/init.js.map +1 -0
- package/dist/parser.d.ts +7 -0
- package/dist/parser.js +3586 -0
- package/dist/parser.js.map +1 -0
- package/dist/react/chat.jsx +44 -0
- package/dist/react/counter.jsx +30 -0
- package/dist/react/dashboard.jsx +60 -0
- package/dist/react/ecommerce.jsx +63 -0
- package/dist/react/todo.jsx +38 -0
- package/dist/svelte/chat.svelte +41 -0
- package/dist/svelte/counter.svelte +27 -0
- package/dist/svelte/dashboard.svelte +57 -0
- package/dist/svelte/ecommerce.svelte +59 -0
- package/dist/svelte/todo.svelte +35 -0
- package/dist/tokenizer.d.ts +13 -0
- package/dist/tokenizer.js +318 -0
- package/dist/tokenizer.js.map +1 -0
- package/dist/validator.d.ts +16 -0
- package/dist/validator.js +315 -0
- package/dist/validator.js.map +1 -0
- package/dist/vue/chat.vue +44 -0
- package/dist/vue/counter.vue +30 -0
- package/dist/vue/dashboard.vue +60 -0
- package/dist/vue/ecommerce.vue +62 -0
- package/dist/vue/todo.vue +38 -0
- package/package.json +63 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 0x-lang contributors
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
10
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
11
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
12
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
13
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
14
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
|
+
PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="website/assets/logo.svg" alt="0x Logo" width="120" height="120" />
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<h1 align="center">0x</h1>
|
|
6
|
+
<p align="center"><strong>The AI-First Programming Language</strong></p>
|
|
7
|
+
|
|
8
|
+
<p align="center">
|
|
9
|
+
18 lines of 0x replaces 96 lines of React.<br/>
|
|
10
|
+
<strong>80% less code. Zero ambiguity. Multi-target output.</strong>
|
|
11
|
+
</p>
|
|
12
|
+
|
|
13
|
+
<p align="center">
|
|
14
|
+
<a href="https://www.npmjs.com/package/0x-lang"><img src="https://img.shields.io/npm/v/0x-lang.svg?style=flat-square&color=FF4D4D" alt="npm version" /></a>
|
|
15
|
+
<a href="https://github.com/user/0x-lang/actions"><img src="https://img.shields.io/github/actions/workflow/status/user/0x-lang/ci.yml?style=flat-square" alt="CI" /></a>
|
|
16
|
+
<a href="https://opensource.org/licenses/ISC"><img src="https://img.shields.io/badge/license-ISC-blue.svg?style=flat-square" alt="License" /></a>
|
|
17
|
+
</p>
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Why 0x?
|
|
22
|
+
|
|
23
|
+
AI models spend most of their tokens generating boilerplate — `useState`, `useCallback`, JSX wrappers, CSS-in-JS. **0x eliminates that entirely.**
|
|
24
|
+
|
|
25
|
+
| | 0x | Production React | Savings |
|
|
26
|
+
|---|---|---|---|
|
|
27
|
+
| **Counter App** | 18 lines | 96 lines | **81%** |
|
|
28
|
+
| **Todo App** | 24 lines | 136 lines | **82%** |
|
|
29
|
+
| **Dashboard** | 37 lines | ~185 lines | **80%** |
|
|
30
|
+
| **Chat App** | 31 lines | ~155 lines | **80%** |
|
|
31
|
+
| **E-commerce** | 44 lines | ~210 lines | **79%** |
|
|
32
|
+
|
|
33
|
+
> Compared against production TypeScript React with full inline styling, types, and component structure.
|
|
34
|
+
|
|
35
|
+
0x is a **declarative, indentation-based language** that compiles to production-ready React JSX, Vue 3 SFC, and Svelte 5 components. It's designed specifically for AI agents to generate UI code faster, cheaper, and more accurately.
|
|
36
|
+
|
|
37
|
+
## Quick Start
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
# Install globally
|
|
41
|
+
npm install -g 0x-lang
|
|
42
|
+
|
|
43
|
+
# Or use directly with npx
|
|
44
|
+
npx 0x-lang build app.ai --target react
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Initialize a New Project
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
npx 0x-lang init my-app
|
|
51
|
+
cd my-app
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
This creates a project with example `.ai` files and a ready-to-use build configuration.
|
|
55
|
+
|
|
56
|
+
### Your First 0x Program
|
|
57
|
+
|
|
58
|
+
Create `counter.ai`:
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
page Counter:
|
|
62
|
+
state count: int = 0
|
|
63
|
+
derived doubled = count * 2
|
|
64
|
+
|
|
65
|
+
fn increment():
|
|
66
|
+
count += 1
|
|
67
|
+
|
|
68
|
+
fn decrement():
|
|
69
|
+
count -= 1
|
|
70
|
+
|
|
71
|
+
layout col gap=16 padding=24 center:
|
|
72
|
+
text "Counter" size=2xl bold
|
|
73
|
+
text "{count}" size=3xl bold color=#333
|
|
74
|
+
text "Doubled: {doubled}" size=lg color=#666
|
|
75
|
+
|
|
76
|
+
layout row gap=8:
|
|
77
|
+
button "-1" style=danger -> decrement()
|
|
78
|
+
button "Reset" -> count = 0
|
|
79
|
+
button "+1" style=primary -> increment()
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Compile
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
# To React
|
|
86
|
+
0x build counter.ai --target react
|
|
87
|
+
|
|
88
|
+
# To Vue 3
|
|
89
|
+
0x build counter.ai --target vue
|
|
90
|
+
|
|
91
|
+
# To Svelte 5
|
|
92
|
+
0x build counter.ai --target svelte
|
|
93
|
+
|
|
94
|
+
# All targets at once
|
|
95
|
+
0x build counter.ai --target react,vue,svelte
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Watch Mode
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
0x dev counter.ai --target react
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Language Reference
|
|
105
|
+
|
|
106
|
+
### Structure
|
|
107
|
+
|
|
108
|
+
```python
|
|
109
|
+
page PageName: # Page component (has routing)
|
|
110
|
+
component CompName: # Reusable component
|
|
111
|
+
app AppName: # App root
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### State Management
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
state count: int = 0 # Reactive state
|
|
118
|
+
derived doubled = count * 2 # Auto-computed derived value
|
|
119
|
+
prop title: str = "default" # External property
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Types
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
type Item = {id: int, text: str, done: bool}
|
|
126
|
+
state items: list[Item] = []
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Functions
|
|
130
|
+
|
|
131
|
+
```python
|
|
132
|
+
fn add():
|
|
133
|
+
items.push({id: Date.now(), text: input, done: false})
|
|
134
|
+
input = ""
|
|
135
|
+
|
|
136
|
+
async fn fetchData():
|
|
137
|
+
data = await api.getData()
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### Layout
|
|
141
|
+
|
|
142
|
+
```python
|
|
143
|
+
layout col gap=16 padding=24: # Vertical flex
|
|
144
|
+
layout row gap=8 center: # Horizontal flex
|
|
145
|
+
layout grid cols=3 gap=16: # CSS Grid
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### UI Elements
|
|
149
|
+
|
|
150
|
+
```python
|
|
151
|
+
text "Hello" size=2xl bold color=#333 # Text
|
|
152
|
+
text "{variable}" size=lg # Interpolation
|
|
153
|
+
button "Click" style=primary -> action() # Button + action
|
|
154
|
+
input binding placeholder="Type..." # Two-way binding
|
|
155
|
+
toggle binding # Toggle switch
|
|
156
|
+
select binding options=["a", "b", "c"] # Select dropdown
|
|
157
|
+
image src width=100 height=100 # Image
|
|
158
|
+
link "Text" href="/path" # Link
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### Control Flow
|
|
162
|
+
|
|
163
|
+
```python
|
|
164
|
+
if condition:
|
|
165
|
+
text "True"
|
|
166
|
+
elif other:
|
|
167
|
+
text "Other"
|
|
168
|
+
else:
|
|
169
|
+
text "False"
|
|
170
|
+
|
|
171
|
+
for item in items:
|
|
172
|
+
text item.name
|
|
173
|
+
|
|
174
|
+
show isVisible: # Conditional display
|
|
175
|
+
hide isHidden: # Conditional hide
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Lifecycle & Watchers
|
|
179
|
+
|
|
180
|
+
```python
|
|
181
|
+
on mount:
|
|
182
|
+
data = await fetchData()
|
|
183
|
+
|
|
184
|
+
on destroy:
|
|
185
|
+
cleanup()
|
|
186
|
+
|
|
187
|
+
watch variable:
|
|
188
|
+
console.log("Changed")
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### API & Validation
|
|
192
|
+
|
|
193
|
+
```python
|
|
194
|
+
api getData = GET "/api/data"
|
|
195
|
+
api postItem = POST "/api/items"
|
|
196
|
+
|
|
197
|
+
check items.length <= 100 "Max 100 items allowed"
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
## Real-World Example: Todo App
|
|
201
|
+
|
|
202
|
+
```python
|
|
203
|
+
page Todo:
|
|
204
|
+
type Item = {id: int, text: str, done: bool}
|
|
205
|
+
|
|
206
|
+
state items: list[Item] = []
|
|
207
|
+
state input: str = ""
|
|
208
|
+
derived remaining = items.filter(i => !i.done).length
|
|
209
|
+
|
|
210
|
+
fn add():
|
|
211
|
+
if input.trim() != "":
|
|
212
|
+
items.push({id: Date.now(), text: input, done: false})
|
|
213
|
+
input = ""
|
|
214
|
+
|
|
215
|
+
fn remove(id: int):
|
|
216
|
+
items = items.filter(i => i.id != id)
|
|
217
|
+
|
|
218
|
+
layout col gap=16 padding=24 maxWidth=600 margin=auto:
|
|
219
|
+
text "Todo ({remaining} remaining)" size=2xl bold
|
|
220
|
+
|
|
221
|
+
layout row gap=8:
|
|
222
|
+
input input placeholder="What needs to be done?"
|
|
223
|
+
button "Add" style=primary -> add()
|
|
224
|
+
|
|
225
|
+
for item in items:
|
|
226
|
+
layout row gap=8 center:
|
|
227
|
+
toggle item.done
|
|
228
|
+
text item.text strike={item.done}
|
|
229
|
+
button "Delete" style=danger size=sm -> remove(item.id)
|
|
230
|
+
|
|
231
|
+
if items.length == 0:
|
|
232
|
+
text "Nothing to do" color=#999 center
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
This compiles to a full React component with `useState`, `useMemo`, `useCallback`, JSX, and styling — **80% less code** than writing React directly.
|
|
236
|
+
|
|
237
|
+
## Benchmarks
|
|
238
|
+
|
|
239
|
+
Run benchmarks yourself:
|
|
240
|
+
|
|
241
|
+
```bash
|
|
242
|
+
0x bench examples/counter.ai
|
|
243
|
+
0x bench examples/todo.ai
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
| Example | 0x Lines | React Lines | Savings |
|
|
247
|
+
|---------|----------|-------------|---------|
|
|
248
|
+
| Counter | 18 | 96 | **81%** |
|
|
249
|
+
| Todo | 24 | 136 | **82%** |
|
|
250
|
+
| Dashboard | 37 | ~185 | **80%** |
|
|
251
|
+
| Chat | 31 | ~155 | **80%** |
|
|
252
|
+
| E-commerce | 44 | ~210 | **79%** |
|
|
253
|
+
|
|
254
|
+
> Lines of code compared against production TypeScript React with full inline styling and component structure.
|
|
255
|
+
|
|
256
|
+
## MCP Integration (Claude / Cursor)
|
|
257
|
+
|
|
258
|
+
0x includes an [MCP server](mcp-server/) for seamless integration with Claude and Cursor IDE. AI agents can compile 0x code directly within their workflow.
|
|
259
|
+
|
|
260
|
+
```bash
|
|
261
|
+
cd mcp-server
|
|
262
|
+
npm install
|
|
263
|
+
npm start
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
See [mcp-server/README.md](mcp-server/README.md) for setup details.
|
|
267
|
+
|
|
268
|
+
## Programmatic API
|
|
269
|
+
|
|
270
|
+
```typescript
|
|
271
|
+
import { compile } from '0x-lang';
|
|
272
|
+
|
|
273
|
+
const source = `
|
|
274
|
+
page Hello:
|
|
275
|
+
state name: str = "World"
|
|
276
|
+
layout col:
|
|
277
|
+
text "Hello, {name}!" size=2xl bold
|
|
278
|
+
`;
|
|
279
|
+
|
|
280
|
+
const result = compile(source, { target: 'react' });
|
|
281
|
+
console.log(result.code); // React JSX output
|
|
282
|
+
console.log(result.tokenCount); // Token count
|
|
283
|
+
console.log(result.lineCount); // Line count
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
### Individual Pipeline Steps
|
|
287
|
+
|
|
288
|
+
```typescript
|
|
289
|
+
import { tokenize, parse, validate, generateReact, generateVue, generateSvelte } from '0x-lang';
|
|
290
|
+
|
|
291
|
+
const tokens = tokenize(source);
|
|
292
|
+
const ast = parse(source);
|
|
293
|
+
const validation = validate(ast);
|
|
294
|
+
const react = generateReact(ast);
|
|
295
|
+
const vue = generateVue(ast);
|
|
296
|
+
const svelte = generateSvelte(ast);
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
## CLI Reference
|
|
300
|
+
|
|
301
|
+
```
|
|
302
|
+
0x build <file.ai> --target <target> [--output <dir>]
|
|
303
|
+
0x dev <file.ai> --target <target>
|
|
304
|
+
0x bench <file.ai>
|
|
305
|
+
0x init [project-name]
|
|
306
|
+
|
|
307
|
+
Options:
|
|
308
|
+
--target, -t Target: react, vue, svelte (comma-separated)
|
|
309
|
+
--output, -o Output directory (default: ./dist/)
|
|
310
|
+
--help, -h Show help
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
## Architecture
|
|
314
|
+
|
|
315
|
+
```
|
|
316
|
+
Source (.ai) → Tokenizer → Parser → AST → Validator → Generator → Output
|
|
317
|
+
├── React JSX
|
|
318
|
+
├── Vue 3 SFC
|
|
319
|
+
└── Svelte 5
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
The compiler follows a clean pipeline architecture:
|
|
323
|
+
|
|
324
|
+
1. **Tokenizer** — Lexical analysis with indentation-aware token generation
|
|
325
|
+
2. **Parser** — Recursive descent parser producing a typed AST
|
|
326
|
+
3. **Validator** — Static analysis (circular deps, unused state, type checks)
|
|
327
|
+
4. **Generators** — Target-specific code generation (React/Vue/Svelte)
|
|
328
|
+
|
|
329
|
+
## Contributing
|
|
330
|
+
|
|
331
|
+
We welcome contributions! Please read [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
|
|
332
|
+
|
|
333
|
+
```bash
|
|
334
|
+
# Clone the repo
|
|
335
|
+
git clone https://github.com/user/0x-lang.git
|
|
336
|
+
cd 0x-lang
|
|
337
|
+
|
|
338
|
+
# Install dependencies
|
|
339
|
+
npm install
|
|
340
|
+
|
|
341
|
+
# Run tests
|
|
342
|
+
npm test
|
|
343
|
+
|
|
344
|
+
# Build
|
|
345
|
+
npm run build
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
## License
|
|
349
|
+
|
|
350
|
+
[ISC](LICENSE) — Free for personal and commercial use.
|
|
351
|
+
|
|
352
|
+
---
|
|
353
|
+
|
|
354
|
+
<p align="center">
|
|
355
|
+
<strong>0x</strong> — Write less. Compile more. Ship everywhere.<br/>
|
|
356
|
+
<a href="https://0x-lang.dev">Website</a> · <a href="https://github.com/user/0x-lang">GitHub</a> · <a href="https://www.npmjs.com/package/0x-lang">npm</a>
|
|
357
|
+
</p>
|