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
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// Example: Async pipe (~>) and flow (>>) operators
|
|
2
|
+
// These operators now support async functions seamlessly
|
|
3
|
+
|
|
4
|
+
// Sync functions work as before
|
|
5
|
+
fn double(x) { return x * 2 }
|
|
6
|
+
fn addOne(x) { return x + 1 }
|
|
7
|
+
fn square(x) { return x * x }
|
|
8
|
+
|
|
9
|
+
// Async functions - simulate API calls with delays
|
|
10
|
+
async fn fetchUser(id) {
|
|
11
|
+
// Simulate async operation
|
|
12
|
+
return { id: id, name: "User" + id }
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async fn enrichUser(user) {
|
|
16
|
+
// Simulate enriching user data
|
|
17
|
+
return { ...user, email: user.name + "@example.com" }
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async fn formatUser(user) {
|
|
21
|
+
return "Name: " + user.name + ", Email: " + user.email
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Main async function to demonstrate the operators
|
|
25
|
+
async fn main() {
|
|
26
|
+
print "=== Async Pipe Operator (~>) ==="
|
|
27
|
+
|
|
28
|
+
// Pipe with async functions - each step is awaited
|
|
29
|
+
dec userInfo = await (1 ~> fetchUser ~> enrichUser ~> formatUser)
|
|
30
|
+
print userInfo
|
|
31
|
+
|
|
32
|
+
// Mixed sync and async in pipe chain
|
|
33
|
+
dec result = await (5 ~> double ~> addOne)
|
|
34
|
+
print "5 ~> double ~> addOne = ${result}"
|
|
35
|
+
|
|
36
|
+
print ""
|
|
37
|
+
print "=== Async Flow Operator (>>) ==="
|
|
38
|
+
|
|
39
|
+
// Flow creates a reusable async composed function
|
|
40
|
+
processUser >> fetchUser enrichUser formatUser
|
|
41
|
+
|
|
42
|
+
// Call the composed function - it's async so we await it
|
|
43
|
+
dec user1 = await processUser(1)
|
|
44
|
+
dec user2 = await processUser(2)
|
|
45
|
+
print "User 1: ${user1}"
|
|
46
|
+
print "User 2: ${user2}"
|
|
47
|
+
|
|
48
|
+
// Flow with sync functions also works
|
|
49
|
+
transform >> double addOne square
|
|
50
|
+
dec transformed = await transform(5)
|
|
51
|
+
print "transform(5) = ${transformed}"
|
|
52
|
+
|
|
53
|
+
print ""
|
|
54
|
+
print "Done!"
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Run the main function
|
|
58
|
+
main()
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// KimchiLang Basic Examples
|
|
2
|
+
// This file demonstrates the core features of KimchiLang
|
|
3
|
+
|
|
4
|
+
// Variables (all immutable with dec)
|
|
5
|
+
dec name = "World"
|
|
6
|
+
dec PI = 3.14159
|
|
7
|
+
|
|
8
|
+
// Print statement (convenience syntax)
|
|
9
|
+
print "Hello, KimchiLang!"
|
|
10
|
+
print name
|
|
11
|
+
|
|
12
|
+
// Functions
|
|
13
|
+
fn greet(person) {
|
|
14
|
+
return "Hello, " + person + "!"
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
fn add(a, b) {
|
|
18
|
+
return a + b
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
print greet("Alice")
|
|
22
|
+
print add(5, 3)
|
|
23
|
+
|
|
24
|
+
// Arrow functions
|
|
25
|
+
dec double = x => x * 2
|
|
26
|
+
dec multiply = (a, b) => a * b
|
|
27
|
+
|
|
28
|
+
print double(21)
|
|
29
|
+
print multiply(6, 7)
|
|
30
|
+
|
|
31
|
+
// Arrays
|
|
32
|
+
dec numbers = [1, 2, 3, 4, 5]
|
|
33
|
+
dec fruits = ["apple", "banana", "cherry"]
|
|
34
|
+
|
|
35
|
+
print numbers
|
|
36
|
+
print fruits[0]
|
|
37
|
+
|
|
38
|
+
// Objects
|
|
39
|
+
dec person = {
|
|
40
|
+
name: "Bob",
|
|
41
|
+
age: 30,
|
|
42
|
+
city: "New York"
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
print person.name
|
|
46
|
+
print person["age"]
|
|
47
|
+
|
|
48
|
+
// Control flow - If/Else
|
|
49
|
+
dec score = 85
|
|
50
|
+
|
|
51
|
+
if score >= 90 {
|
|
52
|
+
print "Grade: A"
|
|
53
|
+
} elif score >= 80 {
|
|
54
|
+
print "Grade: B"
|
|
55
|
+
} elif score >= 70 {
|
|
56
|
+
print "Grade: C"
|
|
57
|
+
} else {
|
|
58
|
+
print "Grade: F"
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Loops - For (immutable iteration)
|
|
62
|
+
for item in fruits {
|
|
63
|
+
print item
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Range expressions
|
|
67
|
+
for i in 0..5 {
|
|
68
|
+
print i
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Flow operator - creates a composed function
|
|
72
|
+
fn addOne(x) {
|
|
73
|
+
return x + 1
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
fn square(x) {
|
|
77
|
+
return x * x
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
transform >> addOne square
|
|
81
|
+
dec result = transform(5)
|
|
82
|
+
print "transform(5) = ${result}"
|
|
83
|
+
|
|
84
|
+
// Pipe operator - immediate execution
|
|
85
|
+
dec pipeResult = 5 ~> addOne ~> square
|
|
86
|
+
print "5 ~> addOne ~> square = ${pipeResult}"
|
|
87
|
+
|
|
88
|
+
// Ternary operator
|
|
89
|
+
dec age = 20
|
|
90
|
+
dec status = age >= 18 ? "adult" : "minor"
|
|
91
|
+
print status
|
|
92
|
+
|
|
93
|
+
// Spread operator
|
|
94
|
+
dec arr1 = [1, 2, 3]
|
|
95
|
+
dec arr2 = [...arr1, 4, 5, 6]
|
|
96
|
+
print arr2
|
|
97
|
+
|
|
98
|
+
// Try/Catch
|
|
99
|
+
fn riskyOperation() {
|
|
100
|
+
throw "Something went wrong!"
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
try {
|
|
104
|
+
riskyOperation()
|
|
105
|
+
} catch(e) {
|
|
106
|
+
print "Caught error: " + e
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
print "Program completed successfully!"
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# KimchiLang as a CLI Framework
|
|
2
|
+
|
|
3
|
+
KimchiLang's built-in module system makes it an excellent choice for building CLI tools. This directory contains examples demonstrating CLI patterns.
|
|
4
|
+
|
|
5
|
+
## Features for CLI Development
|
|
6
|
+
|
|
7
|
+
- **`arg` / `!arg`** - Declare optional and required arguments
|
|
8
|
+
- **`_describe()`** - Provide module description for help output
|
|
9
|
+
- **Module paths** - Run modules with `kimchi module.path`
|
|
10
|
+
- **Named args** - Pass `--arg-name value` from command line
|
|
11
|
+
- **Dependency injection** - Mock dependencies for testing
|
|
12
|
+
|
|
13
|
+
## Examples
|
|
14
|
+
|
|
15
|
+
### 1. Simple Greeter (`greeter.km`)
|
|
16
|
+
|
|
17
|
+
A basic CLI tool with required and optional arguments:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
kimchi cli-framework.greeter --name Alice
|
|
21
|
+
kimchi cli-framework.greeter --name Bob --greeting "Hey there" --times 3
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### 2. Calculator (`calculator.km`)
|
|
25
|
+
|
|
26
|
+
A calculator with multiple operations:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
kimchi cli-framework.calculator --op add --a 5 --b 3
|
|
30
|
+
kimchi cli-framework.calculator --op multiply --a 7 --b 6
|
|
31
|
+
kimchi cli-framework.calculator --op divide --a 100 --b 4
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### 3. Deploy Tool (`deploy.km`)
|
|
35
|
+
|
|
36
|
+
A deployment tool showing multi-action patterns with environment configuration:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
kimchi cli-framework.deploy --action build
|
|
40
|
+
kimchi cli-framework.deploy --action test
|
|
41
|
+
kimchi cli-framework.deploy --action publish --target-env production --verbose true
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Running Examples
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
kimchi cli-framework.greeter --name World
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## CLI Patterns
|
|
51
|
+
|
|
52
|
+
### Required vs Optional Arguments
|
|
53
|
+
|
|
54
|
+
```kimchi
|
|
55
|
+
!arg name // Required - throws error if missing
|
|
56
|
+
arg greeting // Optional - undefined if not provided
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Handling Defaults
|
|
60
|
+
|
|
61
|
+
Since CLI args come as strings, handle defaults explicitly:
|
|
62
|
+
|
|
63
|
+
```kimchi
|
|
64
|
+
!arg name
|
|
65
|
+
arg greeting
|
|
66
|
+
arg times
|
|
67
|
+
|
|
68
|
+
dec actualGreeting = greeting ? greeting : "Hello"
|
|
69
|
+
dec actualTimes = times ? Number(times) : 1
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Boolean Flags
|
|
73
|
+
|
|
74
|
+
Boolean args from CLI come as strings:
|
|
75
|
+
|
|
76
|
+
```kimchi
|
|
77
|
+
arg verbose
|
|
78
|
+
arg dryRun
|
|
79
|
+
|
|
80
|
+
dec isVerbose = verbose == "true" || verbose == true
|
|
81
|
+
dec isDryRun = dryRun == "true" || dryRun == true
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Module Description
|
|
85
|
+
|
|
86
|
+
Provide a `_describe()` function for help output:
|
|
87
|
+
|
|
88
|
+
```kimchi
|
|
89
|
+
expose fn _describe() {
|
|
90
|
+
return "A brief description of what this CLI does"
|
|
91
|
+
}
|
|
92
|
+
```
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// Calculator CLI
|
|
2
|
+
// Usage: kimchi cli-framework.calculator --op add --a 5 --b 3
|
|
3
|
+
// kimchi cli-framework.calculator --op multiply --a 7 --b 6
|
|
4
|
+
|
|
5
|
+
expose fn _describe() {
|
|
6
|
+
return "A simple calculator CLI with basic operations"
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// Arguments
|
|
10
|
+
!arg op
|
|
11
|
+
!arg a
|
|
12
|
+
!arg b
|
|
13
|
+
|
|
14
|
+
// Convert string args to numbers
|
|
15
|
+
dec numA = Number(a)
|
|
16
|
+
dec numB = Number(b)
|
|
17
|
+
|
|
18
|
+
// Operations
|
|
19
|
+
fn doAdd() {
|
|
20
|
+
dec result = numA + numB
|
|
21
|
+
print "${numA} + ${numB} = ${result}"
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
fn doSubtract() {
|
|
25
|
+
dec result = numA - numB
|
|
26
|
+
print "${numA} - ${numB} = ${result}"
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
fn doMultiply() {
|
|
30
|
+
dec result = numA * numB
|
|
31
|
+
print "${numA} × ${numB} = ${result}"
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
fn doDivide() {
|
|
35
|
+
if numB == 0 {
|
|
36
|
+
print "Error: Cannot divide by zero"
|
|
37
|
+
return null
|
|
38
|
+
}
|
|
39
|
+
dec result = numA / numB
|
|
40
|
+
print "${numA} ÷ ${numB} = ${result}"
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
fn showHelp() {
|
|
44
|
+
print "Unknown operation: ${op}"
|
|
45
|
+
print ""
|
|
46
|
+
print "Available operations:"
|
|
47
|
+
print " add - Add two numbers"
|
|
48
|
+
print " subtract - Subtract b from a"
|
|
49
|
+
print " multiply - Multiply two numbers"
|
|
50
|
+
print " divide - Divide a by b"
|
|
51
|
+
print ""
|
|
52
|
+
print "Example:"
|
|
53
|
+
print " kimchi cli-framework.calculator --op add --a 10 --b 5"
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Dispatch
|
|
57
|
+
|op == "add"| => { doAdd() }
|
|
58
|
+
|op == "subtract"| => { doSubtract() }
|
|
59
|
+
|op == "multiply"| => { doMultiply() }
|
|
60
|
+
|op == "divide"| => { doDivide() }
|
|
61
|
+
|true| => { showHelp() }
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// Deploy CLI - Multi-Action Tool
|
|
2
|
+
// Usage: kimchi cli-framework.deploy --action build
|
|
3
|
+
// kimchi cli-framework.deploy --action test
|
|
4
|
+
// kimchi cli-framework.deploy --action publish --targetEnv production
|
|
5
|
+
|
|
6
|
+
expose fn _describe() {
|
|
7
|
+
return "A deployment tool with multiple actions (build, test, publish)"
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// Arguments
|
|
11
|
+
!arg action
|
|
12
|
+
arg targetEnv
|
|
13
|
+
arg verbose
|
|
14
|
+
arg dryRun
|
|
15
|
+
|
|
16
|
+
// Handle defaults
|
|
17
|
+
dec targetEnvironment = targetEnv ? targetEnv : "development"
|
|
18
|
+
dec isVerbose = verbose == "true" || verbose == true
|
|
19
|
+
dec isDryRun = dryRun == "true" || dryRun == true
|
|
20
|
+
|
|
21
|
+
// Configuration based on environment
|
|
22
|
+
dec config = {
|
|
23
|
+
development: {
|
|
24
|
+
url: "http://localhost:3000",
|
|
25
|
+
minify: false,
|
|
26
|
+
sourceMaps: true
|
|
27
|
+
},
|
|
28
|
+
staging: {
|
|
29
|
+
url: "https://staging.example.com",
|
|
30
|
+
minify: true,
|
|
31
|
+
sourceMaps: true
|
|
32
|
+
},
|
|
33
|
+
production: {
|
|
34
|
+
url: "https://example.com",
|
|
35
|
+
minify: true,
|
|
36
|
+
sourceMaps: false
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
dec envConfig = config[targetEnvironment]
|
|
41
|
+
|
|
42
|
+
// Action handlers
|
|
43
|
+
fn handleBuild() {
|
|
44
|
+
print "🔨 Building for ${targetEnvironment}..."
|
|
45
|
+
if isVerbose {
|
|
46
|
+
print " Minify: ${envConfig.minify}"
|
|
47
|
+
print " Source maps: ${envConfig.sourceMaps}"
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if isDryRun {
|
|
51
|
+
print " [DRY RUN] Would compile source files"
|
|
52
|
+
print " [DRY RUN] Would bundle assets"
|
|
53
|
+
} else {
|
|
54
|
+
// Simulate build steps
|
|
55
|
+
print " ✓ Compiled source files"
|
|
56
|
+
print " ✓ Bundled assets"
|
|
57
|
+
print " ✓ Generated output"
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
print "✅ Build complete!"
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
fn handleTest() {
|
|
64
|
+
print "🧪 Running tests..."
|
|
65
|
+
|
|
66
|
+
if isDryRun {
|
|
67
|
+
print " [DRY RUN] Would run unit tests"
|
|
68
|
+
print " [DRY RUN] Would run integration tests"
|
|
69
|
+
} else {
|
|
70
|
+
// Simulate test execution
|
|
71
|
+
print " ✓ Unit tests: 42 passed"
|
|
72
|
+
print " ✓ Integration tests: 15 passed"
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
print "✅ All tests passed!"
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
fn handlePublish() {
|
|
79
|
+
print "🚀 Publishing to ${targetEnvironment}..."
|
|
80
|
+
print " Target: ${envConfig.url}"
|
|
81
|
+
|
|
82
|
+
if targetEnvironment == "production" {
|
|
83
|
+
print " ⚠️ WARNING: Publishing to PRODUCTION!"
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if isDryRun {
|
|
87
|
+
print " [DRY RUN] Would upload build artifacts"
|
|
88
|
+
print " [DRY RUN] Would invalidate cache"
|
|
89
|
+
print " [DRY RUN] Would notify team"
|
|
90
|
+
} else {
|
|
91
|
+
print " ✓ Uploaded build artifacts"
|
|
92
|
+
print " ✓ Invalidated CDN cache"
|
|
93
|
+
print " ✓ Notified team via Slack"
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
print "✅ Published successfully!"
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
fn showHelp() {
|
|
100
|
+
print "Unknown action: ${action}"
|
|
101
|
+
print ""
|
|
102
|
+
print "Available actions:"
|
|
103
|
+
print " build - Compile and bundle the application"
|
|
104
|
+
print " test - Run the test suite"
|
|
105
|
+
print " publish - Deploy to the target environment"
|
|
106
|
+
print ""
|
|
107
|
+
print "Examples:"
|
|
108
|
+
print " kimchi cli-framework.deploy --action build"
|
|
109
|
+
print " kimchi cli-framework.deploy --action publish --target-env production"
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Main dispatch
|
|
113
|
+
print "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
114
|
+
print " Deploy Tool v1.0"
|
|
115
|
+
print " Environment: ${targetEnvironment}"
|
|
116
|
+
if isDryRun {
|
|
117
|
+
print " Mode: DRY RUN"
|
|
118
|
+
}
|
|
119
|
+
print "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
120
|
+
print ""
|
|
121
|
+
|
|
122
|
+
// Dispatch action
|
|
123
|
+
|action == "build"| => { handleBuild() }
|
|
124
|
+
|action == "test"| => { handleTest() }
|
|
125
|
+
|action == "publish"| => { handlePublish() }
|
|
126
|
+
|true| => { showHelp() }
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Simple Greeter CLI
|
|
2
|
+
// Usage: kimchi cli-framework.greeter --name Alice
|
|
3
|
+
// kimchi cli-framework.greeter --name Bob --greeting "Hey there"
|
|
4
|
+
|
|
5
|
+
// Module description (shown in `kimchi help`)
|
|
6
|
+
expose fn _describe() {
|
|
7
|
+
return "A simple greeter CLI tool"
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// Arguments
|
|
11
|
+
!arg name
|
|
12
|
+
arg greeting
|
|
13
|
+
arg times
|
|
14
|
+
|
|
15
|
+
// Main logic
|
|
16
|
+
dec actualGreeting = greeting ? greeting : "Hello"
|
|
17
|
+
dec actualTimes = times ? times : 1
|
|
18
|
+
|
|
19
|
+
fn greet() {
|
|
20
|
+
for i in 0..actualTimes {
|
|
21
|
+
print "${actualGreeting}, ${name}!"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Run on module load
|
|
26
|
+
greet()
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// Example static file with arrays, objects, and enums
|
|
2
|
+
|
|
3
|
+
Colors [
|
|
4
|
+
"red"
|
|
5
|
+
"green"
|
|
6
|
+
"blue"
|
|
7
|
+
"yellow"
|
|
8
|
+
]
|
|
9
|
+
|
|
10
|
+
AppConfig {
|
|
11
|
+
name = "MyApp"
|
|
12
|
+
version = "1.0.0"
|
|
13
|
+
debug = true
|
|
14
|
+
maxRetries = 3
|
|
15
|
+
testing = {
|
|
16
|
+
enabled = true
|
|
17
|
+
retries = 2
|
|
18
|
+
timeout = 5000
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
HttpStatus `STATUS_OK = 200, STATUS_NOT_FOUND = 404, STATUS_ERROR = 500`
|
|
23
|
+
|
|
24
|
+
Endpoints {
|
|
25
|
+
api = "https://api.example.com"
|
|
26
|
+
auth = "https://auth.example.com"
|
|
27
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Generated from .static file
|
|
2
|
+
|
|
3
|
+
export const Colors = ["red", "green", "blue", "yellow"];
|
|
4
|
+
|
|
5
|
+
export const AppConfig = { name: "MyApp", version: "1.0.0", debug: true, maxRetries: 3 };
|
|
6
|
+
|
|
7
|
+
export const HttpStatus = Object.freeze({ STATUS_OK: 200, STATUS_NOT_FOUND: 404, STATUS_ERROR: 500 });
|
|
8
|
+
|
|
9
|
+
export const Endpoints = { api: "https://api.example.com", auth: "https://auth.example.com" };
|
|
10
|
+
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// Test file for env, arg, and secret keywords
|
|
2
|
+
// Demonstrates: env, !env, arg, secret
|
|
3
|
+
|
|
4
|
+
// Arguments
|
|
5
|
+
arg name = "World"
|
|
6
|
+
secret arg password = "default-pass"
|
|
7
|
+
|
|
8
|
+
// Environment variables
|
|
9
|
+
env HOME
|
|
10
|
+
env DEBUG = "false"
|
|
11
|
+
|
|
12
|
+
// Secret env var - will be masked when printed
|
|
13
|
+
secret env API_TOKEN = "default-token-123"
|
|
14
|
+
|
|
15
|
+
// Secret dec - will be masked when printed
|
|
16
|
+
secret dec apiKey = "sk-12345-secret-key"
|
|
17
|
+
|
|
18
|
+
// Normal dec for comparison
|
|
19
|
+
dec normalValue = "visible-value"
|
|
20
|
+
|
|
21
|
+
print "=== Arguments ==="
|
|
22
|
+
print "Name: ${name}"
|
|
23
|
+
print "Password: ${password}"
|
|
24
|
+
|
|
25
|
+
print ""
|
|
26
|
+
print "=== Environment Variables ==="
|
|
27
|
+
print "HOME: ${HOME}"
|
|
28
|
+
print "DEBUG: ${DEBUG}"
|
|
29
|
+
|
|
30
|
+
print ""
|
|
31
|
+
print "=== Secret Values (should be masked) ==="
|
|
32
|
+
print "API Token: ${API_TOKEN}"
|
|
33
|
+
print "API Key: ${apiKey}"
|
|
34
|
+
|
|
35
|
+
print ""
|
|
36
|
+
print "=== Normal Values (should be visible) ==="
|
|
37
|
+
print "Normal: ${normalValue}"
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Fibonacci sequence in KimchiLang
|
|
2
|
+
|
|
3
|
+
fn fibonacci(n) {
|
|
4
|
+
if n <= 1 {
|
|
5
|
+
return n
|
|
6
|
+
}
|
|
7
|
+
return fibonacci(n - 1) + fibonacci(n - 2)
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// Print first 10 fibonacci numbers
|
|
11
|
+
print "Fibonacci Sequence:"
|
|
12
|
+
for i in 0..10 {
|
|
13
|
+
print fibonacci(i)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
print "Fibonacci of 15:"
|
|
17
|
+
print fibonacci(15)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
console.log("Hello, World!");
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// JavaScript Interop Examples
|
|
2
|
+
|
|
3
|
+
// Simple JS block (no inputs)
|
|
4
|
+
js {
|
|
5
|
+
console.log("Hello from raw JavaScript!");
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// JS block with inputs from kimchi scope
|
|
9
|
+
dec name = "Alice"
|
|
10
|
+
dec count = 5
|
|
11
|
+
|
|
12
|
+
js(name, count) {
|
|
13
|
+
const greeting = `Hello, ${name}! Count: ${count}`;
|
|
14
|
+
console.log(greeting);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// JS block as expression - returns a value
|
|
18
|
+
dec doubled = js(count) {
|
|
19
|
+
return count * 2;
|
|
20
|
+
}
|
|
21
|
+
print "Doubled: ${doubled}"
|
|
22
|
+
|
|
23
|
+
// Using JS for complex operations
|
|
24
|
+
dec numbers = [1, 2, 3, 4, 5]
|
|
25
|
+
dec sum = js(numbers) {
|
|
26
|
+
return numbers.reduce((a, b) => a + b, 0);
|
|
27
|
+
}
|
|
28
|
+
print "Sum: ${sum}"
|
|
29
|
+
|
|
30
|
+
// Accessing JS libraries
|
|
31
|
+
dec timestamp = js {
|
|
32
|
+
return Date.now();
|
|
33
|
+
}
|
|
34
|
+
print "Timestamp: ${timestamp}"
|
|
35
|
+
|
|
36
|
+
// Complex JS with multiple statements
|
|
37
|
+
dec result = js(name) {
|
|
38
|
+
const upper = name.toUpperCase();
|
|
39
|
+
const reversed = upper.split('').reverse().join('');
|
|
40
|
+
return reversed;
|
|
41
|
+
}
|
|
42
|
+
print "Reversed uppercase: ${result}"
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Logger Example
|
|
2
|
+
// Demonstrates structured JSON logging with log levels
|
|
3
|
+
|
|
4
|
+
// Import the logger from stdlib
|
|
5
|
+
as log dep stdlib.logger
|
|
6
|
+
|
|
7
|
+
// Basic logging at different levels
|
|
8
|
+
log.info("Application started")
|
|
9
|
+
log.debug("Debug information", { userId: 123 })
|
|
10
|
+
log.warn("This is a warning")
|
|
11
|
+
log.error("Something went wrong", { code: "ERR_001" })
|
|
12
|
+
|
|
13
|
+
// Create a child logger with context
|
|
14
|
+
dec userLog = log.child({ userId: 456, session: "abc123" })
|
|
15
|
+
userLog.info("User logged in")
|
|
16
|
+
userLog.debug("Processing request")
|
|
17
|
+
|
|
18
|
+
// Function that uses logging
|
|
19
|
+
fn processOrder(orderId) {
|
|
20
|
+
log.info("Processing order", { orderId: orderId })
|
|
21
|
+
|
|
22
|
+
// Simulate some work
|
|
23
|
+
log.debug("Validating order")
|
|
24
|
+
log.debug("Charging payment")
|
|
25
|
+
|
|
26
|
+
log.info("Order completed", { orderId: orderId, status: "success" })
|
|
27
|
+
return true
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
processOrder(789)
|
|
31
|
+
|
|
32
|
+
// To test different log levels, run with:
|
|
33
|
+
// LOG_LEVEL=debug kimchi examples/logger-example.km
|
|
34
|
+
// LOG_LEVEL=warn kimchi examples/logger-example.km
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Memoized Fibonacci - demonstrates the memo keyword
|
|
2
|
+
|
|
3
|
+
memo fibonacci(n) {
|
|
4
|
+
if n <= 1 {
|
|
5
|
+
return n
|
|
6
|
+
}
|
|
7
|
+
return fibonacci(n - 1) + fibonacci(n - 2)
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// This would be slow without memoization, but with memo it's fast
|
|
11
|
+
print "Memoized Fibonacci Sequence:"
|
|
12
|
+
for i in 0..20 {
|
|
13
|
+
print "fib(${i}) = ${fibonacci(i)}"
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
print "\nFibonacci of 35 (would be slow without memo):"
|
|
17
|
+
print "fib(35) = ${fibonacci(35)}"
|