kimchilang 1.0.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/.github/workflows/ci.yml +66 -0
- package/README.md +1547 -0
- package/create-kimchi-app/README.md +44 -0
- package/create-kimchi-app/index.js +214 -0
- package/create-kimchi-app/package.json +22 -0
- package/editors/README.md +121 -0
- package/editors/sublime/KimchiLang.sublime-syntax +138 -0
- package/editors/vscode/README.md +90 -0
- package/editors/vscode/kimchilang-1.1.0.vsix +0 -0
- package/editors/vscode/language-configuration.json +37 -0
- package/editors/vscode/package.json +55 -0
- package/editors/vscode/src/extension.js +354 -0
- package/editors/vscode/syntaxes/kimchi.tmLanguage.json +215 -0
- package/examples/api/client.km +36 -0
- package/examples/async_pipe.km +58 -0
- package/examples/basic.kimchi +109 -0
- package/examples/cli_framework/README.md +92 -0
- package/examples/cli_framework/calculator.km +61 -0
- package/examples/cli_framework/deploy.km +126 -0
- package/examples/cli_framework/greeter.km +26 -0
- package/examples/config.static +27 -0
- package/examples/config.static.js +10 -0
- package/examples/env_test.km +37 -0
- package/examples/fibonacci.kimchi +17 -0
- package/examples/greeter.km +15 -0
- package/examples/hello.js +1 -0
- package/examples/hello.kimchi +3 -0
- package/examples/js_interop.km +42 -0
- package/examples/logger_example.km +34 -0
- package/examples/memo_fibonacci.km +17 -0
- package/examples/myapp/lib/http.js +14 -0
- package/examples/myapp/lib/http.km +16 -0
- package/examples/myapp/main.km +16 -0
- package/examples/myapp/main_with_mock.km +42 -0
- package/examples/myapp/services/api.js +18 -0
- package/examples/myapp/services/api.km +18 -0
- package/examples/new_features.kimchi +52 -0
- package/examples/project_example.static +20 -0
- package/examples/readme_examples.km +240 -0
- package/examples/reduce_pattern_match.km +85 -0
- package/examples/regex_match.km +46 -0
- package/examples/sample.js +45 -0
- package/examples/sample.km +39 -0
- package/examples/secrets.static +35 -0
- package/examples/secrets.static.js +30 -0
- package/examples/shell-example.mjs +144 -0
- package/examples/shell_example.km +19 -0
- package/examples/stdlib_test.km +22 -0
- package/examples/test_example.km +69 -0
- package/examples/testing/README.md +88 -0
- package/examples/testing/http_client.km +18 -0
- package/examples/testing/math.km +48 -0
- package/examples/testing/math.test.km +93 -0
- package/examples/testing/user_service.km +29 -0
- package/examples/testing/user_service.test.km +72 -0
- package/examples/use-config.mjs +141 -0
- package/examples/use_config.km +13 -0
- package/install.sh +59 -0
- package/package.json +29 -0
- package/pantry/acorn/index.km +1 -0
- package/pantry/is_number/index.km +1 -0
- package/pantry/is_odd/index.km +2 -0
- package/project.static +6 -0
- package/src/cli.js +1245 -0
- package/src/generator.js +1241 -0
- package/src/index.js +141 -0
- package/src/js2km.js +568 -0
- package/src/lexer.js +822 -0
- package/src/linter.js +810 -0
- package/src/package-manager.js +307 -0
- package/src/parser.js +1876 -0
- package/src/static-parser.js +500 -0
- package/src/typechecker.js +950 -0
- package/stdlib/array.km +0 -0
- package/stdlib/bitwise.km +38 -0
- package/stdlib/console.km +49 -0
- package/stdlib/date.km +97 -0
- package/stdlib/function.km +44 -0
- package/stdlib/http.km +197 -0
- package/stdlib/http.md +333 -0
- package/stdlib/index.km +26 -0
- package/stdlib/json.km +17 -0
- package/stdlib/logger.js +114 -0
- package/stdlib/logger.km +104 -0
- package/stdlib/math.km +120 -0
- package/stdlib/object.km +41 -0
- package/stdlib/promise.km +33 -0
- package/stdlib/string.km +93 -0
- package/stdlib/testing.md +265 -0
- package/test/test.js +599 -0
package/stdlib/array.km
ADDED
|
File without changes
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// KimchiLang Bitwise Operations
|
|
2
|
+
// Usage: as bit dep stdlib.bitwise
|
|
3
|
+
// Provides wrapper functions for JavaScript bitwise operators
|
|
4
|
+
|
|
5
|
+
// Bitwise AND: a & b
|
|
6
|
+
expose fn band(a, b) {
|
|
7
|
+
return js(a, b) { return a & b; }
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// Bitwise OR: a | b
|
|
11
|
+
expose fn bor(a, b) {
|
|
12
|
+
return js(a, b) { return a | b; }
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Bitwise XOR: a ^ b
|
|
16
|
+
expose fn bxor(a, b) {
|
|
17
|
+
return js(a, b) { return a ^ b; }
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Bitwise NOT: ~a
|
|
21
|
+
expose fn bnot(a) {
|
|
22
|
+
return js(a) { return ~a; }
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Left shift: a << b
|
|
26
|
+
expose fn lshift(a, b) {
|
|
27
|
+
return js(a, b) { return a << b; }
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Right shift (sign-propagating): a >> b
|
|
31
|
+
expose fn rshift(a, b) {
|
|
32
|
+
return js(a, b) { return a >> b; }
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Unsigned right shift: a >>> b
|
|
36
|
+
expose fn urshift(a, b) {
|
|
37
|
+
return js(a, b) { return a >>> b; }
|
|
38
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// KimchiLang Standard Library - Console Functions
|
|
2
|
+
|
|
3
|
+
expose fn _describe() {
|
|
4
|
+
return "Console/IO utilities: log, error, warn, table, etc."
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
expose fn log(message) {
|
|
8
|
+
console.log(message)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
expose fn error(message) {
|
|
12
|
+
console.error(message)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
expose fn warn(message) {
|
|
16
|
+
console.warn(message)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
expose fn info(message) {
|
|
20
|
+
console.info(message)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
expose fn debug(message) {
|
|
24
|
+
console.debug(message)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
expose fn table(data) {
|
|
28
|
+
console.table(data)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
expose fn clear() {
|
|
32
|
+
console.clear()
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
expose fn time(label) {
|
|
36
|
+
console.time(label)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
expose fn timeEnd(label) {
|
|
40
|
+
console.timeEnd(label)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
expose fn trace(message) {
|
|
44
|
+
console.trace(message)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
expose fn dir(obj) {
|
|
48
|
+
console.dir(obj)
|
|
49
|
+
}
|
package/stdlib/date.km
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// KimchiLang Standard Library - Date Functions
|
|
2
|
+
|
|
3
|
+
expose fn _describe() {
|
|
4
|
+
return "Date/time utilities: now, format, parse, diff, etc."
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
expose fn now() {
|
|
8
|
+
return Date.now()
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
expose fn create(value) {
|
|
12
|
+
return new Date(value)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
expose fn getYear(date) {
|
|
16
|
+
return date.getFullYear()
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
expose fn getMonth(date) {
|
|
20
|
+
return date.getMonth()
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
expose fn getDay(date) {
|
|
24
|
+
return date.getDate()
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
expose fn getDayOfWeek(date) {
|
|
28
|
+
return date.getDay()
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
expose fn getHours(date) {
|
|
32
|
+
return date.getHours()
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
expose fn getMinutes(date) {
|
|
36
|
+
return date.getMinutes()
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
expose fn getSeconds(date) {
|
|
40
|
+
return date.getSeconds()
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
expose fn getTime(date) {
|
|
44
|
+
return date.getTime()
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
expose fn toISO(date) {
|
|
48
|
+
return date.toISOString()
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
expose fn toLocaleDateString(date) {
|
|
52
|
+
return date.toDateString()
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
expose fn parse(str) {
|
|
56
|
+
return new Date(str)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
expose fn addMs(date, ms) {
|
|
60
|
+
return new Date(date.getTime() + ms)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
expose fn addSeconds(date, seconds) {
|
|
64
|
+
return new Date(date.getTime() + seconds * 1000)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
expose fn addMinutes(date, minutes) {
|
|
68
|
+
return new Date(date.getTime() + minutes * 60 * 1000)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
expose fn addHours(date, hours) {
|
|
72
|
+
return new Date(date.getTime() + hours * 60 * 60 * 1000)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
expose fn addDays(date, days) {
|
|
76
|
+
return new Date(date.getTime() + days * 24 * 60 * 60 * 1000)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
expose fn diffMs(date1, date2) {
|
|
80
|
+
return date1.getTime() - date2.getTime()
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
expose fn diffDays(date1, date2) {
|
|
84
|
+
return (date1.getTime() - date2.getTime()) / (24 * 60 * 60 * 1000)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
expose fn isBefore(date1, date2) {
|
|
88
|
+
return date1.getTime() < date2.getTime()
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
expose fn isAfter(date1, date2) {
|
|
92
|
+
return date1.getTime() > date2.getTime()
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
expose fn isSameDay(date1, date2) {
|
|
96
|
+
return date1.toDateString() == date2.toDateString()
|
|
97
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// KimchiLang Standard Library - Function Utilities
|
|
2
|
+
|
|
3
|
+
expose fn _describe() {
|
|
4
|
+
return "Function utilities: compose, pipe, identity, constant, etc."
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
expose fn identity(x) {
|
|
8
|
+
return x
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
expose fn constant(x) {
|
|
12
|
+
return () => x
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
expose fn negate(predicate) {
|
|
16
|
+
return (x) => !predicate(x)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
expose fn flip(f) {
|
|
20
|
+
return (a, b) => f(b, a)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
expose fn compose(f, g) {
|
|
24
|
+
return (x) => f(g(x))
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
expose fn pipe(f, g) {
|
|
28
|
+
return (x) => g(f(x))
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
expose fn tap(f) {
|
|
32
|
+
return (x) => {
|
|
33
|
+
f(x)
|
|
34
|
+
return x
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
expose fn unary(f) {
|
|
39
|
+
return (x) => f(x)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
expose fn binary(f) {
|
|
43
|
+
return (a, b) => f(a, b)
|
|
44
|
+
}
|
package/stdlib/http.km
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
// KimchiLang Standard Library - HTTP Client
|
|
2
|
+
// Wrapper for Node.js http/https modules with a simple, promise-based API
|
|
3
|
+
|
|
4
|
+
expose fn _describe() {
|
|
5
|
+
return "HTTP client: get, post, put, patch, delete, request"
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// Make an HTTP GET request
|
|
9
|
+
expose async fn get(url, options) {
|
|
10
|
+
return await request(url, { ...options, method: "GET" })
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// Make an HTTP POST request
|
|
14
|
+
expose async fn post(url, body, options) {
|
|
15
|
+
return await request(url, { ...options, method: "POST", body: body })
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Make an HTTP PUT request
|
|
19
|
+
expose async fn put(url, body, options) {
|
|
20
|
+
return await request(url, { ...options, method: "PUT", body: body })
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Make an HTTP PATCH request
|
|
24
|
+
expose async fn patch(url, body, options) {
|
|
25
|
+
return await request(url, { ...options, method: "PATCH", body: body })
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Make an HTTP DELETE request
|
|
29
|
+
expose async fn del(url, options) {
|
|
30
|
+
return await request(url, { ...options, method: "DELETE" })
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Generic HTTP request function
|
|
34
|
+
expose async fn request(url, options) {
|
|
35
|
+
dec opts = options ? options : {}
|
|
36
|
+
dec method = opts.method ? opts.method : "GET"
|
|
37
|
+
dec headers = opts.headers ? opts.headers : {}
|
|
38
|
+
dec body = opts.body
|
|
39
|
+
dec timeout = opts.timeout ? opts.timeout : 30000
|
|
40
|
+
|
|
41
|
+
// Auto-set content-type for JSON bodies
|
|
42
|
+
dec finalHeaders = body and not headers["Content-Type"]
|
|
43
|
+
? { ...headers, "Content-Type": "application/json" }
|
|
44
|
+
: headers
|
|
45
|
+
|
|
46
|
+
dec result = js(url, method, finalHeaders, body, timeout) {
|
|
47
|
+
return new Promise((resolve, reject) => {
|
|
48
|
+
const urlObj = new URL(url);
|
|
49
|
+
const isHttps = urlObj.protocol === 'https:';
|
|
50
|
+
const lib = isHttps ? require('https') : require('http');
|
|
51
|
+
|
|
52
|
+
const reqOptions = {
|
|
53
|
+
hostname: urlObj.hostname,
|
|
54
|
+
port: urlObj.port || (isHttps ? 443 : 80),
|
|
55
|
+
path: urlObj.pathname + urlObj.search,
|
|
56
|
+
method: method,
|
|
57
|
+
headers: finalHeaders,
|
|
58
|
+
timeout: timeout,
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const req = lib.request(reqOptions, (res) => {
|
|
62
|
+
let data = '';
|
|
63
|
+
res.on('data', chunk => data += chunk);
|
|
64
|
+
res.on('end', () => {
|
|
65
|
+
let parsedBody = data;
|
|
66
|
+
const contentType = res.headers['content-type'] || '';
|
|
67
|
+
if (contentType.includes('application/json')) {
|
|
68
|
+
try {
|
|
69
|
+
parsedBody = JSON.parse(data);
|
|
70
|
+
} catch (e) {
|
|
71
|
+
// Keep as string if JSON parse fails
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
resolve({
|
|
75
|
+
status: res.statusCode,
|
|
76
|
+
statusText: res.statusMessage,
|
|
77
|
+
headers: res.headers,
|
|
78
|
+
body: parsedBody,
|
|
79
|
+
ok: res.statusCode >= 200 && res.statusCode < 300,
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
req.on('error', (e) => reject(e));
|
|
85
|
+
req.on('timeout', () => {
|
|
86
|
+
req.destroy();
|
|
87
|
+
reject(new Error('Request timeout'));
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
if (body) {
|
|
91
|
+
const bodyStr = typeof body === 'string' ? body : JSON.stringify(body);
|
|
92
|
+
req.write(bodyStr);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
req.end();
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return result
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Helper to build query strings
|
|
103
|
+
expose fn queryString(params) {
|
|
104
|
+
dec result = js(params) {
|
|
105
|
+
return Object.entries(params)
|
|
106
|
+
.map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`)
|
|
107
|
+
.join('&');
|
|
108
|
+
}
|
|
109
|
+
return result
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Helper to build URL with query params
|
|
113
|
+
expose fn buildUrl(baseUrl, params) {
|
|
114
|
+
dec qs = queryString(params)
|
|
115
|
+
if qs {
|
|
116
|
+
return "${baseUrl}?${qs}"
|
|
117
|
+
}
|
|
118
|
+
return baseUrl
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Create a client with default options (base URL, headers, etc.)
|
|
122
|
+
expose fn createClient(baseOptions) {
|
|
123
|
+
dec baseUrl = baseOptions.baseUrl ? baseOptions.baseUrl : ""
|
|
124
|
+
dec defaultHeaders = baseOptions.headers ? baseOptions.headers : {}
|
|
125
|
+
dec defaultTimeout = baseOptions.timeout ? baseOptions.timeout : 30000
|
|
126
|
+
|
|
127
|
+
dec clientGet = (path, options) => {
|
|
128
|
+
dec url = "${baseUrl}${path}"
|
|
129
|
+
dec opts = options ? options : {}
|
|
130
|
+
dec mergedHeaders = { ...defaultHeaders, ...(opts.headers ? opts.headers : {}) }
|
|
131
|
+
return request(url, {
|
|
132
|
+
...opts,
|
|
133
|
+
method: "GET",
|
|
134
|
+
headers: mergedHeaders,
|
|
135
|
+
timeout: opts.timeout ? opts.timeout : defaultTimeout
|
|
136
|
+
})
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
dec clientPost = (path, body, options) => {
|
|
140
|
+
dec url = "${baseUrl}${path}"
|
|
141
|
+
dec opts = options ? options : {}
|
|
142
|
+
dec mergedHeaders = { ...defaultHeaders, ...(opts.headers ? opts.headers : {}) }
|
|
143
|
+
return request(url, {
|
|
144
|
+
...opts,
|
|
145
|
+
method: "POST",
|
|
146
|
+
body: body,
|
|
147
|
+
headers: mergedHeaders,
|
|
148
|
+
timeout: opts.timeout ? opts.timeout : defaultTimeout
|
|
149
|
+
})
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
dec clientPut = (path, body, options) => {
|
|
153
|
+
dec url = "${baseUrl}${path}"
|
|
154
|
+
dec opts = options ? options : {}
|
|
155
|
+
dec mergedHeaders = { ...defaultHeaders, ...(opts.headers ? opts.headers : {}) }
|
|
156
|
+
return request(url, {
|
|
157
|
+
...opts,
|
|
158
|
+
method: "PUT",
|
|
159
|
+
body: body,
|
|
160
|
+
headers: mergedHeaders,
|
|
161
|
+
timeout: opts.timeout ? opts.timeout : defaultTimeout
|
|
162
|
+
})
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
dec clientPatch = (path, body, options) => {
|
|
166
|
+
dec url = "${baseUrl}${path}"
|
|
167
|
+
dec opts = options ? options : {}
|
|
168
|
+
dec mergedHeaders = { ...defaultHeaders, ...(opts.headers ? opts.headers : {}) }
|
|
169
|
+
return request(url, {
|
|
170
|
+
...opts,
|
|
171
|
+
method: "PATCH",
|
|
172
|
+
body: body,
|
|
173
|
+
headers: mergedHeaders,
|
|
174
|
+
timeout: opts.timeout ? opts.timeout : defaultTimeout
|
|
175
|
+
})
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
dec clientDel = (path, options) => {
|
|
179
|
+
dec url = "${baseUrl}${path}"
|
|
180
|
+
dec opts = options ? options : {}
|
|
181
|
+
dec mergedHeaders = { ...defaultHeaders, ...(opts.headers ? opts.headers : {}) }
|
|
182
|
+
return request(url, {
|
|
183
|
+
...opts,
|
|
184
|
+
method: "DELETE",
|
|
185
|
+
headers: mergedHeaders,
|
|
186
|
+
timeout: opts.timeout ? opts.timeout : defaultTimeout
|
|
187
|
+
})
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
return {
|
|
191
|
+
get: clientGet,
|
|
192
|
+
post: clientPost,
|
|
193
|
+
put: clientPut,
|
|
194
|
+
patch: clientPatch,
|
|
195
|
+
del: clientDel
|
|
196
|
+
}
|
|
197
|
+
}
|