dirac-lang 0.1.23 → 0.1.25
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/dist/{chunk-APWJJXNI.js → chunk-7OUYWIZV.js} +55 -14
- package/dist/{chunk-RGS2XK6T.js → chunk-OUMUIBK3.js} +1 -1
- package/dist/cli.js +15 -3
- package/dist/index.js +2 -2
- package/dist/{interpreter-UZDVASAW.js → interpreter-MTIIHIIQ.js} +1 -1
- package/dist/test-runner.js +1 -1
- package/lib/index.di +9 -0
- package/package.json +13 -1
- package/.env.example +0 -8
- package/COMMUNITY.md +0 -465
- package/CONDITIONAL-TAGS.md +0 -172
- package/EXCEPTION-HANDLING.md +0 -156
- package/LIBRARIES.md +0 -172
- package/LLM-VALIDATION.md +0 -128
- package/NAMESPACES.md +0 -366
- package/PROMOTION.md +0 -257
- package/QUICKSTART-LIBRARY.md +0 -93
- package/TEST-COVERAGE.md +0 -113
- package/TESTING.md +0 -162
- package/config.test.yml +0 -5
- package/dirac-http/examples/demo.di +0 -9
- package/dirac-http/lib/index.di +0 -12
- package/examples/add-demo.di +0 -74
- package/examples/add.bk +0 -11
- package/examples/advanced-math-demo.di +0 -53
- package/examples/calculator.di +0 -32
- package/examples/compact-test.di +0 -6
- package/examples/comprehensive.bk +0 -29
- package/examples/defvar-variable-demo.di +0 -18
- package/examples/direct-call.di +0 -17
- package/examples/disk-analysis.di +0 -16
- package/examples/exception-demo.di +0 -82
- package/examples/executable-hello.di +0 -7
- package/examples/execute-demo.di +0 -38
- package/examples/file-manager.di +0 -77
- package/examples/file-stats.di +0 -18
- package/examples/hello.bk +0 -1
- package/examples/hello.di +0 -5
- package/examples/if-comparison.di +0 -91
- package/examples/if-cstyle-test.di +0 -149
- package/examples/if-vs-testif.di +0 -56
- package/examples/import-demo.di +0 -31
- package/examples/inline-test.bk +0 -7
- package/examples/llm-agent.di +0 -32
- package/examples/llm-basic.di +0 -12
- package/examples/llm-command-more.di +0 -6
- package/examples/llm-command-no-exec.di +0 -13
- package/examples/llm-command.di +0 -6
- package/examples/llm-complex.di +0 -141
- package/examples/llm-feedback-debug.di +0 -30
- package/examples/llm-feedback-demo.di +0 -19
- package/examples/llm-feedback-math.di +0 -22
- package/examples/llm-feedback-simple.di +0 -16
- package/examples/llm-feedback-sub.di +0 -22
- package/examples/llm-no-feedback.di +0 -10
- package/examples/llm-recursive.di +0 -31
- package/examples/llm-reflection-test.di +0 -19
- package/examples/llm-simple-test.di +0 -12
- package/examples/llm-subs.di +0 -132
- package/examples/llm-use-subs.di +0 -6
- package/examples/llm-validate-test.di +0 -18
- package/examples/loop.di +0 -12
- package/examples/math-test.di +0 -22
- package/examples/minimal-test.di +0 -13
- package/examples/mongodb-context-test.di +0 -27
- package/examples/mongodb-count-events.di +0 -8
- package/examples/mongodb-import-demo.di +0 -25
- package/examples/mongodb-simple-test.di +0 -18
- package/examples/nl-agent.di +0 -47
- package/examples/parameters-demo.di +0 -68
- package/examples/params-meta-test.di +0 -17
- package/examples/params-test.di +0 -10
- package/examples/recipe-chain.di +0 -38
- package/examples/recursive-llm.di +0 -44
- package/examples/sample-library/README.md +0 -152
- package/examples/sample-library/examples/demo.di +0 -34
- package/examples/sample-library/lib/index.di +0 -65
- package/examples/sample-library/package.json +0 -31
- package/examples/scope-test-nested.di +0 -60
- package/examples/scope-test.di +0 -55
- package/examples/seamless.di +0 -45
- package/examples/shell-test.bk +0 -10
- package/examples/simple-import.di +0 -13
- package/examples/simple-recursive.di +0 -26
- package/examples/story-builder.di +0 -45
- package/examples/subroutine.di +0 -23
- package/examples/system-llm.di +0 -21
- package/examples/system-simple.di +0 -3
- package/examples/system-test.di +0 -8
- package/examples/tag-check-test.di +0 -139
- package/examples/task-assistant.di +0 -27
- package/examples/test-if-demo.di +0 -110
- package/examples/test-parameters.di +0 -50
- package/examples/try-catch-test.di +0 -118
- package/examples/two-styles.di +0 -28
- package/examples/var-debug.di +0 -6
- package/examples/var-inline.di +0 -4
- package/examples/var-test2.di +0 -6
- package/examples/variable-replace.di +0 -25
- package/examples/variable-simple.di +0 -16
- package/examples/variable-test.di +0 -22
- package/examples/whitespace-test.di +0 -24
- package/filePath +0 -1
- package/greeting.txt +0 -1
- package/src/cli.ts +0 -140
- package/src/index.ts +0 -33
- package/src/llm/ollama.ts +0 -58
- package/src/runtime/braket-parser.ts +0 -234
- package/src/runtime/interpreter.ts +0 -203
- package/src/runtime/parser.ts +0 -155
- package/src/runtime/session.ts +0 -325
- package/src/tags/assign.ts +0 -37
- package/src/tags/attr.ts +0 -64
- package/src/tags/available-subroutines.ts +0 -70
- package/src/tags/call.ts +0 -259
- package/src/tags/catch.ts +0 -24
- package/src/tags/defvar.ts +0 -115
- package/src/tags/environment.ts +0 -21
- package/src/tags/eval.ts +0 -71
- package/src/tags/exception.ts +0 -20
- package/src/tags/execute.ts +0 -52
- package/src/tags/expr.ts +0 -128
- package/src/tags/foreach.ts +0 -170
- package/src/tags/if.ts +0 -191
- package/src/tags/import.ts +0 -66
- package/src/tags/index.ts +0 -41
- package/src/tags/input.ts +0 -182
- package/src/tags/llm.ts +0 -415
- package/src/tags/loop.ts +0 -43
- package/src/tags/mongodb.ts +0 -70
- package/src/tags/output.ts +0 -53
- package/src/tags/parameters.ts +0 -81
- package/src/tags/require_module.ts +0 -19
- package/src/tags/subroutine.ts +0 -75
- package/src/tags/system.ts +0 -93
- package/src/tags/tag-check.ts +0 -176
- package/src/tags/test-if.ts +0 -112
- package/src/tags/throw.ts +0 -26
- package/src/tags/try.ts +0 -19
- package/src/tags/variable.ts +0 -25
- package/src/test-runner.ts +0 -300
- package/src/types/index.ts +0 -128
- package/src/utils/llm-adapter.ts +0 -113
- package/src/utils/tag-validator.ts +0 -231
- package/test-available-extends.di +0 -28
- package/test-available-simple.di +0 -12
- package/test-available-subroutines.di +0 -16
- package/test-call.di +0 -9
- package/test-extend-basic.di +0 -17
- package/test-extend-chain.di +0 -26
- package/test-extend-debug.di +0 -17
- package/test-extend-debug2.di +0 -15
- package/test-extend-person.di +0 -17
- package/test-extend-simple.di +0 -11
- package/test-extend-zhi.di +0 -23
- package/test-extend.di +0 -19
- package/test-extend2.di +0 -26
- package/test-extend3-fixed.di +0 -23
- package/test-extend3-trouble.di +0 -23
- package/test-extend3.di +0 -21
- package/test-factorial.di +0 -19
- package/test-input-debug.di +0 -19
- package/test-nested-debug.di +0 -7
- package/test-nested-debug2.di +0 -8
- package/test-no-extend.di +0 -16
- package/test-simple-call.di +0 -7
- package/test-simple.di +0 -6
- package/tests/README.md +0 -69
- package/tests/assign-basic.test.di +0 -7
- package/tests/assign-from-eval.test.di +0 -7
- package/tests/available-subroutines-foreach.test.di +0 -32
- package/tests/basic-output.test.di +0 -5
- package/tests/call-basic.test.di +0 -11
- package/tests/call-with-output.test.di +0 -10
- package/tests/comments-before-content.test.di +0 -6
- package/tests/defvar-multiple.test.di +0 -8
- package/tests/environment-basic.test.di +0 -22
- package/tests/environment-nonexistent.test.di +0 -5
- package/tests/environment-with-defvar.test.di +0 -15
- package/tests/eval-basic.test.di +0 -6
- package/tests/eval-with-variables.test.di +0 -8
- package/tests/exception-basic.test.di +0 -10
- package/tests/expr-basic.test.di +0 -11
- package/tests/extend-basic.test.di +0 -19
- package/tests/extend-inheritance-chain.test.di +0 -26
- package/tests/extend-multiple-nested.test.di +0 -24
- package/tests/extend-self.test.di +0 -19
- package/tests/extend-with-parameters.test.di +0 -14
- package/tests/generate-dirac.test.di +0 -22
- package/tests/if-conditional.test.di +0 -17
- package/tests/if-else.test.di +0 -11
- package/tests/if-with-variables.test.di +0 -8
- package/tests/import-basic.test.di +0 -6
- package/tests/input-file-all.test.di +0 -5
- package/tests/input-file-line.test.di +0 -15
- package/tests/input-file-loop.test.di +0 -12
- package/tests/input-stdin-all.test.di +0 -8
- package/tests/input-stdin-all.txt +0 -1
- package/tests/llm-validate.test.di +0 -17
- package/tests/loop-basic.test.di +0 -9
- package/tests/loop-nested.test.di +0 -10
- package/tests/loop-with-eval.test.di +0 -8
- package/tests/no-root-element.test.di +0 -6
- package/tests/output-file.test.di +0 -19
- package/tests/output-multiple.test.di +0 -9
- package/tests/parameters-basic.test.di +0 -6
- package/tests/require-module-basic.test.di +0 -7
- package/tests/subroutine-basic.test.di +0 -9
- package/tests/subroutine-multiple-params.test.di +0 -10
- package/tests/subroutine-nested-calls.test.di +0 -32
- package/tests/subroutine-sequential-calls.test.di +0 -36
- package/tests/system-background.test.di +0 -39
- package/tests/system-basic.test.di +0 -5
- package/tests/tag-check.test.di +0 -27
- package/tests/test-if-basic.test.di +0 -8
- package/tests/test-input.txt +0 -3
- package/tests/try-catch-basic.test.di +0 -10
- package/tests/try-catch-eval-error.test.di +0 -10
- package/tests/variable-basic.test.di +0 -6
- package/tests/variable-interpolation.test.di +0 -7
- package/tools/create-library.sh +0 -175
- package/tsconfig.json +0 -19
- /package/{examples/lib → lib}/advanced-math.di +0 -0
- /package/{examples/lib → lib}/fileops.di +0 -0
- /package/{examples/lib → lib}/math.di +0 -0
- /package/{examples/lib → lib}/mongodb.di +0 -0
package/examples/nl-agent.di
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
<!-- Advanced Agent - Natural language to operations -->
|
|
2
|
-
<dirac>
|
|
3
|
-
<output>Interactive Agent Example </output>
|
|
4
|
-
|
|
5
|
-
<!-- Task 1: File operations -->
|
|
6
|
-
<defvar name="userRequest" value="count how many .di files are in examples directory" />
|
|
7
|
-
|
|
8
|
-
<output>Request: ${userRequest} </output>
|
|
9
|
-
<LLM output="code1" maxTokens="300">
|
|
10
|
-
Generate Dirac XML to: ${userRequest}
|
|
11
|
-
|
|
12
|
-
Use these tags ONLY:
|
|
13
|
-
1. <eval name="varname">return javascriptExpression;</eval>
|
|
14
|
-
2. <output>text with ${varname}</output>
|
|
15
|
-
|
|
16
|
-
Example:
|
|
17
|
-
<dirac>
|
|
18
|
-
<eval name="result">return fs.readdirSync('examples').filter(f => f.endsWith('.di')).length;</eval>
|
|
19
|
-
<output>Count: ${result}</output>
|
|
20
|
-
</dirac>
|
|
21
|
-
|
|
22
|
-
Return only XML, no markdown or explanations.
|
|
23
|
-
</LLM>
|
|
24
|
-
|
|
25
|
-
<output>Executing... </output>
|
|
26
|
-
<execute source="code1" />
|
|
27
|
-
<output> </output>
|
|
28
|
-
|
|
29
|
-
<!-- Task 2: Data processing -->
|
|
30
|
-
<assign name="userRequest" value="create a JSON file with current date and time" />
|
|
31
|
-
|
|
32
|
-
<output>Request: ${userRequest} </output>
|
|
33
|
-
<LLM output="code2" maxTokens="300">
|
|
34
|
-
Generate Dirac XML to: ${userRequest}
|
|
35
|
-
|
|
36
|
-
Available:
|
|
37
|
-
- <eval name="var">return jsExpression</eval> (MUST use 'return', fs and path available, can use Date)
|
|
38
|
-
- <output>text ${variable}</output>
|
|
39
|
-
|
|
40
|
-
IMPORTANT: Every eval MUST have 'return' statement.
|
|
41
|
-
Return only <dirac> XML, no markdown. Name the file timestamp.json.
|
|
42
|
-
</LLM>
|
|
43
|
-
|
|
44
|
-
<output>Executing... </output>
|
|
45
|
-
<execute source="code2" />
|
|
46
|
-
<output> </output>
|
|
47
|
-
</dirac>
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env dirac
|
|
2
|
-
<dirac>
|
|
3
|
-
<!--
|
|
4
|
-
Parameters Tag Example
|
|
5
|
-
|
|
6
|
-
The <parameters> tag allows subroutines to access their caller's
|
|
7
|
-
children and attributes, enabling functional-style parameter passing.
|
|
8
|
-
|
|
9
|
-
select="*" - Execute all child elements of caller
|
|
10
|
-
select="@attr" - Emit specific attribute value
|
|
11
|
-
select="@*" - Emit all attributes as name="value" pairs
|
|
12
|
-
-->
|
|
13
|
-
|
|
14
|
-
<!-- Example 1: Functional wrapper with child content -->
|
|
15
|
-
<subroutine name="BOLD">
|
|
16
|
-
<output><b></output>
|
|
17
|
-
<parameters select="*"/>
|
|
18
|
-
<output></b></output>
|
|
19
|
-
</subroutine>
|
|
20
|
-
|
|
21
|
-
<output>Example 1: </output>
|
|
22
|
-
<BOLD>
|
|
23
|
-
<output>Hello World</output>
|
|
24
|
-
</BOLD>
|
|
25
|
-
<output> </output>
|
|
26
|
-
|
|
27
|
-
<!-- Example 2: Attribute passthrough -->
|
|
28
|
-
<subroutine name="ATTR_DEMO">
|
|
29
|
-
<output>a=</output>
|
|
30
|
-
<parameters select="@a"/>
|
|
31
|
-
<output>, b=</output>
|
|
32
|
-
<parameters select="@b"/>
|
|
33
|
-
</subroutine>
|
|
34
|
-
|
|
35
|
-
<output>Example 2: </output>
|
|
36
|
-
<ATTR_DEMO a="3" b="4"/>
|
|
37
|
-
<output> </output>
|
|
38
|
-
|
|
39
|
-
<!-- Example 3: Inspector showing all attributes -->
|
|
40
|
-
<subroutine name="INSPECT">
|
|
41
|
-
<output>Element attributes: [</output>
|
|
42
|
-
<parameters select="@*"/>
|
|
43
|
-
<output>] </output>
|
|
44
|
-
</subroutine>
|
|
45
|
-
|
|
46
|
-
<output>Example 3: </output>
|
|
47
|
-
<INSPECT id="widget-1" type="button" enabled="true"/>
|
|
48
|
-
|
|
49
|
-
<!-- Example 4: List formatter -->
|
|
50
|
-
<subroutine name="UL">
|
|
51
|
-
<output><ul> </output>
|
|
52
|
-
<parameters select="*"/>
|
|
53
|
-
<output></ul> </output>
|
|
54
|
-
</subroutine>
|
|
55
|
-
|
|
56
|
-
<subroutine name="LI">
|
|
57
|
-
<output> <li></output>
|
|
58
|
-
<parameters select="*"/>
|
|
59
|
-
<output></li> </output>
|
|
60
|
-
</subroutine>
|
|
61
|
-
|
|
62
|
-
<output>Example 4: </output>
|
|
63
|
-
<UL>
|
|
64
|
-
<LI><output>First item</output></LI>
|
|
65
|
-
<LI><output>Second item</output></LI>
|
|
66
|
-
<LI><output>Third item</output></LI>
|
|
67
|
-
</UL>
|
|
68
|
-
</dirac>
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
<dirac>
|
|
2
|
-
<subroutine name="greet">
|
|
3
|
-
<parameters select="@name"/>
|
|
4
|
-
<output>Hello, <variable name="name"/>!</output>
|
|
5
|
-
</subroutine>
|
|
6
|
-
|
|
7
|
-
<subroutine name="greetmeta" param-name="string:required:name of the person" >
|
|
8
|
-
<output>From Meta: Hello, <variable name="name" /></output>
|
|
9
|
-
</subroutine>
|
|
10
|
-
<greet name="Alice"/>
|
|
11
|
-
<output> </output>
|
|
12
|
-
<greet name="Bob"/>
|
|
13
|
-
|
|
14
|
-
<output> </output>
|
|
15
|
-
<greetmeta name="Zhi" />
|
|
16
|
-
|
|
17
|
-
</dirac>
|
package/examples/params-test.di
DELETED
package/examples/recipe-chain.di
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
<!-- Recipe Generator - Chained LLM calls -->
|
|
2
|
-
<dirac>
|
|
3
|
-
<defvar name="ingredients" value="chicken, rice, tomatoes, garlic" />
|
|
4
|
-
|
|
5
|
-
<output>Available ingredients: ${ingredients} </output>
|
|
6
|
-
|
|
7
|
-
<!-- Step 1: Generate a dish name -->
|
|
8
|
-
<output>Step 1: Coming up with a dish... </output>
|
|
9
|
-
<LLM output="dishName" maxTokens="50">
|
|
10
|
-
Given these ingredients: ${ingredients}
|
|
11
|
-
Suggest ONE dish name (just the name, nothing else).
|
|
12
|
-
</LLM>
|
|
13
|
-
<output>Dish: ${dishName} </output>
|
|
14
|
-
|
|
15
|
-
<!-- Step 2: Create the recipe using the dish name -->
|
|
16
|
-
<output>Step 2: Creating recipe for ${dishName}... </output>
|
|
17
|
-
<LLM output="recipe" maxTokens="400">
|
|
18
|
-
Create a simple recipe for "${dishName}" using: ${ingredients}
|
|
19
|
-
|
|
20
|
-
Format:
|
|
21
|
-
Ingredients:
|
|
22
|
-
- list items
|
|
23
|
-
|
|
24
|
-
Instructions:
|
|
25
|
-
1. numbered steps
|
|
26
|
-
|
|
27
|
-
Keep it brief and practical.
|
|
28
|
-
</LLM>
|
|
29
|
-
<output> ${recipe} </output>
|
|
30
|
-
|
|
31
|
-
<!-- Step 3: Estimate cooking time -->
|
|
32
|
-
<output>Step 3: Estimating time... </output>
|
|
33
|
-
<LLM output="cookTime" maxTokens="50" context="recipe">
|
|
34
|
-
Based on this recipe, what's the total cooking time?
|
|
35
|
-
Answer with just a number and unit (e.g., "45 minutes").
|
|
36
|
-
</LLM>
|
|
37
|
-
<output>Total time: ${cookTime} </output>
|
|
38
|
-
</dirac>
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
<!-- Recursive LLM-Dirac Interleaving (LISP Style) -->
|
|
2
|
-
<dirac>
|
|
3
|
-
<output>Recursive Execution Demo </output>
|
|
4
|
-
|
|
5
|
-
<!-- Define subroutines that can be called by LLM -->
|
|
6
|
-
<subroutine name="GET_FILE_COUNT">
|
|
7
|
-
<eval name="count">
|
|
8
|
-
return fs.readdirSync('examples').filter(f => f.endsWith('.di')).length;
|
|
9
|
-
</eval>
|
|
10
|
-
<output>File count: ${count} </output>
|
|
11
|
-
</subroutine>
|
|
12
|
-
|
|
13
|
-
<subroutine name="GET_FILE_NAMES">
|
|
14
|
-
<eval name="names">
|
|
15
|
-
return fs.readdirSync('examples')
|
|
16
|
-
.filter(f => f.endsWith('.di'))
|
|
17
|
-
.slice(0, 3)
|
|
18
|
-
.join(', ');
|
|
19
|
-
</eval>
|
|
20
|
-
<output>Sample files: ${names} </output>
|
|
21
|
-
</subroutine>
|
|
22
|
-
|
|
23
|
-
<subroutine name="ANALYZE_DEEPER">
|
|
24
|
-
<output>Deep analysis requested... </output>
|
|
25
|
-
<!-- This subroutine itself calls an LLM! Recursion! -->
|
|
26
|
-
<LLM execute="true" maxTokens="80">
|
|
27
|
-
Return XML: <dirac><output>Analysis complete! </output></dirac>
|
|
28
|
-
</LLM>
|
|
29
|
-
</subroutine>
|
|
30
|
-
|
|
31
|
-
<!-- Level 1: User calls LLM -->
|
|
32
|
-
<output>Level 1: Asking LLM to analyze... </output>
|
|
33
|
-
<LLM execute="true" maxTokens="150">
|
|
34
|
-
Return ONLY XML calling these subroutines:
|
|
35
|
-
<dirac>
|
|
36
|
-
<output>Starting analysis... </output>
|
|
37
|
-
<GET_FILE_COUNT />
|
|
38
|
-
<GET_FILE_NAMES />
|
|
39
|
-
<ANALYZE_DEEPER />
|
|
40
|
-
</dirac>
|
|
41
|
-
</LLM>
|
|
42
|
-
|
|
43
|
-
<output> All levels complete! </output>
|
|
44
|
-
</dirac>
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
# dirac-string
|
|
2
|
-
|
|
3
|
-
String manipulation library for Dirac.
|
|
4
|
-
|
|
5
|
-

|
|
6
|
-

|
|
7
|
-
|
|
8
|
-
## Installation
|
|
9
|
-
|
|
10
|
-
```bash
|
|
11
|
-
npm install dirac-string
|
|
12
|
-
```
|
|
13
|
-
|
|
14
|
-
## Usage
|
|
15
|
-
|
|
16
|
-
```xml
|
|
17
|
-
<dirac>
|
|
18
|
-
<import src="./node_modules/dirac-string/lib/index.di"/>
|
|
19
|
-
|
|
20
|
-
<UPPERCASE text="hello world"/>
|
|
21
|
-
<!-- Outputs: HELLO WORLD -->
|
|
22
|
-
|
|
23
|
-
<LOWERCASE text="HELLO WORLD"/>
|
|
24
|
-
<!-- Outputs: hello world -->
|
|
25
|
-
|
|
26
|
-
<SUBSTRING text="Hello World" start="0" end="5"/>
|
|
27
|
-
<!-- Outputs: Hello -->
|
|
28
|
-
</dirac>
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
## API Reference
|
|
32
|
-
|
|
33
|
-
### UPPERCASE
|
|
34
|
-
Convert text to uppercase.
|
|
35
|
-
|
|
36
|
-
**Attributes:**
|
|
37
|
-
- `text` (string, required) - Text to convert
|
|
38
|
-
|
|
39
|
-
**Example:**
|
|
40
|
-
```xml
|
|
41
|
-
<UPPERCASE text="hello"/>
|
|
42
|
-
<!-- Output: HELLO -->
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
### LOWERCASE
|
|
46
|
-
Convert text to lowercase.
|
|
47
|
-
|
|
48
|
-
**Attributes:**
|
|
49
|
-
- `text` (string, required) - Text to convert
|
|
50
|
-
|
|
51
|
-
**Example:**
|
|
52
|
-
```xml
|
|
53
|
-
<LOWERCASE text="WORLD"/>
|
|
54
|
-
<!-- Output: world -->
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
### TRIM
|
|
58
|
-
Remove leading and trailing whitespace.
|
|
59
|
-
|
|
60
|
-
**Attributes:**
|
|
61
|
-
- `text` (string, required) - Text to trim
|
|
62
|
-
|
|
63
|
-
**Example:**
|
|
64
|
-
```xml
|
|
65
|
-
<TRIM text=" hello "/>
|
|
66
|
-
<!-- Output: hello -->
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
### SUBSTRING
|
|
70
|
-
Extract a substring.
|
|
71
|
-
|
|
72
|
-
**Attributes:**
|
|
73
|
-
- `text` (string, required) - Source text
|
|
74
|
-
- `start` (number, required) - Start index (0-based)
|
|
75
|
-
- `end` (number, optional) - End index (exclusive)
|
|
76
|
-
|
|
77
|
-
**Example:**
|
|
78
|
-
```xml
|
|
79
|
-
<SUBSTRING text="Hello World" start="6" end="11"/>
|
|
80
|
-
<!-- Output: World -->
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
### REPLACE
|
|
84
|
-
Replace all occurrences of a pattern.
|
|
85
|
-
|
|
86
|
-
**Attributes:**
|
|
87
|
-
- `text` (string, required) - Source text
|
|
88
|
-
- `find` (string, required) - Pattern to find (regex)
|
|
89
|
-
- `replace` (string, required) - Replacement text
|
|
90
|
-
|
|
91
|
-
**Example:**
|
|
92
|
-
```xml
|
|
93
|
-
<REPLACE text="Hello World" find="World" replace="Dirac"/>
|
|
94
|
-
<!-- Output: Hello Dirac -->
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
### SPLIT
|
|
98
|
-
Split text into array.
|
|
99
|
-
|
|
100
|
-
**Attributes:**
|
|
101
|
-
- `text` (string, required) - Text to split
|
|
102
|
-
- `delimiter` (string, optional) - Delimiter (default: ",")
|
|
103
|
-
|
|
104
|
-
**Example:**
|
|
105
|
-
```xml
|
|
106
|
-
<SPLIT text="a,b,c" delimiter=","/>
|
|
107
|
-
<!-- Output: ["a","b","c"] -->
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
### LENGTH
|
|
111
|
-
Get string length.
|
|
112
|
-
|
|
113
|
-
**Attributes:**
|
|
114
|
-
- `text` (string, required) - Text to measure
|
|
115
|
-
|
|
116
|
-
**Example:**
|
|
117
|
-
```xml
|
|
118
|
-
<LENGTH text="Hello"/>
|
|
119
|
-
<!-- Output: 5 -->
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
## Development
|
|
123
|
-
|
|
124
|
-
```bash
|
|
125
|
-
# Clone repository
|
|
126
|
-
git clone https://github.com/dirac-lang/dirac-string
|
|
127
|
-
cd dirac-string
|
|
128
|
-
|
|
129
|
-
# Run examples
|
|
130
|
-
dirac examples/demo.di
|
|
131
|
-
|
|
132
|
-
# Run tests
|
|
133
|
-
npm test
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
## Contributing
|
|
137
|
-
|
|
138
|
-
Contributions welcome! Please:
|
|
139
|
-
1. Fork the repository
|
|
140
|
-
2. Create a feature branch
|
|
141
|
-
3. Add tests for new functionality
|
|
142
|
-
4. Submit a pull request
|
|
143
|
-
|
|
144
|
-
## License
|
|
145
|
-
|
|
146
|
-
MIT © Dirac Community
|
|
147
|
-
|
|
148
|
-
## Links
|
|
149
|
-
|
|
150
|
-
- [Dirac Language](https://github.com/wangzhi63/dirac)
|
|
151
|
-
- [Report Issues](https://github.com/dirac-lang/dirac-string/issues)
|
|
152
|
-
- [All Dirac Libraries](https://github.com/topics/dirac-library)
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env dirac
|
|
2
|
-
<dirac>
|
|
3
|
-
<import src="../lib/index.di"/>
|
|
4
|
-
|
|
5
|
-
<output>String Library Demo </output>
|
|
6
|
-
|
|
7
|
-
<output>1. STR_UPPERCASE: </output>
|
|
8
|
-
<STR_UPPERCASE text="hello world"/>
|
|
9
|
-
<output> </output>
|
|
10
|
-
|
|
11
|
-
<output>2. STR_LOWERCASE: </output>
|
|
12
|
-
<STR_LOWERCASE text="HELLO WORLD"/>
|
|
13
|
-
<output> </output>
|
|
14
|
-
|
|
15
|
-
<output>3. STR_TRIM: </output>
|
|
16
|
-
<STR_TRIM text=" spaces "/>
|
|
17
|
-
<output> </output>
|
|
18
|
-
|
|
19
|
-
<output>4. STR_SUBSTRING (0,5): </output>
|
|
20
|
-
<STR_SUBSTRING text="Hello World" start="0" end="5"/>
|
|
21
|
-
<output> </output>
|
|
22
|
-
|
|
23
|
-
<output>5. STR_REPLACE: </output>
|
|
24
|
-
<STR_REPLACE text="Hello World" find="World" replace="Dirac"/>
|
|
25
|
-
<output> </output>
|
|
26
|
-
|
|
27
|
-
<output>6. STR_SPLIT: </output>
|
|
28
|
-
<STR_SPLIT text="apple,banana,cherry" delimiter=","/>
|
|
29
|
-
<output> </output>
|
|
30
|
-
|
|
31
|
-
<output>7. STR_LENGTH: </output>
|
|
32
|
-
<STR_LENGTH text="Hello"/>
|
|
33
|
-
<output> </output>
|
|
34
|
-
</dirac>
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
<dirac>
|
|
2
|
-
|
|
3
|
-
<subroutine name="STR_UPPERCASE">
|
|
4
|
-
<eval>
|
|
5
|
-
const caller = getParams();
|
|
6
|
-
const text = caller.attributes.text || '';
|
|
7
|
-
console.log(text.toUpperCase());
|
|
8
|
-
</eval>
|
|
9
|
-
</subroutine>
|
|
10
|
-
|
|
11
|
-
<subroutine name="STR_LOWERCASE">
|
|
12
|
-
<eval>
|
|
13
|
-
const caller = getParams();
|
|
14
|
-
const text = caller.attributes.text || '';
|
|
15
|
-
console.log(text.toLowerCase());
|
|
16
|
-
</eval>
|
|
17
|
-
</subroutine>
|
|
18
|
-
|
|
19
|
-
<subroutine name="STR_TRIM">
|
|
20
|
-
<eval>
|
|
21
|
-
const caller = getParams();
|
|
22
|
-
const text = caller.attributes.text || '';
|
|
23
|
-
console.log(text.trim());
|
|
24
|
-
</eval>
|
|
25
|
-
</subroutine>
|
|
26
|
-
|
|
27
|
-
<subroutine name="STR_SUBSTRING">
|
|
28
|
-
<eval>
|
|
29
|
-
const caller = getParams();
|
|
30
|
-
const text = caller.attributes.text || '';
|
|
31
|
-
const start = parseInt(caller.attributes.start || 0);
|
|
32
|
-
const end = caller.attributes.end ? parseInt(caller.attributes.end) : undefined;
|
|
33
|
-
console.log(text.substring(start, end));
|
|
34
|
-
</eval>
|
|
35
|
-
</subroutine>
|
|
36
|
-
|
|
37
|
-
<subroutine name="STR_REPLACE">
|
|
38
|
-
<eval>
|
|
39
|
-
const caller = getParams();
|
|
40
|
-
const text = caller.attributes.text || '';
|
|
41
|
-
const find = caller.attributes.find || '';
|
|
42
|
-
const replace = caller.attributes.replace || '';
|
|
43
|
-
console.log(text.replace(new RegExp(find, 'g'), replace));
|
|
44
|
-
</eval>
|
|
45
|
-
</subroutine>
|
|
46
|
-
|
|
47
|
-
<subroutine name="STR_SPLIT">
|
|
48
|
-
<eval>
|
|
49
|
-
const caller = getParams();
|
|
50
|
-
const text = caller.attributes.text || '';
|
|
51
|
-
const delimiter = caller.attributes.delimiter || ',';
|
|
52
|
-
const parts = text.split(delimiter);
|
|
53
|
-
console.log(JSON.stringify(parts));
|
|
54
|
-
</eval>
|
|
55
|
-
</subroutine>
|
|
56
|
-
|
|
57
|
-
<subroutine name="STR_LENGTH">
|
|
58
|
-
<eval>
|
|
59
|
-
const caller = getParams();
|
|
60
|
-
const text = caller.attributes.text || '';
|
|
61
|
-
console.log(text.length);
|
|
62
|
-
</eval>
|
|
63
|
-
</subroutine>
|
|
64
|
-
|
|
65
|
-
</dirac>
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "dirac-string",
|
|
3
|
-
"version": "1.0.0",
|
|
4
|
-
"description": "String manipulation library for Dirac",
|
|
5
|
-
"main": "lib/index.di",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"test": "dirac tests/test.di"
|
|
8
|
-
},
|
|
9
|
-
"keywords": [
|
|
10
|
-
"dirac",
|
|
11
|
-
"string",
|
|
12
|
-
"text",
|
|
13
|
-
"manipulation"
|
|
14
|
-
],
|
|
15
|
-
"author": "Dirac Community",
|
|
16
|
-
"license": "MIT",
|
|
17
|
-
"repository": {
|
|
18
|
-
"type": "git",
|
|
19
|
-
"url": "https://github.com/dirac-lang/dirac-string"
|
|
20
|
-
},
|
|
21
|
-
"bugs": {
|
|
22
|
-
"url": "https://github.com/dirac-lang/dirac-string/issues"
|
|
23
|
-
},
|
|
24
|
-
"homepage": "https://github.com/dirac-lang/dirac-string#readme",
|
|
25
|
-
"dirac": {
|
|
26
|
-
"version": ">=0.1.0",
|
|
27
|
-
"exports": {
|
|
28
|
-
"main": "lib/index.di"
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
<!-- Test nested subroutine calls with variable scope -->
|
|
2
|
-
<dirac>
|
|
3
|
-
<output>
|
|
4
|
-
============ Test: Nested Subroutine Calls with Variable Scope ============
|
|
5
|
-
</output>
|
|
6
|
-
|
|
7
|
-
<!-- Define main scope variables -->
|
|
8
|
-
<eval name="a">return "value-a"</eval>
|
|
9
|
-
<eval name="b">return "value-b"</eval>
|
|
10
|
-
<eval name="c">return "value-c"</eval>
|
|
11
|
-
|
|
12
|
-
<output>
|
|
13
|
-
Main scope: a=<variable name="a" />, b=<variable name="b" />, c=<variable name="c" />
|
|
14
|
-
</output>
|
|
15
|
-
|
|
16
|
-
<!-- Subroutine that calls another subroutine -->
|
|
17
|
-
<subroutine name="outer-sub" param-x="type:string:" param-y="type:string:">
|
|
18
|
-
<output> Outer subroutine - x: <variable name="x" />, y: <variable name="y" /></output>
|
|
19
|
-
|
|
20
|
-
<!-- Define local variable in outer sub -->
|
|
21
|
-
<eval name="outer_local">return "outer-value"</eval>
|
|
22
|
-
<output> Outer local: <variable name="outer_local" /></output>
|
|
23
|
-
|
|
24
|
-
<!-- Call inner subroutine -->
|
|
25
|
-
<call name="inner-sub" p="$x" q="$y"/>
|
|
26
|
-
|
|
27
|
-
<!-- Check outer variables still exist after inner call -->
|
|
28
|
-
<output> After inner call - x: <variable name="x" />, y: <variable name="y" />, outer_local: <variable name="outer_local" /></output>
|
|
29
|
-
</subroutine>
|
|
30
|
-
|
|
31
|
-
<!-- Inner subroutine -->
|
|
32
|
-
<subroutine name="inner-sub" param-p="type:string:" param-q="type:string:">
|
|
33
|
-
<output> Inner subroutine - p: <variable name="p" />, q: <variable name="q" /></output>
|
|
34
|
-
<eval name="inner_local">return "inner-value"</eval>
|
|
35
|
-
<output> Inner local: <variable name="inner_local" /></output>
|
|
36
|
-
</subroutine>
|
|
37
|
-
|
|
38
|
-
<output>
|
|
39
|
-
Calling outer-sub with a and b...
|
|
40
|
-
</output>
|
|
41
|
-
<call name="outer-sub" x="$a" y="$b"/>
|
|
42
|
-
|
|
43
|
-
<output>
|
|
44
|
-
After outer-sub, checking main scope:
|
|
45
|
-
a=<variable name="a" />, b=<variable name="b" />, c=<variable name="c" />
|
|
46
|
-
</output>
|
|
47
|
-
|
|
48
|
-
<!-- Call outer-sub again to ensure no cumulative scope pollution -->
|
|
49
|
-
<output>
|
|
50
|
-
Calling outer-sub AGAIN with b and c...
|
|
51
|
-
</output>
|
|
52
|
-
<call name="outer-sub" x="$b" y="$c"/>
|
|
53
|
-
|
|
54
|
-
<output>
|
|
55
|
-
After second outer-sub call:
|
|
56
|
-
a=<variable name="a" />, b=<variable name="b" />, c=<variable name="c" />
|
|
57
|
-
|
|
58
|
-
============ Test Complete ============
|
|
59
|
-
</output>
|
|
60
|
-
</dirac>
|
package/examples/scope-test.di
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
<dirac>
|
|
2
|
-
<!-- Test library with two simple subroutines -->
|
|
3
|
-
<subroutine name="first-sub"
|
|
4
|
-
param-x="string"
|
|
5
|
-
param-y="string">
|
|
6
|
-
<output>First subroutine - x: <variable name="x" />, y: <variable name="y" /></output>
|
|
7
|
-
</subroutine>
|
|
8
|
-
|
|
9
|
-
<subroutine name="second-sub"
|
|
10
|
-
param-x="string"
|
|
11
|
-
param-y="string"
|
|
12
|
-
param-z="string">
|
|
13
|
-
<output>Second subroutine - x: <variable name="x" />, y: <variable name="y" />, z: <variable name="z" /></output>
|
|
14
|
-
</subroutine>
|
|
15
|
-
|
|
16
|
-
<!-- Main execution -->
|
|
17
|
-
<output>============ Test: Sequential Subroutine Calls ============</output>
|
|
18
|
-
<output></output>
|
|
19
|
-
|
|
20
|
-
<!-- Define variables in main scope -->
|
|
21
|
-
<defvar name="x">value-x</defvar>
|
|
22
|
-
<defvar name="y">value-y</defvar>
|
|
23
|
-
<defvar name="z">value-z</defvar>
|
|
24
|
-
|
|
25
|
-
<output>Variables defined in main scope:</output>
|
|
26
|
-
<output> x = <variable name="x" /></output>
|
|
27
|
-
<output> y = <variable name="y" /></output>
|
|
28
|
-
<output> z = <variable name="z" /></output>
|
|
29
|
-
<output></output>
|
|
30
|
-
|
|
31
|
-
<!-- Call first subroutine -->
|
|
32
|
-
<output>Calling first-sub with x="$x" y="$y"</output>
|
|
33
|
-
<first-sub x="$x" y="$y" />
|
|
34
|
-
<output></output>
|
|
35
|
-
|
|
36
|
-
<!-- Check if variables still exist after first call -->
|
|
37
|
-
<output>After first-sub, checking main scope variables:</output>
|
|
38
|
-
<output> x = <variable name="x" /></output>
|
|
39
|
-
<output> y = <variable name="y" /></output>
|
|
40
|
-
<output> z = <variable name="z" /></output>
|
|
41
|
-
<output></output>
|
|
42
|
-
|
|
43
|
-
<!-- Call second subroutine -->
|
|
44
|
-
<output>Calling second-sub with x="$x" y="$y" z="$z"</output>
|
|
45
|
-
<second-sub x="$x" y="$y" z="$z" />
|
|
46
|
-
<output></output>
|
|
47
|
-
|
|
48
|
-
<output>After second-sub, checking main scope variables:</output>
|
|
49
|
-
<output> x = <variable name="x" /></output>
|
|
50
|
-
<output> y = <variable name="y" /></output>
|
|
51
|
-
<output> z = <variable name="z" /></output>
|
|
52
|
-
<output></output>
|
|
53
|
-
|
|
54
|
-
<output>============ Test Complete ============</output>
|
|
55
|
-
</dirac>
|
package/examples/seamless.di
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
<!-- Seamless LLM-Dirac Interleaving - THE PHILOSOPHICAL DEMO -->
|
|
2
|
-
<dirac>
|
|
3
|
-
<output>Seamless Execution Demo </output>
|
|
4
|
-
|
|
5
|
-
<!-- Define a subroutine that lists files -->
|
|
6
|
-
<subroutine name="LIST_FILES">
|
|
7
|
-
<eval name="files">
|
|
8
|
-
return fs.readdirSync('examples')
|
|
9
|
-
.filter(f => f.endsWith('.di'))
|
|
10
|
-
.slice(0, 5)
|
|
11
|
-
.join(', ');
|
|
12
|
-
</eval>
|
|
13
|
-
<output>Files found: ${files} </output>
|
|
14
|
-
</subroutine>
|
|
15
|
-
|
|
16
|
-
<!-- Define a subroutine that counts something -->
|
|
17
|
-
<subroutine name="COUNT_FILES">
|
|
18
|
-
<eval name="count">
|
|
19
|
-
return fs.readdirSync('examples').filter(f => f.endsWith('.di')).length;
|
|
20
|
-
</eval>
|
|
21
|
-
<output>Total count: ${count} </output>
|
|
22
|
-
</subroutine>
|
|
23
|
-
|
|
24
|
-
<!-- Now the magic: LLM returns Dirac tags that get executed immediately -->
|
|
25
|
-
<output>Asking LLM to analyze and respond with executable tags... </output>
|
|
26
|
-
|
|
27
|
-
<LLM execute="true" maxTokens="200">
|
|
28
|
-
You are analyzing a project directory.
|
|
29
|
-
|
|
30
|
-
Respond by calling ONLY these Dirac subroutines (XML tags):
|
|
31
|
-
- <LIST_FILES /> - lists example files
|
|
32
|
-
- <COUNT_FILES /> - counts total files
|
|
33
|
-
|
|
34
|
-
Your response should be pure XML like:
|
|
35
|
-
<dirac>
|
|
36
|
-
<output>Analysis: </output>
|
|
37
|
-
<LIST_FILES />
|
|
38
|
-
<COUNT_FILES />
|
|
39
|
-
</dirac>
|
|
40
|
-
|
|
41
|
-
Return ONLY the XML, no explanation.
|
|
42
|
-
</LLM>
|
|
43
|
-
|
|
44
|
-
<output> Done! </output>
|
|
45
|
-
</dirac>
|