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.
Files changed (226) hide show
  1. package/dist/{chunk-APWJJXNI.js → chunk-7OUYWIZV.js} +55 -14
  2. package/dist/{chunk-RGS2XK6T.js → chunk-OUMUIBK3.js} +1 -1
  3. package/dist/cli.js +15 -3
  4. package/dist/index.js +2 -2
  5. package/dist/{interpreter-UZDVASAW.js → interpreter-MTIIHIIQ.js} +1 -1
  6. package/dist/test-runner.js +1 -1
  7. package/lib/index.di +9 -0
  8. package/package.json +13 -1
  9. package/.env.example +0 -8
  10. package/COMMUNITY.md +0 -465
  11. package/CONDITIONAL-TAGS.md +0 -172
  12. package/EXCEPTION-HANDLING.md +0 -156
  13. package/LIBRARIES.md +0 -172
  14. package/LLM-VALIDATION.md +0 -128
  15. package/NAMESPACES.md +0 -366
  16. package/PROMOTION.md +0 -257
  17. package/QUICKSTART-LIBRARY.md +0 -93
  18. package/TEST-COVERAGE.md +0 -113
  19. package/TESTING.md +0 -162
  20. package/config.test.yml +0 -5
  21. package/dirac-http/examples/demo.di +0 -9
  22. package/dirac-http/lib/index.di +0 -12
  23. package/examples/add-demo.di +0 -74
  24. package/examples/add.bk +0 -11
  25. package/examples/advanced-math-demo.di +0 -53
  26. package/examples/calculator.di +0 -32
  27. package/examples/compact-test.di +0 -6
  28. package/examples/comprehensive.bk +0 -29
  29. package/examples/defvar-variable-demo.di +0 -18
  30. package/examples/direct-call.di +0 -17
  31. package/examples/disk-analysis.di +0 -16
  32. package/examples/exception-demo.di +0 -82
  33. package/examples/executable-hello.di +0 -7
  34. package/examples/execute-demo.di +0 -38
  35. package/examples/file-manager.di +0 -77
  36. package/examples/file-stats.di +0 -18
  37. package/examples/hello.bk +0 -1
  38. package/examples/hello.di +0 -5
  39. package/examples/if-comparison.di +0 -91
  40. package/examples/if-cstyle-test.di +0 -149
  41. package/examples/if-vs-testif.di +0 -56
  42. package/examples/import-demo.di +0 -31
  43. package/examples/inline-test.bk +0 -7
  44. package/examples/llm-agent.di +0 -32
  45. package/examples/llm-basic.di +0 -12
  46. package/examples/llm-command-more.di +0 -6
  47. package/examples/llm-command-no-exec.di +0 -13
  48. package/examples/llm-command.di +0 -6
  49. package/examples/llm-complex.di +0 -141
  50. package/examples/llm-feedback-debug.di +0 -30
  51. package/examples/llm-feedback-demo.di +0 -19
  52. package/examples/llm-feedback-math.di +0 -22
  53. package/examples/llm-feedback-simple.di +0 -16
  54. package/examples/llm-feedback-sub.di +0 -22
  55. package/examples/llm-no-feedback.di +0 -10
  56. package/examples/llm-recursive.di +0 -31
  57. package/examples/llm-reflection-test.di +0 -19
  58. package/examples/llm-simple-test.di +0 -12
  59. package/examples/llm-subs.di +0 -132
  60. package/examples/llm-use-subs.di +0 -6
  61. package/examples/llm-validate-test.di +0 -18
  62. package/examples/loop.di +0 -12
  63. package/examples/math-test.di +0 -22
  64. package/examples/minimal-test.di +0 -13
  65. package/examples/mongodb-context-test.di +0 -27
  66. package/examples/mongodb-count-events.di +0 -8
  67. package/examples/mongodb-import-demo.di +0 -25
  68. package/examples/mongodb-simple-test.di +0 -18
  69. package/examples/nl-agent.di +0 -47
  70. package/examples/parameters-demo.di +0 -68
  71. package/examples/params-meta-test.di +0 -17
  72. package/examples/params-test.di +0 -10
  73. package/examples/recipe-chain.di +0 -38
  74. package/examples/recursive-llm.di +0 -44
  75. package/examples/sample-library/README.md +0 -152
  76. package/examples/sample-library/examples/demo.di +0 -34
  77. package/examples/sample-library/lib/index.di +0 -65
  78. package/examples/sample-library/package.json +0 -31
  79. package/examples/scope-test-nested.di +0 -60
  80. package/examples/scope-test.di +0 -55
  81. package/examples/seamless.di +0 -45
  82. package/examples/shell-test.bk +0 -10
  83. package/examples/simple-import.di +0 -13
  84. package/examples/simple-recursive.di +0 -26
  85. package/examples/story-builder.di +0 -45
  86. package/examples/subroutine.di +0 -23
  87. package/examples/system-llm.di +0 -21
  88. package/examples/system-simple.di +0 -3
  89. package/examples/system-test.di +0 -8
  90. package/examples/tag-check-test.di +0 -139
  91. package/examples/task-assistant.di +0 -27
  92. package/examples/test-if-demo.di +0 -110
  93. package/examples/test-parameters.di +0 -50
  94. package/examples/try-catch-test.di +0 -118
  95. package/examples/two-styles.di +0 -28
  96. package/examples/var-debug.di +0 -6
  97. package/examples/var-inline.di +0 -4
  98. package/examples/var-test2.di +0 -6
  99. package/examples/variable-replace.di +0 -25
  100. package/examples/variable-simple.di +0 -16
  101. package/examples/variable-test.di +0 -22
  102. package/examples/whitespace-test.di +0 -24
  103. package/filePath +0 -1
  104. package/greeting.txt +0 -1
  105. package/src/cli.ts +0 -140
  106. package/src/index.ts +0 -33
  107. package/src/llm/ollama.ts +0 -58
  108. package/src/runtime/braket-parser.ts +0 -234
  109. package/src/runtime/interpreter.ts +0 -203
  110. package/src/runtime/parser.ts +0 -155
  111. package/src/runtime/session.ts +0 -325
  112. package/src/tags/assign.ts +0 -37
  113. package/src/tags/attr.ts +0 -64
  114. package/src/tags/available-subroutines.ts +0 -70
  115. package/src/tags/call.ts +0 -259
  116. package/src/tags/catch.ts +0 -24
  117. package/src/tags/defvar.ts +0 -115
  118. package/src/tags/environment.ts +0 -21
  119. package/src/tags/eval.ts +0 -71
  120. package/src/tags/exception.ts +0 -20
  121. package/src/tags/execute.ts +0 -52
  122. package/src/tags/expr.ts +0 -128
  123. package/src/tags/foreach.ts +0 -170
  124. package/src/tags/if.ts +0 -191
  125. package/src/tags/import.ts +0 -66
  126. package/src/tags/index.ts +0 -41
  127. package/src/tags/input.ts +0 -182
  128. package/src/tags/llm.ts +0 -415
  129. package/src/tags/loop.ts +0 -43
  130. package/src/tags/mongodb.ts +0 -70
  131. package/src/tags/output.ts +0 -53
  132. package/src/tags/parameters.ts +0 -81
  133. package/src/tags/require_module.ts +0 -19
  134. package/src/tags/subroutine.ts +0 -75
  135. package/src/tags/system.ts +0 -93
  136. package/src/tags/tag-check.ts +0 -176
  137. package/src/tags/test-if.ts +0 -112
  138. package/src/tags/throw.ts +0 -26
  139. package/src/tags/try.ts +0 -19
  140. package/src/tags/variable.ts +0 -25
  141. package/src/test-runner.ts +0 -300
  142. package/src/types/index.ts +0 -128
  143. package/src/utils/llm-adapter.ts +0 -113
  144. package/src/utils/tag-validator.ts +0 -231
  145. package/test-available-extends.di +0 -28
  146. package/test-available-simple.di +0 -12
  147. package/test-available-subroutines.di +0 -16
  148. package/test-call.di +0 -9
  149. package/test-extend-basic.di +0 -17
  150. package/test-extend-chain.di +0 -26
  151. package/test-extend-debug.di +0 -17
  152. package/test-extend-debug2.di +0 -15
  153. package/test-extend-person.di +0 -17
  154. package/test-extend-simple.di +0 -11
  155. package/test-extend-zhi.di +0 -23
  156. package/test-extend.di +0 -19
  157. package/test-extend2.di +0 -26
  158. package/test-extend3-fixed.di +0 -23
  159. package/test-extend3-trouble.di +0 -23
  160. package/test-extend3.di +0 -21
  161. package/test-factorial.di +0 -19
  162. package/test-input-debug.di +0 -19
  163. package/test-nested-debug.di +0 -7
  164. package/test-nested-debug2.di +0 -8
  165. package/test-no-extend.di +0 -16
  166. package/test-simple-call.di +0 -7
  167. package/test-simple.di +0 -6
  168. package/tests/README.md +0 -69
  169. package/tests/assign-basic.test.di +0 -7
  170. package/tests/assign-from-eval.test.di +0 -7
  171. package/tests/available-subroutines-foreach.test.di +0 -32
  172. package/tests/basic-output.test.di +0 -5
  173. package/tests/call-basic.test.di +0 -11
  174. package/tests/call-with-output.test.di +0 -10
  175. package/tests/comments-before-content.test.di +0 -6
  176. package/tests/defvar-multiple.test.di +0 -8
  177. package/tests/environment-basic.test.di +0 -22
  178. package/tests/environment-nonexistent.test.di +0 -5
  179. package/tests/environment-with-defvar.test.di +0 -15
  180. package/tests/eval-basic.test.di +0 -6
  181. package/tests/eval-with-variables.test.di +0 -8
  182. package/tests/exception-basic.test.di +0 -10
  183. package/tests/expr-basic.test.di +0 -11
  184. package/tests/extend-basic.test.di +0 -19
  185. package/tests/extend-inheritance-chain.test.di +0 -26
  186. package/tests/extend-multiple-nested.test.di +0 -24
  187. package/tests/extend-self.test.di +0 -19
  188. package/tests/extend-with-parameters.test.di +0 -14
  189. package/tests/generate-dirac.test.di +0 -22
  190. package/tests/if-conditional.test.di +0 -17
  191. package/tests/if-else.test.di +0 -11
  192. package/tests/if-with-variables.test.di +0 -8
  193. package/tests/import-basic.test.di +0 -6
  194. package/tests/input-file-all.test.di +0 -5
  195. package/tests/input-file-line.test.di +0 -15
  196. package/tests/input-file-loop.test.di +0 -12
  197. package/tests/input-stdin-all.test.di +0 -8
  198. package/tests/input-stdin-all.txt +0 -1
  199. package/tests/llm-validate.test.di +0 -17
  200. package/tests/loop-basic.test.di +0 -9
  201. package/tests/loop-nested.test.di +0 -10
  202. package/tests/loop-with-eval.test.di +0 -8
  203. package/tests/no-root-element.test.di +0 -6
  204. package/tests/output-file.test.di +0 -19
  205. package/tests/output-multiple.test.di +0 -9
  206. package/tests/parameters-basic.test.di +0 -6
  207. package/tests/require-module-basic.test.di +0 -7
  208. package/tests/subroutine-basic.test.di +0 -9
  209. package/tests/subroutine-multiple-params.test.di +0 -10
  210. package/tests/subroutine-nested-calls.test.di +0 -32
  211. package/tests/subroutine-sequential-calls.test.di +0 -36
  212. package/tests/system-background.test.di +0 -39
  213. package/tests/system-basic.test.di +0 -5
  214. package/tests/tag-check.test.di +0 -27
  215. package/tests/test-if-basic.test.di +0 -8
  216. package/tests/test-input.txt +0 -3
  217. package/tests/try-catch-basic.test.di +0 -10
  218. package/tests/try-catch-eval-error.test.di +0 -10
  219. package/tests/variable-basic.test.di +0 -6
  220. package/tests/variable-interpolation.test.di +0 -7
  221. package/tools/create-library.sh +0 -175
  222. package/tsconfig.json +0 -19
  223. /package/{examples/lib → lib}/advanced-math.di +0 -0
  224. /package/{examples/lib → lib}/fileops.di +0 -0
  225. /package/{examples/lib → lib}/math.di +0 -0
  226. /package/{examples/lib → lib}/mongodb.di +0 -0
@@ -1,47 +0,0 @@
1
- <!-- Advanced Agent - Natural language to operations -->
2
- <dirac>
3
- <output>Interactive Agent Example&#10;&#10;</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}&#10;</output>
9
- <LLM output="code1" maxTokens="300">
10
- Generate Dirac XML to: ${userRequest}
11
-
12
- Use these tags ONLY:
13
- 1. &lt;eval name="varname"&gt;return javascriptExpression;&lt;/eval&gt;
14
- 2. &lt;output&gt;text with ${varname}&lt;/output&gt;
15
-
16
- Example:
17
- &lt;dirac&gt;
18
- &lt;eval name="result"&gt;return fs.readdirSync('examples').filter(f =&gt; f.endsWith('.di')).length;&lt;/eval&gt;
19
- &lt;output&gt;Count: ${result}&lt;/output&gt;
20
- &lt;/dirac&gt;
21
-
22
- Return only XML, no markdown or explanations.
23
- </LLM>
24
-
25
- <output>Executing...&#10;</output>
26
- <execute source="code1" />
27
- <output>&#10;&#10;</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}&#10;</output>
33
- <LLM output="code2" maxTokens="300">
34
- Generate Dirac XML to: ${userRequest}
35
-
36
- Available:
37
- - &lt;eval name="var"&gt;return jsExpression&lt;/eval&gt; (MUST use 'return', fs and path available, can use Date)
38
- - &lt;output&gt;text ${variable}&lt;/output&gt;
39
-
40
- IMPORTANT: Every eval MUST have 'return' statement.
41
- Return only &lt;dirac&gt; XML, no markdown. Name the file timestamp.json.
42
- </LLM>
43
-
44
- <output>Executing...&#10;</output>
45
- <execute source="code2" />
46
- <output>&#10;</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>&lt;b&gt;</output>
17
- <parameters select="*"/>
18
- <output>&lt;/b&gt;</output>
19
- </subroutine>
20
-
21
- <output>Example 1: </output>
22
- <BOLD>
23
- <output>Hello World</output>
24
- </BOLD>
25
- <output>&#10;</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>&#10;</output>
38
-
39
- <!-- Example 3: Inspector showing all attributes -->
40
- <subroutine name="INSPECT">
41
- <output>Element attributes: [</output>
42
- <parameters select="@*"/>
43
- <output>]&#10;</output>
44
- </subroutine>
45
-
46
- <output>Example 3:&#10;</output>
47
- <INSPECT id="widget-1" type="button" enabled="true"/>
48
-
49
- <!-- Example 4: List formatter -->
50
- <subroutine name="UL">
51
- <output>&lt;ul&gt;&#10;</output>
52
- <parameters select="*"/>
53
- <output>&lt;/ul&gt;&#10;</output>
54
- </subroutine>
55
-
56
- <subroutine name="LI">
57
- <output> &lt;li&gt;</output>
58
- <parameters select="*"/>
59
- <output>&lt;/li&gt;&#10;</output>
60
- </subroutine>
61
-
62
- <output>Example 4:&#10;</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>&#10;</output>
12
- <greet name="Bob"/>
13
-
14
- <output>&#10;</output>
15
- <greetmeta name="Zhi" />
16
-
17
- </dirac>
@@ -1,10 +0,0 @@
1
- <dirac>
2
- <subroutine name="greet">
3
- <parameters select="@name"/>
4
- <output>Hello, <variable name="name"/>!</output>
5
- </subroutine>
6
-
7
- <greet name="Alice"/>
8
- <output>&#10;</output>
9
- <greet name="Bob"/>
10
- </dirac>
@@ -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}&#10;&#10;</output>
6
-
7
- <!-- Step 1: Generate a dish name -->
8
- <output>Step 1: Coming up with a dish...&#10;</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}&#10;&#10;</output>
14
-
15
- <!-- Step 2: Create the recipe using the dish name -->
16
- <output>Step 2: Creating recipe for ${dishName}...&#10;</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>&#10;${recipe}&#10;&#10;</output>
30
-
31
- <!-- Step 3: Estimate cooking time -->
32
- <output>Step 3: Estimating time...&#10;</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}&#10;</output>
38
- </dirac>
@@ -1,44 +0,0 @@
1
- <!-- Recursive LLM-Dirac Interleaving (LISP Style) -->
2
- <dirac>
3
- <output>Recursive Execution Demo&#10;&#10;</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}&#10;</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}&#10;</output>
21
- </subroutine>
22
-
23
- <subroutine name="ANALYZE_DEEPER">
24
- <output>Deep analysis requested...&#10;</output>
25
- <!-- This subroutine itself calls an LLM! Recursion! -->
26
- <LLM execute="true" maxTokens="80">
27
- Return XML: &lt;dirac&gt;&lt;output&gt;Analysis complete!&#10;&lt;/output&gt;&lt;/dirac&gt;
28
- </LLM>
29
- </subroutine>
30
-
31
- <!-- Level 1: User calls LLM -->
32
- <output>Level 1: Asking LLM to analyze...&#10;</output>
33
- <LLM execute="true" maxTokens="150">
34
- Return ONLY XML calling these subroutines:
35
- &lt;dirac&gt;
36
- &lt;output&gt;Starting analysis...&#10;&lt;/output&gt;
37
- &lt;GET_FILE_COUNT /&gt;
38
- &lt;GET_FILE_NAMES /&gt;
39
- &lt;ANALYZE_DEEPER /&gt;
40
- &lt;/dirac&gt;
41
- </LLM>
42
-
43
- <output>&#10;All levels complete!&#10;</output>
44
- </dirac>
@@ -1,152 +0,0 @@
1
- # dirac-string
2
-
3
- String manipulation library for Dirac.
4
-
5
- ![npm version](https://img.shields.io/npm/v/dirac-string)
6
- ![license](https://img.shields.io/npm/l/dirac-string)
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&#10;&#10;</output>
6
-
7
- <output>1. STR_UPPERCASE: </output>
8
- <STR_UPPERCASE text="hello world"/>
9
- <output>&#10;</output>
10
-
11
- <output>2. STR_LOWERCASE: </output>
12
- <STR_LOWERCASE text="HELLO WORLD"/>
13
- <output>&#10;</output>
14
-
15
- <output>3. STR_TRIM: </output>
16
- <STR_TRIM text=" spaces "/>
17
- <output>&#10;</output>
18
-
19
- <output>4. STR_SUBSTRING (0,5): </output>
20
- <STR_SUBSTRING text="Hello World" start="0" end="5"/>
21
- <output>&#10;</output>
22
-
23
- <output>5. STR_REPLACE: </output>
24
- <STR_REPLACE text="Hello World" find="World" replace="Dirac"/>
25
- <output>&#10;</output>
26
-
27
- <output>6. STR_SPLIT: </output>
28
- <STR_SPLIT text="apple,banana,cherry" delimiter=","/>
29
- <output>&#10;</output>
30
-
31
- <output>7. STR_LENGTH: </output>
32
- <STR_LENGTH text="Hello"/>
33
- <output>&#10;</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>
@@ -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>
@@ -1,45 +0,0 @@
1
- <!-- Seamless LLM-Dirac Interleaving - THE PHILOSOPHICAL DEMO -->
2
- <dirac>
3
- <output>Seamless Execution Demo&#10;&#10;</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}&#10;</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}&#10;</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...&#10;&#10;</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
- - &lt;LIST_FILES /&gt; - lists example files
32
- - &lt;COUNT_FILES /&gt; - counts total files
33
-
34
- Your response should be pure XML like:
35
- &lt;dirac&gt;
36
- &lt;output&gt;Analysis:&#10;&lt;/output&gt;
37
- &lt;LIST_FILES /&gt;
38
- &lt;COUNT_FILES /&gt;
39
- &lt;/dirac&gt;
40
-
41
- Return ONLY the XML, no explanation.
42
- </LLM>
43
-
44
- <output>&#10;Done!&#10;</output>
45
- </dirac>