tjs-lang 0.2.0

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 (91) hide show
  1. package/CONTEXT.md +594 -0
  2. package/LICENSE +190 -0
  3. package/README.md +220 -0
  4. package/bin/benchmarks.ts +351 -0
  5. package/bin/dev.ts +205 -0
  6. package/bin/docs.js +170 -0
  7. package/bin/install-cursor.sh +71 -0
  8. package/bin/install-vscode.sh +71 -0
  9. package/bin/select-local-models.d.ts +1 -0
  10. package/bin/select-local-models.js +28 -0
  11. package/bin/select-local-models.ts +31 -0
  12. package/demo/autocomplete.test.ts +232 -0
  13. package/demo/docs.json +186 -0
  14. package/demo/examples.test.ts +598 -0
  15. package/demo/index.html +91 -0
  16. package/demo/src/autocomplete.ts +482 -0
  17. package/demo/src/capabilities.ts +859 -0
  18. package/demo/src/demo-nav.ts +2097 -0
  19. package/demo/src/examples.test.ts +161 -0
  20. package/demo/src/examples.ts +476 -0
  21. package/demo/src/imports.test.ts +196 -0
  22. package/demo/src/imports.ts +421 -0
  23. package/demo/src/index.ts +639 -0
  24. package/demo/src/module-store.ts +635 -0
  25. package/demo/src/module-sw.ts +132 -0
  26. package/demo/src/playground.ts +949 -0
  27. package/demo/src/service-host.ts +389 -0
  28. package/demo/src/settings.ts +440 -0
  29. package/demo/src/style.ts +280 -0
  30. package/demo/src/tjs-playground.ts +1605 -0
  31. package/demo/src/ts-examples.ts +478 -0
  32. package/demo/src/ts-playground.ts +1092 -0
  33. package/demo/static/favicon.svg +30 -0
  34. package/demo/static/photo-1.jpg +0 -0
  35. package/demo/static/photo-2.jpg +0 -0
  36. package/demo/static/texts/ai-history.txt +9 -0
  37. package/demo/static/texts/coffee-origins.txt +9 -0
  38. package/demo/static/texts/renewable-energy.txt +9 -0
  39. package/dist/index.js +256 -0
  40. package/dist/index.js.map +37 -0
  41. package/dist/tjs-batteries.js +4 -0
  42. package/dist/tjs-batteries.js.map +15 -0
  43. package/dist/tjs-full.js +256 -0
  44. package/dist/tjs-full.js.map +37 -0
  45. package/dist/tjs-transpiler.js +220 -0
  46. package/dist/tjs-transpiler.js.map +21 -0
  47. package/dist/tjs-vm.js +4 -0
  48. package/dist/tjs-vm.js.map +14 -0
  49. package/docs/CNAME +1 -0
  50. package/docs/favicon.svg +30 -0
  51. package/docs/index.html +91 -0
  52. package/docs/index.js +10468 -0
  53. package/docs/index.js.map +92 -0
  54. package/docs/photo-1.jpg +0 -0
  55. package/docs/photo-1.webp +0 -0
  56. package/docs/photo-2.jpg +0 -0
  57. package/docs/photo-2.webp +0 -0
  58. package/docs/texts/ai-history.txt +9 -0
  59. package/docs/texts/coffee-origins.txt +9 -0
  60. package/docs/texts/renewable-energy.txt +9 -0
  61. package/docs/tjs-lang.svg +31 -0
  62. package/docs/tosijs-agent.svg +31 -0
  63. package/editors/README.md +325 -0
  64. package/editors/ace/ajs-mode.js +328 -0
  65. package/editors/ace/ajs-mode.ts +269 -0
  66. package/editors/ajs-syntax.ts +212 -0
  67. package/editors/build-grammars.ts +510 -0
  68. package/editors/codemirror/ajs-language.js +287 -0
  69. package/editors/codemirror/ajs-language.ts +1447 -0
  70. package/editors/codemirror/autocomplete.test.ts +531 -0
  71. package/editors/codemirror/component.ts +404 -0
  72. package/editors/monaco/ajs-monarch.js +243 -0
  73. package/editors/monaco/ajs-monarch.ts +225 -0
  74. package/editors/tjs-syntax.ts +115 -0
  75. package/editors/vscode/language-configuration.json +37 -0
  76. package/editors/vscode/package.json +65 -0
  77. package/editors/vscode/syntaxes/ajs-injection.tmLanguage.json +107 -0
  78. package/editors/vscode/syntaxes/ajs.tmLanguage.json +252 -0
  79. package/editors/vscode/syntaxes/tjs.tmLanguage.json +333 -0
  80. package/package.json +83 -0
  81. package/src/cli/commands/check.ts +41 -0
  82. package/src/cli/commands/convert.ts +133 -0
  83. package/src/cli/commands/emit.ts +260 -0
  84. package/src/cli/commands/run.ts +68 -0
  85. package/src/cli/commands/test.ts +194 -0
  86. package/src/cli/commands/types.ts +20 -0
  87. package/src/cli/create-app.ts +236 -0
  88. package/src/cli/playground.ts +250 -0
  89. package/src/cli/tjs.ts +166 -0
  90. package/src/cli/tjsx.ts +160 -0
  91. package/tjs-lang.svg +31 -0
@@ -0,0 +1,328 @@
1
+ /**
2
+ * Ace Editor Mode for AsyncJS
3
+ *
4
+ * Usage:
5
+ * ```html
6
+ * <script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.32.2/ace.js"></script>
7
+ * <script src="path/to/ajs-mode.js"></script>
8
+ * <script>
9
+ * const editor = ace.edit("editor");
10
+ * editor.session.setMode("ace/mode/ajs");
11
+ * </script>
12
+ * ```
13
+ *
14
+ * Or as ES module:
15
+ * ```javascript
16
+ * import ace from 'ace-builds'
17
+ * import { registerAjsMode } from 'tjs-lang/editors/ace/ajs-mode'
18
+ * registerAjsMode(ace)
19
+ * editor.session.setMode('ace/mode/ajs')
20
+ * ```
21
+ */
22
+
23
+ // Forbidden keywords in AsyncJS - these will be highlighted as errors
24
+ const FORBIDDEN_KEYWORDS = [
25
+ 'new',
26
+ 'class',
27
+ 'async',
28
+ 'await',
29
+ 'var',
30
+ 'this',
31
+ 'super',
32
+ 'extends',
33
+ 'implements',
34
+ 'interface',
35
+ 'type',
36
+ 'yield',
37
+ 'import',
38
+ 'export',
39
+ 'require',
40
+ 'throw',
41
+ ]
42
+
43
+ // Valid keywords in AsyncJS
44
+ const KEYWORDS = [
45
+ 'function',
46
+ 'return',
47
+ 'if',
48
+ 'else',
49
+ 'while',
50
+ 'for',
51
+ 'of',
52
+ 'in',
53
+ 'try',
54
+ 'catch',
55
+ 'finally',
56
+ 'let',
57
+ 'const',
58
+ ]
59
+
60
+ // Language constants
61
+ const CONSTANTS = ['true', 'false', 'null']
62
+
63
+ // Built-in type constructors
64
+ const BUILTINS = [
65
+ 'Date',
66
+ 'Set',
67
+ 'Map',
68
+ 'Array',
69
+ 'Object',
70
+ 'String',
71
+ 'Number',
72
+ 'Math',
73
+ 'JSON',
74
+ ]
75
+
76
+ /**
77
+ * Create the AsyncJS highlight rules for Ace
78
+ */
79
+ function createAjsHighlightRules(ace) {
80
+ const oop = ace.require('ace/lib/oop')
81
+ const TextHighlightRules = ace.require(
82
+ 'ace/mode/text_highlight_rules'
83
+ ).TextHighlightRules
84
+
85
+ function AjsHighlightRules() {
86
+ const keywordMapper = this.createKeywordMapper(
87
+ {
88
+ 'invalid.illegal': FORBIDDEN_KEYWORDS.join('|'),
89
+ keyword: KEYWORDS.join('|'),
90
+ 'constant.language': CONSTANTS.join('|'),
91
+ 'support.function': BUILTINS.join('|'),
92
+ },
93
+ 'identifier'
94
+ )
95
+
96
+ this.$rules = {
97
+ start: [
98
+ // Comments
99
+ {
100
+ token: 'comment.line',
101
+ regex: /\/\/.*$/,
102
+ },
103
+ {
104
+ token: 'comment.block.documentation',
105
+ regex: /\/\*\*/,
106
+ next: 'doc_comment',
107
+ },
108
+ {
109
+ token: 'comment.block',
110
+ regex: /\/\*/,
111
+ next: 'block_comment',
112
+ },
113
+
114
+ // Strings - must come before keywords to avoid highlighting inside strings
115
+ {
116
+ token: 'string.quoted.single',
117
+ regex: /'(?:[^'\\]|\\.)*'/,
118
+ },
119
+ {
120
+ token: 'string.quoted.double',
121
+ regex: /"(?:[^"\\]|\\.)*"/,
122
+ },
123
+ // Template literals with embedded expressions
124
+ {
125
+ token: 'string.template',
126
+ regex: /`/,
127
+ next: 'template_string',
128
+ },
129
+
130
+ // Numbers
131
+ {
132
+ token: 'constant.numeric.float',
133
+ regex: /\d+\.\d+(?:[eE][+-]?\d+)?/,
134
+ },
135
+ {
136
+ token: 'constant.numeric.hex',
137
+ regex: /0[xX][0-9a-fA-F]+/,
138
+ },
139
+ {
140
+ token: 'constant.numeric',
141
+ regex: /\d+/,
142
+ },
143
+
144
+ // Function definition
145
+ {
146
+ token: ['keyword', 'text', 'entity.name.function'],
147
+ regex: /(function)(\s+)([a-zA-Z_$][a-zA-Z0-9_$]*)/,
148
+ },
149
+
150
+ // Keywords and identifiers
151
+ {
152
+ token: keywordMapper,
153
+ regex: /[a-zA-Z_$][a-zA-Z0-9_$]*/,
154
+ },
155
+
156
+ // Operators
157
+ {
158
+ token: 'keyword.operator',
159
+ regex: /\+\+|--|\*\*|&&|\|\||==|!=|>=|<=|=>|[+\-*/%=<>!&|^~?:]/,
160
+ },
161
+
162
+ // Brackets
163
+ {
164
+ token: 'paren.lparen',
165
+ regex: /[{(\[]/,
166
+ },
167
+ {
168
+ token: 'paren.rparen',
169
+ regex: /[})\]]/,
170
+ },
171
+
172
+ // Punctuation
173
+ {
174
+ token: 'punctuation',
175
+ regex: /[;,.:]/,
176
+ },
177
+ ],
178
+
179
+ block_comment: [
180
+ {
181
+ token: 'comment.block',
182
+ regex: /\*\//,
183
+ next: 'start',
184
+ },
185
+ {
186
+ defaultToken: 'comment.block',
187
+ },
188
+ ],
189
+
190
+ doc_comment: [
191
+ {
192
+ token: 'comment.block.documentation',
193
+ regex: /\*\//,
194
+ next: 'start',
195
+ },
196
+ {
197
+ token: 'keyword.other.documentation',
198
+ regex: /@(?:param|returns?|description|example)\b/,
199
+ },
200
+ {
201
+ defaultToken: 'comment.block.documentation',
202
+ },
203
+ ],
204
+
205
+ template_string: [
206
+ {
207
+ token: 'string.template',
208
+ regex: /`/,
209
+ next: 'start',
210
+ },
211
+ {
212
+ token: 'constant.character.escape',
213
+ regex: /\\./,
214
+ },
215
+ {
216
+ token: 'paren.quasi.start',
217
+ regex: /\$\{/,
218
+ push: 'template_expression',
219
+ },
220
+ {
221
+ defaultToken: 'string.template',
222
+ },
223
+ ],
224
+
225
+ template_expression: [
226
+ {
227
+ token: 'paren.quasi.end',
228
+ regex: /\}/,
229
+ next: 'pop',
230
+ },
231
+ {
232
+ include: 'start',
233
+ },
234
+ ],
235
+ }
236
+
237
+ this.normalizeRules()
238
+ }
239
+
240
+ oop.inherits(AjsHighlightRules, TextHighlightRules)
241
+
242
+ return AjsHighlightRules
243
+ }
244
+
245
+ /**
246
+ * Create the AsyncJS mode for Ace
247
+ */
248
+ function createAjsMode(ace) {
249
+ const oop = ace.require('ace/lib/oop')
250
+ const TextMode = ace.require('ace/mode/text').Mode
251
+ const MatchingBraceOutdent = ace.require(
252
+ 'ace/mode/matching_brace_outdent'
253
+ ).MatchingBraceOutdent
254
+ const CstyleBehaviour = ace.require(
255
+ 'ace/mode/behaviour/cstyle'
256
+ ).CstyleBehaviour
257
+ const CStyleFoldMode = ace.require('ace/mode/folding/cstyle').FoldMode
258
+
259
+ const AjsHighlightRules = createAjsHighlightRules(ace)
260
+
261
+ function AjsMode() {
262
+ this.HighlightRules = AjsHighlightRules
263
+ this.$outdent = new MatchingBraceOutdent()
264
+ this.$behaviour = new CstyleBehaviour()
265
+ this.foldingRules = new CStyleFoldMode()
266
+ }
267
+
268
+ oop.inherits(AjsMode, TextMode)
269
+ ;(function () {
270
+ this.lineCommentStart = '//'
271
+ this.blockComment = { start: '/*', end: '*/' }
272
+
273
+ this.getNextLineIndent = function (state, line, tab) {
274
+ let indent = this.$getIndent(line)
275
+ if (state === 'start') {
276
+ const match = line.match(/^.*[{(\[]\s*$/)
277
+ if (match) {
278
+ indent += tab
279
+ }
280
+ }
281
+ return indent
282
+ }
283
+
284
+ this.checkOutdent = function (state, line, input) {
285
+ return this.$outdent.checkOutdent(line, input)
286
+ }
287
+
288
+ this.autoOutdent = function (state, doc, row) {
289
+ this.$outdent.autoOutdent(doc, row)
290
+ }
291
+
292
+ this.$id = 'ace/mode/ajs'
293
+ }).call(AjsMode.prototype)
294
+
295
+ return AjsMode
296
+ }
297
+
298
+ /**
299
+ * Register AsyncJS mode with Ace editor
300
+ *
301
+ * @param {object} ace - The Ace editor instance
302
+ */
303
+ export function registerAjsMode(ace) {
304
+ const AjsMode = createAjsMode(ace)
305
+ ace.define(
306
+ 'ace/mode/ajs',
307
+ ['require', 'exports', 'module'],
308
+ function (require, exports) {
309
+ exports.Mode = AjsMode
310
+ }
311
+ )
312
+ }
313
+
314
+ // Auto-register if Ace is available globally
315
+ if (typeof window !== 'undefined' && window.ace) {
316
+ registerAjsMode(window.ace)
317
+ }
318
+
319
+ // Export for CommonJS/AMD
320
+ if (typeof module !== 'undefined' && module.exports) {
321
+ module.exports = {
322
+ registerAjsMode,
323
+ FORBIDDEN_KEYWORDS,
324
+ KEYWORDS,
325
+ CONSTANTS,
326
+ BUILTINS,
327
+ }
328
+ }
@@ -0,0 +1,269 @@
1
+ /**
2
+ * Ace Editor Mode for AsyncJS
3
+ *
4
+ * Usage:
5
+ * ```typescript
6
+ * import ace from 'ace-builds'
7
+ * import { registerAjsMode } from 'tjs-lang/editors/ace/ajs-mode'
8
+ *
9
+ * registerAjsMode(ace)
10
+ * const editor = ace.edit('editor')
11
+ * editor.session.setMode('ace/mode/ajs')
12
+ * ```
13
+ */
14
+
15
+ import {
16
+ KEYWORDS as KEYWORDS_LIST,
17
+ FORBIDDEN_KEYWORDS as FORBIDDEN_LIST,
18
+ TYPE_CONSTRUCTORS,
19
+ } from '../ajs-syntax'
20
+
21
+ // Re-export from shared definition for backwards compatibility
22
+ export const FORBIDDEN_KEYWORDS = [...FORBIDDEN_LIST]
23
+ export const KEYWORDS = [...KEYWORDS_LIST]
24
+ export const CONSTANTS = ['true', 'false', 'null', 'undefined']
25
+ export const BUILTINS = [...TYPE_CONSTRUCTORS]
26
+
27
+ type AceEditor = typeof import('ace-builds')
28
+
29
+ /**
30
+ * Create the AsyncJS highlight rules for Ace
31
+ */
32
+ function createAjsHighlightRules(ace: AceEditor) {
33
+ const oop = ace.require('ace/lib/oop')
34
+ const TextHighlightRules = ace.require(
35
+ 'ace/mode/text_highlight_rules'
36
+ ).TextHighlightRules
37
+
38
+ function AjsHighlightRules(this: any) {
39
+ const keywordMapper = this.createKeywordMapper(
40
+ {
41
+ 'invalid.illegal': FORBIDDEN_KEYWORDS.join('|'),
42
+ keyword: KEYWORDS.join('|'),
43
+ 'constant.language': CONSTANTS.join('|'),
44
+ 'support.function': BUILTINS.join('|'),
45
+ },
46
+ 'identifier'
47
+ )
48
+
49
+ this.$rules = {
50
+ start: [
51
+ // Comments
52
+ {
53
+ token: 'comment.line',
54
+ regex: /\/\/.*$/,
55
+ },
56
+ {
57
+ token: 'comment.block.documentation',
58
+ regex: /\/\*\*/,
59
+ next: 'doc_comment',
60
+ },
61
+ {
62
+ token: 'comment.block',
63
+ regex: /\/\*/,
64
+ next: 'block_comment',
65
+ },
66
+
67
+ // Strings - must come before keywords to avoid highlighting inside strings
68
+ {
69
+ token: 'string.quoted.single',
70
+ regex: /'(?:[^'\\]|\\.)*'/,
71
+ },
72
+ {
73
+ token: 'string.quoted.double',
74
+ regex: /"(?:[^"\\]|\\.)*"/,
75
+ },
76
+ // Template literals with embedded expressions
77
+ {
78
+ token: 'string.template',
79
+ regex: /`/,
80
+ next: 'template_string',
81
+ },
82
+
83
+ // Numbers
84
+ {
85
+ token: 'constant.numeric.float',
86
+ regex: /\d+\.\d+(?:[eE][+-]?\d+)?/,
87
+ },
88
+ {
89
+ token: 'constant.numeric.hex',
90
+ regex: /0[xX][0-9a-fA-F]+/,
91
+ },
92
+ {
93
+ token: 'constant.numeric',
94
+ regex: /\d+/,
95
+ },
96
+
97
+ // Function definition
98
+ {
99
+ token: ['keyword', 'text', 'entity.name.function'],
100
+ regex: /(function)(\s+)([a-zA-Z_$][a-zA-Z0-9_$]*)/,
101
+ },
102
+
103
+ // Keywords and identifiers
104
+ {
105
+ token: keywordMapper,
106
+ regex: /[a-zA-Z_$][a-zA-Z0-9_$]*/,
107
+ },
108
+
109
+ // Operators
110
+ {
111
+ token: 'keyword.operator',
112
+ regex: /\+\+|--|\*\*|&&|\|\||==|!=|>=|<=|=>|[+\-*/%=<>!&|^~?:]/,
113
+ },
114
+
115
+ // Brackets
116
+ {
117
+ token: 'paren.lparen',
118
+ regex: /[{(\[]/,
119
+ },
120
+ {
121
+ token: 'paren.rparen',
122
+ regex: /[})\]]/,
123
+ },
124
+
125
+ // Punctuation
126
+ {
127
+ token: 'punctuation',
128
+ regex: /[;,.:]/,
129
+ },
130
+ ],
131
+
132
+ block_comment: [
133
+ {
134
+ token: 'comment.block',
135
+ regex: /\*\//,
136
+ next: 'start',
137
+ },
138
+ {
139
+ defaultToken: 'comment.block',
140
+ },
141
+ ],
142
+
143
+ doc_comment: [
144
+ {
145
+ token: 'comment.block.documentation',
146
+ regex: /\*\//,
147
+ next: 'start',
148
+ },
149
+ {
150
+ token: 'keyword.other.documentation',
151
+ regex: /@(?:param|returns?|description|example)\b/,
152
+ },
153
+ {
154
+ defaultToken: 'comment.block.documentation',
155
+ },
156
+ ],
157
+
158
+ template_string: [
159
+ {
160
+ token: 'string.template',
161
+ regex: /`/,
162
+ next: 'start',
163
+ },
164
+ {
165
+ token: 'constant.character.escape',
166
+ regex: /\\./,
167
+ },
168
+ {
169
+ token: 'paren.quasi.start',
170
+ regex: /\$\{/,
171
+ push: 'template_expression',
172
+ },
173
+ {
174
+ defaultToken: 'string.template',
175
+ },
176
+ ],
177
+
178
+ template_expression: [
179
+ {
180
+ token: 'paren.quasi.end',
181
+ regex: /\}/,
182
+ next: 'pop',
183
+ },
184
+ {
185
+ include: 'start',
186
+ },
187
+ ],
188
+ }
189
+
190
+ this.normalizeRules()
191
+ }
192
+
193
+ oop.inherits(AjsHighlightRules, TextHighlightRules)
194
+
195
+ return AjsHighlightRules
196
+ }
197
+
198
+ /**
199
+ * Create the AsyncJS mode for Ace
200
+ */
201
+ function createAjsMode(ace: AceEditor) {
202
+ const oop = ace.require('ace/lib/oop')
203
+ const TextMode = ace.require('ace/mode/text').Mode
204
+ const MatchingBraceOutdent = ace.require(
205
+ 'ace/mode/matching_brace_outdent'
206
+ ).MatchingBraceOutdent
207
+ const CstyleBehaviour = ace.require(
208
+ 'ace/mode/behaviour/cstyle'
209
+ ).CstyleBehaviour
210
+ const CStyleFoldMode = ace.require('ace/mode/folding/cstyle').FoldMode
211
+
212
+ const AjsHighlightRules = createAjsHighlightRules(ace)
213
+
214
+ function AjsMode(this: any) {
215
+ this.HighlightRules = AjsHighlightRules
216
+ this.$outdent = new MatchingBraceOutdent()
217
+ this.$behaviour = new CstyleBehaviour()
218
+ this.foldingRules = new CStyleFoldMode()
219
+ }
220
+
221
+ oop.inherits(AjsMode, TextMode)
222
+ ;(function (this: any) {
223
+ this.lineCommentStart = '//'
224
+ this.blockComment = { start: '/*', end: '*/' }
225
+
226
+ this.getNextLineIndent = function (
227
+ state: string,
228
+ line: string,
229
+ tab: string
230
+ ) {
231
+ let indent = this.$getIndent(line)
232
+ if (state === 'start') {
233
+ const match = line.match(/^.*[{(\[]\s*$/)
234
+ if (match) {
235
+ indent += tab
236
+ }
237
+ }
238
+ return indent
239
+ }
240
+
241
+ this.checkOutdent = function (state: string, line: string, input: string) {
242
+ return this.$outdent.checkOutdent(line, input)
243
+ }
244
+
245
+ this.autoOutdent = function (state: string, doc: any, row: number) {
246
+ this.$outdent.autoOutdent(doc, row)
247
+ }
248
+
249
+ this.$id = 'ace/mode/ajs'
250
+ }).call(AjsMode.prototype)
251
+
252
+ return AjsMode
253
+ }
254
+
255
+ /**
256
+ * Register AsyncJS mode with Ace editor
257
+ *
258
+ * @param ace - The Ace editor instance
259
+ */
260
+ export function registerAjsMode(ace: AceEditor): void {
261
+ const AjsMode = createAjsMode(ace)
262
+ ace.define(
263
+ 'ace/mode/ajs',
264
+ ['require', 'exports', 'module'],
265
+ function (_require: any, exports: any) {
266
+ exports.Mode = AjsMode
267
+ }
268
+ )
269
+ }