cajyu 1.2.0 → 1.2.1

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/ErrTable.md ADDED
@@ -0,0 +1,54 @@
1
+ # Cajyu Error Table
2
+
3
+ Complete list of all error codes in Cajyu (ERR001 – ERR040).
4
+
5
+ | Code | Name | Description |
6
+ |--------|-------------------------------|-------------|
7
+ | ERR001 | Syntax error | General syntax error in the source code |
8
+ | ERR002 | Unexpected token | The parser encountered a token it did not expect |
9
+ | ERR003 | Missing closing brace | A `{` was opened but never closed with `}` |
10
+ | ERR004 | Type mismatch | A value does not match the declared type |
11
+ | ERR005 | Undefined variable | A variable was used before being declared |
12
+ | ERR006 | Invalid function call | Attempted to call something that is not a function |
13
+ | ERR007 | Missing parentheses | Expected `(` or `)` but it was missing |
14
+ | ERR008 | Invalid import | The import statement is malformed |
15
+ | ERR009 | Unexpected end of file | The file ended while the parser still expected more code |
16
+ | ERR010 | Invalid operator | An operator was used in an invalid context |
17
+ | ERR011 | Missing semicolon or block | Expected `;` or a `{ ... }` block |
18
+ | ERR012 | Invalid type annotation | The type after `:` is not recognized |
19
+ | ERR013 | Keyword used as identifier | A reserved keyword was used as a variable or function name |
20
+ | ERR014 | Unterminated string | A string was opened with `"` or `'` but never closed |
21
+ | ERR015 | Invalid number | A numeric literal is malformed |
22
+ | ERR016 | Duplicate declaration | A variable or function was declared more than once in the same scope |
23
+ | ERR017 | Missing return value | A function declared to return a value did not return anything |
24
+ | ERR018 | Invalid class member | A class contains an invalid member |
25
+ | ERR019 | Async error | Error related to `sync` / `wait` |
26
+ | ERR020 | Library not found | The requested library does not exist in CajyuLibs |
27
+ | ERR021 | Division by zero | Attempted to divide by zero |
28
+ | ERR022 | Index out of range | Array or string index is outside valid bounds |
29
+ | ERR023 | Invalid argument count | A function was called with the wrong number of arguments |
30
+ | ERR024 | Cannot call non-function | Tried to call a value that is not callable |
31
+ | ERR025 | Missing property | Tried to access a property that does not exist |
32
+ | ERR026 | Circular import | An import cycle was detected |
33
+ | ERR027 | Invalid range | `range()` received invalid arguments |
34
+ | ERR028 | File not found | A file operation targeted a non-existent file |
35
+ | ERR029 | Permission denied | The process does not have permission to access a resource |
36
+ | ERR030 | Network error | A network request failed |
37
+ | ERR031 | JSON parse error | Failed to parse a JSON string |
38
+ | ERR032 | Timeout | An operation took too long and timed out |
39
+ | ERR033 | Invalid assignment | Tried to assign to something that cannot be assigned |
40
+ | ERR034 | Break outside loop | `break` was used outside of a loop |
41
+ | ERR035 | Continue outside loop | `continue` was used outside of a loop |
42
+ | ERR036 | Invalid class inheritance | Class inheritance is malformed |
43
+ | ERR037 | Abstract method not implemented | An abstract method was not implemented |
44
+ | ERR038 | Stack overflow | The call stack exceeded its limit |
45
+ | ERR039 | Memory limit exceeded | The program used too much memory |
46
+ | ERR040 | Unknown builtin | Called a builtin function that does not exist |
47
+
48
+ All errors follow the format:
49
+
50
+ ```
51
+ There is an <error name> in line <n>: ERR0xx.
52
+ <line content>
53
+ ^
54
+ ```
package/README.md CHANGED
@@ -10,7 +10,7 @@ Cajyu gives you a simpler, more expressive syntax while staying fully compatible
10
10
 
11
11
  [![npm](https://img.shields.io/badge/npm-cajyu-blue)](https://www.npmjs.com/package/cajyu)
12
12
  [![License](https://img.shields.io/badge/license-MIT-green)](LICENSE)
13
- [![Version](https://img.shields.io/badge/version-1.1.0-brightgreen)](package.json)
13
+ [![Version](https://img.shields.io/badge/version-1.2.1-brightgreen)](package.json)
14
14
 
15
15
  ---
16
16
 
@@ -0,0 +1,51 @@
1
+ # Comparison: JavaScript vs TypeScript vs Cajyu
2
+
3
+ Three identical features implemented in three languages.
4
+
5
+ ## 1. Simple HTML Server
6
+
7
+ | Language | File | Lines (approx) | Notes |
8
+ |------------|-----------------------------------|----------------|-------|
9
+ | JavaScript | `js/simple-server.js` | 18 | Direct `http` module |
10
+ | TypeScript | `ts/simple-server.ts` | 18 | Same + types |
11
+ | Cajyu | `cajyu/simple-server.cjy` | 10 | Uses `CajyuLibs.http` |
12
+
13
+ **Cajyu is the shortest.** The HTTP library abstracts the boilerplate.
14
+
15
+ ## 2. Click Counter
16
+
17
+ | Language | File | Lines (approx) | Notes |
18
+ |------------|-----------------------------------|----------------|-------|
19
+ | JavaScript | `js/click-counter.js` | 35 | Manual route + inline HTML/JS |
20
+ | TypeScript | `ts/click-counter.ts` | 35 | Same + types |
21
+ | Cajyu | `cajyu/click-counter.cjy` | 16 | `server.post` + `server.file` |
22
+
23
+ Again, Cajyu is more concise because of the built-in server abstraction.
24
+
25
+ ## 3. Live Chat (WebSocket)
26
+
27
+ | Language | File | Lines (approx) | Notes |
28
+ |------------|-----------------------------------|----------------|-------|
29
+ | JavaScript | `js/live-chat.js` | 45 | Uses `ws` package + full HTML |
30
+ | TypeScript | `ts/live-chat.ts` | 45 | Same + types |
31
+ | Cajyu | `cajyu/live-chat.cjy` | 12 | Uses `CajyuLibs.websocket` (broadcast only) |
32
+
33
+ Cajyu version is shorter but currently only shows the WebSocket server side.
34
+
35
+ ## Summary
36
+
37
+ | Aspect | JavaScript | TypeScript | Cajyu |
38
+ |---------------------|-----------------|------------------|------------------------|
39
+ | Boilerplate | Medium | Medium | Low |
40
+ | Type safety | None | Strong | Optional runtime |
41
+ | Learning curve | Low | Medium | Low (if you know JS) |
42
+ | Ecosystem | Huge | Huge | Small (growing) |
43
+ | Abstraction level | Low-medium | Low-medium | Higher |
44
+ | Best for | Production | Large projects | Prototyping / learning |
45
+
46
+ **Conclusion:**
47
+ - **JavaScript** is the baseline.
48
+ - **TypeScript** adds safety with almost no extra cost.
49
+ - **Cajyu** reduces boilerplate the most, especially for servers, but is still a prototype language.
50
+
51
+ All examples are in `examples/comparison/`.
@@ -0,0 +1,17 @@
1
+ import Server from CajyuLibs.http
2
+ import print from CajyuLibs.serial
3
+
4
+ var clicks = 0
5
+ var server = new Server(3001)
6
+ print("Cajyu click server at http://localhost:3001")
7
+
8
+ var html = "<!DOCTYPE html><html><body><h1>Click Counter (Cajyu)</h1><button id='btn'>Click me</button><p>Total clicks: <span id='count'>0</span></p><script>const btn=document.getElementById('btn');const count=document.getElementById('count');btn.onclick=async()=>{const r=await fetch('/click',{method:'POST'});const data=await r.json();count.textContent=data.clicks;};</script></body></html>"
9
+
10
+ server.file("/", html)
11
+ server.file("index.html", html)
12
+
13
+ server.post(fn b {
14
+ clicks = clicks + 1
15
+ print("Click #" + clicks)
16
+ return { code: 200, clicks: clicks }
17
+ })
@@ -0,0 +1,16 @@
1
+ import WS from CajyuLibs.websocket
2
+ import print from CajyuLibs.serial
3
+
4
+ var wss = new WS.Server(3002)
5
+ print("Cajyu live chat WebSocket on port 3002")
6
+
7
+ wss.on("connection", fn client {
8
+ print("Client connected")
9
+ })
10
+
11
+ wss.on("message", fn msg, client {
12
+ print("Message: " + msg)
13
+ wss.broadcast(msg)
14
+ })
15
+
16
+ print("Open a WebSocket client to ws://localhost:3002 to chat")
@@ -0,0 +1,10 @@
1
+ import Server from CajyuLibs.http
2
+ import print from CajyuLibs.serial
3
+
4
+ var server = new Server(3000)
5
+ print("Cajyu simple server running at http://localhost:3000")
6
+
7
+ var html = "<!DOCTYPE html><html><head><title>Simple Server</title></head><body><h1>Hello from Cajyu!</h1><p>This is a simple text served by a Cajyu server.</p></body></html>"
8
+
9
+ server.file("/", html)
10
+ server.file("index.html", html)
@@ -0,0 +1,20 @@
1
+ // Simple HTML server - JavaScript
2
+ import http from 'http';
3
+
4
+ const server = http.createServer((req, res) => {
5
+ res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
6
+ res.end(`
7
+ <!DOCTYPE html>
8
+ <html>
9
+ <head><title>Simple Server</title></head>
10
+ <body>
11
+ <h1>Hello from JavaScript!</h1>
12
+ <p>This is a simple text served by a Node.js server.</p>
13
+ </body>
14
+ </html>
15
+ `);
16
+ });
17
+
18
+ server.listen(3000, () => {
19
+ console.log('JS server running at http://localhost:3000');
20
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cajyu",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "Cajyu programming language - a custom language that compiles to JavaScript",
5
5
  "main": "src/compiler.js",
6
6
  "bin": {
@@ -1,16 +0,0 @@
1
- # AST Migration in progress
2
-
3
- The compiler now has a real Tokenizer + recursive descent Parser that builds an AST.
4
-
5
- Current status:
6
- - Tokenizer handles strings, numbers, identifiers, keywords correctly
7
- - Parser builds AST for var, fn, if/elif/else, while, for, class, return, expressions
8
- - Code generator emits JavaScript from the AST
9
-
10
- Still being completed:
11
- - Full import resolution
12
- - Builtins (range, typeCheck)
13
- - Async (sync/wait)
14
- - One-liners and more edge cases
15
-
16
- This is the foundation for a robust parser.