code-the-jewels 0.1.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 (60) hide show
  1. package/.claude/settings.local.json +7 -0
  2. package/PROMPTS/01-build-v0.1.md +10 -0
  3. package/README.md +186 -0
  4. package/dist/ast.d.ts +143 -0
  5. package/dist/ast.js +2 -0
  6. package/dist/cli.d.ts +2 -0
  7. package/dist/cli.js +145 -0
  8. package/dist/diagnostics.d.ts +7 -0
  9. package/dist/diagnostics.js +16 -0
  10. package/dist/generator.d.ts +11 -0
  11. package/dist/generator.js +126 -0
  12. package/dist/index.d.ts +7 -0
  13. package/dist/index.js +15 -0
  14. package/dist/lexer.d.ts +18 -0
  15. package/dist/lexer.js +210 -0
  16. package/dist/parser.d.ts +40 -0
  17. package/dist/parser.js +394 -0
  18. package/dist/repl.d.ts +1 -0
  19. package/dist/repl.js +132 -0
  20. package/dist/runtime/atl-data.d.ts +4 -0
  21. package/dist/runtime/atl-data.js +18 -0
  22. package/dist/runtime/atl-flow.d.ts +1 -0
  23. package/dist/runtime/atl-flow.js +5 -0
  24. package/dist/runtime/bk-parse.d.ts +3 -0
  25. package/dist/runtime/bk-parse.js +9 -0
  26. package/dist/runtime/bk-text.d.ts +5 -0
  27. package/dist/runtime/bk-text.js +13 -0
  28. package/dist/runtime/rtj-core.d.ts +1 -0
  29. package/dist/runtime/rtj-core.js +51 -0
  30. package/dist/semantic.d.ts +11 -0
  31. package/dist/semantic.js +153 -0
  32. package/dist/tests/basic.test.d.ts +1 -0
  33. package/dist/tests/basic.test.js +69 -0
  34. package/dist/token.d.ts +56 -0
  35. package/dist/token.js +77 -0
  36. package/examples/cities.rtj +11 -0
  37. package/examples/count-words.rtj +12 -0
  38. package/examples/duo.rtj +12 -0
  39. package/examples/hello.rtj +1 -0
  40. package/examples/pipes.rtj +6 -0
  41. package/package.json +22 -0
  42. package/public/_redirects +1 -0
  43. package/public/index.html +559 -0
  44. package/src/ast.ts +189 -0
  45. package/src/cli.ts +120 -0
  46. package/src/diagnostics.ts +15 -0
  47. package/src/generator.ts +129 -0
  48. package/src/index.ts +7 -0
  49. package/src/lexer.ts +208 -0
  50. package/src/parser.ts +461 -0
  51. package/src/repl.ts +105 -0
  52. package/src/runtime/atl-data.ts +11 -0
  53. package/src/runtime/atl-flow.ts +1 -0
  54. package/src/runtime/bk-parse.ts +3 -0
  55. package/src/runtime/bk-text.ts +5 -0
  56. package/src/runtime/rtj-core.ts +21 -0
  57. package/src/semantic.ts +144 -0
  58. package/src/tests/basic.test.ts +74 -0
  59. package/src/token.ts +85 -0
  60. package/tsconfig.json +15 -0
package/dist/repl.js ADDED
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.startRepl = startRepl;
37
+ const readline = __importStar(require("readline"));
38
+ const path = __importStar(require("path"));
39
+ const vm = __importStar(require("vm"));
40
+ const lexer_1 = require("./lexer");
41
+ const parser_1 = require("./parser");
42
+ const semantic_1 = require("./semantic");
43
+ const generator_1 = require("./generator");
44
+ const diagnostics_1 = require("./diagnostics");
45
+ function startRepl() {
46
+ const rl = readline.createInterface({
47
+ input: process.stdin,
48
+ output: process.stdout,
49
+ prompt: 'rtj> ',
50
+ });
51
+ // Load the runtime once
52
+ const runtimePath = path.join(__dirname, 'runtime', 'rtj-core');
53
+ const rtjCore = require(runtimePath);
54
+ // Persistent context for the REPL
55
+ const context = vm.createContext({
56
+ __rtj: rtjCore,
57
+ __modules: rtjCore.modules,
58
+ console: console,
59
+ require: require,
60
+ });
61
+ const history = [];
62
+ console.log('');
63
+ console.log(' \uD83D\uDC49{\uD83D\uDC8E}.rtj');
64
+ console.log(' Code The Jewels v0.1 \u2014 RTJ0 "The Self-Titled Era"');
65
+ console.log(' El-P (Brooklyn) & Killer Mike (Atlanta) \u2014 MIT Forever');
66
+ console.log('');
67
+ console.log(' .help for commands \u00B7 .exit to quit');
68
+ console.log('');
69
+ rl.prompt();
70
+ rl.on('line', (line) => {
71
+ const input = line.trim();
72
+ if (input === '.exit') {
73
+ process.exit(0);
74
+ }
75
+ if (input === '') {
76
+ rl.prompt();
77
+ return;
78
+ }
79
+ if (input === '.help') {
80
+ console.log('.exit quit the REPL');
81
+ console.log('.legend print version info');
82
+ console.log('.duo print duo() spec');
83
+ rl.prompt();
84
+ return;
85
+ }
86
+ if (input === '.legend') {
87
+ console.log('Code The Jewels v0.1 \u2014 RTJ0 "The Self-Titled Era"');
88
+ console.log('El-P (Brooklyn) & Killer Mike (Atlanta) \u2014 MIT Forever');
89
+ rl.prompt();
90
+ return;
91
+ }
92
+ if (input === '.duo') {
93
+ console.log('duo(input) { mike: fn el: fn }');
94
+ console.log('mike runs first (Atlanta). el responds (Brooklyn).');
95
+ console.log('Both branches required. Compiles to: el(mike(input))');
96
+ rl.prompt();
97
+ return;
98
+ }
99
+ try {
100
+ const lexer = new lexer_1.Lexer(input);
101
+ const tokens = lexer.tokenize();
102
+ const parser = new parser_1.Parser(tokens);
103
+ const ast = parser.parse();
104
+ const semantic = new semantic_1.Semantic();
105
+ semantic.analyze(ast);
106
+ const gen = new generator_1.Generator();
107
+ let js = gen.generate(ast);
108
+ // Strip the prelude since we already have the runtime in context
109
+ js = js.replace('"use strict";\n', '');
110
+ js = js.replace('const __rtj = require("./runtime/rtj-core");\n', '');
111
+ js = js.replace('const __modules = __rtj.modules;\n', '');
112
+ history.push(js);
113
+ const result = vm.runInContext(js, context);
114
+ if (result !== undefined) {
115
+ console.log(result);
116
+ }
117
+ }
118
+ catch (err) {
119
+ if (err instanceof diagnostics_1.RTJError) {
120
+ console.error(err.format());
121
+ }
122
+ else if (err instanceof Error) {
123
+ console.error(err.message);
124
+ }
125
+ else {
126
+ console.error(err);
127
+ }
128
+ }
129
+ rl.prompt();
130
+ });
131
+ rl.on('close', () => process.exit(0));
132
+ }
@@ -0,0 +1,4 @@
1
+ export declare const count: (list: unknown[]) => number;
2
+ export declare const countBy: (list: unknown[]) => Record<string, number>;
3
+ export declare const first: (list: unknown[]) => unknown;
4
+ export declare const last: (list: unknown[]) => unknown;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.last = exports.first = exports.countBy = exports.count = void 0;
4
+ const count = (list) => list.length;
5
+ exports.count = count;
6
+ const countBy = (list) => {
7
+ const map = {};
8
+ for (const item of list) {
9
+ const key = String(item);
10
+ map[key] = (map[key] || 0) + 1;
11
+ }
12
+ return map;
13
+ };
14
+ exports.countBy = countBy;
15
+ const first = (list) => list[0];
16
+ exports.first = first;
17
+ const last = (list) => list[list.length - 1];
18
+ exports.last = last;
@@ -0,0 +1 @@
1
+ export declare const identity: (x: unknown) => unknown;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.identity = void 0;
4
+ const identity = (x) => x;
5
+ exports.identity = identity;
@@ -0,0 +1,3 @@
1
+ export declare const words: (text: string) => string[];
2
+ export declare const lines: (text: string) => string[];
3
+ export declare const chars: (text: string) => string[];
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.chars = exports.lines = exports.words = void 0;
4
+ const words = (text) => text.trim().split(/\s+/).filter(w => w.length > 0);
5
+ exports.words = words;
6
+ const lines = (text) => text.split(/\r?\n/);
7
+ exports.lines = lines;
8
+ const chars = (text) => text.split('');
9
+ exports.chars = chars;
@@ -0,0 +1,5 @@
1
+ export declare const trim: (text: string) => string;
2
+ export declare const upper: (text: string) => string;
3
+ export declare const lower: (text: string) => string;
4
+ export declare const split: (text: string, sep?: string) => string[];
5
+ export declare const join: (list: string[], sep?: string) => string;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.join = exports.split = exports.lower = exports.upper = exports.trim = void 0;
4
+ const trim = (text) => text.trim();
5
+ exports.trim = trim;
6
+ const upper = (text) => text.toUpperCase();
7
+ exports.upper = upper;
8
+ const lower = (text) => text.toLowerCase();
9
+ exports.lower = lower;
10
+ const split = (text, sep) => sep ? text.split(sep) : text.split(' ');
11
+ exports.split = split;
12
+ const join = (list, sep = '') => list.join(sep);
13
+ exports.join = join;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ const modules = {};
37
+ function registerModule(name, fns) {
38
+ modules[name] = fns;
39
+ }
40
+ function talk(value) {
41
+ console.log(value);
42
+ }
43
+ const bkText = __importStar(require("./bk-text"));
44
+ const bkParse = __importStar(require("./bk-parse"));
45
+ const atlData = __importStar(require("./atl-data"));
46
+ const atlFlow = __importStar(require("./atl-flow"));
47
+ registerModule('bk:text', bkText);
48
+ registerModule('bk:parse', bkParse);
49
+ registerModule('atl:data', atlData);
50
+ registerModule('atl:flow', atlFlow);
51
+ module.exports = { talk, modules };
@@ -0,0 +1,11 @@
1
+ import { Program } from './ast';
2
+ export declare class Semantic {
3
+ private scopes;
4
+ analyze(program: Program): void;
5
+ private pushScope;
6
+ private popScope;
7
+ private declare;
8
+ private lookup;
9
+ private analyzeStatement;
10
+ private analyzeExpression;
11
+ }
@@ -0,0 +1,153 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Semantic = void 0;
4
+ const diagnostics_1 = require("./diagnostics");
5
+ const VALID_MODULES = ['bk:text', 'bk:parse', 'atl:data', 'atl:flow'];
6
+ class Semantic {
7
+ constructor() {
8
+ this.scopes = [];
9
+ }
10
+ analyze(program) {
11
+ this.pushScope();
12
+ for (const stmt of program.body) {
13
+ this.analyzeStatement(stmt);
14
+ }
15
+ this.popScope();
16
+ }
17
+ pushScope() {
18
+ this.scopes.push(new Set());
19
+ }
20
+ popScope() {
21
+ this.scopes.pop();
22
+ }
23
+ declare(name, line) {
24
+ const top = this.scopes[this.scopes.length - 1];
25
+ if (top.has(name)) {
26
+ throw new diagnostics_1.RTJError('NameError', `duplicate jewel '${name}'`, line);
27
+ }
28
+ top.add(name);
29
+ }
30
+ lookup(name) {
31
+ for (let i = this.scopes.length - 1; i >= 0; i--) {
32
+ if (this.scopes[i].has(name))
33
+ return true;
34
+ }
35
+ return false;
36
+ }
37
+ analyzeStatement(stmt) {
38
+ switch (stmt.type) {
39
+ case 'VarDecl':
40
+ this.analyzeExpression(stmt.init);
41
+ this.declare(stmt.name, stmt.loc.line);
42
+ break;
43
+ case 'FunctionDecl':
44
+ this.declare(stmt.name, stmt.loc.line);
45
+ this.pushScope();
46
+ for (const p of stmt.params) {
47
+ this.declare(p, stmt.loc.line);
48
+ }
49
+ for (const s of stmt.body.body) {
50
+ this.analyzeStatement(s);
51
+ }
52
+ this.popScope();
53
+ break;
54
+ case 'ReturnStmt':
55
+ if (stmt.value)
56
+ this.analyzeExpression(stmt.value);
57
+ break;
58
+ case 'TalkStmt':
59
+ this.analyzeExpression(stmt.value);
60
+ break;
61
+ case 'IfStmt':
62
+ this.analyzeExpression(stmt.condition);
63
+ this.pushScope();
64
+ for (const s of stmt.consequent.body)
65
+ this.analyzeStatement(s);
66
+ this.popScope();
67
+ if (stmt.alternate) {
68
+ this.pushScope();
69
+ for (const s of stmt.alternate.body)
70
+ this.analyzeStatement(s);
71
+ this.popScope();
72
+ }
73
+ break;
74
+ case 'LoopStmt':
75
+ this.analyzeExpression(stmt.iterable);
76
+ this.pushScope();
77
+ this.declare(stmt.variable, stmt.loc.line);
78
+ for (const s of stmt.body.body)
79
+ this.analyzeStatement(s);
80
+ this.popScope();
81
+ break;
82
+ case 'ImportStmt':
83
+ if (!VALID_MODULES.includes(stmt.source)) {
84
+ throw new diagnostics_1.RTJError('ImportError', `unknown feature source '${stmt.source}'`, stmt.loc.line);
85
+ }
86
+ for (const name of stmt.names) {
87
+ this.declare(name, stmt.loc.line);
88
+ }
89
+ break;
90
+ case 'ThrowStmt':
91
+ this.analyzeExpression(stmt.value);
92
+ break;
93
+ case 'ExpressionStmt':
94
+ this.analyzeExpression(stmt.expr);
95
+ break;
96
+ case 'BlockStmt':
97
+ this.pushScope();
98
+ for (const s of stmt.body)
99
+ this.analyzeStatement(s);
100
+ this.popScope();
101
+ break;
102
+ }
103
+ }
104
+ analyzeExpression(expr) {
105
+ switch (expr.type) {
106
+ case 'Identifier':
107
+ // Warn but don't error in v0.1 (runtime may provide)
108
+ break;
109
+ case 'StringLiteral':
110
+ case 'NumberLiteral':
111
+ case 'BooleanLiteral':
112
+ case 'NullLiteral':
113
+ break;
114
+ case 'ArrayLiteral':
115
+ for (const el of expr.elements)
116
+ this.analyzeExpression(el);
117
+ break;
118
+ case 'ObjectLiteral':
119
+ for (const pair of expr.pairs)
120
+ this.analyzeExpression(pair.value);
121
+ break;
122
+ case 'BinaryExpr':
123
+ this.analyzeExpression(expr.left);
124
+ this.analyzeExpression(expr.right);
125
+ break;
126
+ case 'UnaryExpr':
127
+ this.analyzeExpression(expr.operand);
128
+ break;
129
+ case 'CallExpr':
130
+ this.analyzeExpression(expr.callee);
131
+ for (const arg of expr.args)
132
+ this.analyzeExpression(arg);
133
+ break;
134
+ case 'MemberExpr':
135
+ this.analyzeExpression(expr.object);
136
+ if (expr.computed)
137
+ this.analyzeExpression(expr.property);
138
+ break;
139
+ case 'PipeExpr':
140
+ for (const step of expr.steps)
141
+ this.analyzeExpression(step);
142
+ break;
143
+ case 'DuoExpr':
144
+ this.analyzeExpression(expr.input);
145
+ for (const step of expr.mikePipeline)
146
+ this.analyzeExpression(step);
147
+ for (const step of expr.elPipeline)
148
+ this.analyzeExpression(step);
149
+ break;
150
+ }
151
+ }
152
+ }
153
+ exports.Semantic = Semantic;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const lexer_1 = require("../lexer");
4
+ const parser_1 = require("../parser");
5
+ const semantic_1 = require("../semantic");
6
+ const generator_1 = require("../generator");
7
+ function compile(source) {
8
+ const lexer = new lexer_1.Lexer(source);
9
+ const tokens = lexer.tokenize();
10
+ const parser = new parser_1.Parser(tokens);
11
+ const ast = parser.parse();
12
+ const semantic = new semantic_1.Semantic();
13
+ semantic.analyze(ast);
14
+ const gen = new generator_1.Generator();
15
+ return gen.generate(ast);
16
+ }
17
+ function test(name, fn) {
18
+ try {
19
+ fn();
20
+ console.log(`PASS: ${name}`);
21
+ }
22
+ catch (err) {
23
+ console.error(`FAIL: ${name}`);
24
+ console.error(err);
25
+ process.exitCode = 1;
26
+ }
27
+ }
28
+ function assert(condition, msg) {
29
+ if (!condition)
30
+ throw new Error(`Assertion failed: ${msg}`);
31
+ }
32
+ test('lexer tokenizes hello world', () => {
33
+ const lexer = new lexer_1.Lexer('talk "hello"');
34
+ const tokens = lexer.tokenize();
35
+ assert(tokens[0].type === 'TALK', 'first token is TALK');
36
+ assert(tokens[1].type === 'STRING', 'second token is STRING');
37
+ assert(tokens[1].value === 'hello', 'string value is hello');
38
+ });
39
+ test('parser creates TalkStmt', () => {
40
+ const lexer = new lexer_1.Lexer('talk "hello"');
41
+ const tokens = lexer.tokenize();
42
+ const parser = new parser_1.Parser(tokens);
43
+ const ast = parser.parse();
44
+ assert(ast.body.length === 1, 'one statement');
45
+ assert(ast.body[0].type === 'TalkStmt', 'is TalkStmt');
46
+ });
47
+ test('generator outputs talk call', () => {
48
+ const js = compile('talk "hello"');
49
+ assert(js.includes('__rtj.talk("hello")'), 'contains talk call');
50
+ });
51
+ test('pipe expression compiles to nested calls', () => {
52
+ const js = compile('feature trim, upper from "bk:text"\njewel x = "hi" |> trim |> upper');
53
+ assert(js.includes('upper(trim("hi"))'), 'pipe flattened correctly');
54
+ });
55
+ test('duo expression compiles', () => {
56
+ const js = compile('feature trim from "bk:text"\nfeature words from "bk:parse"\nfeature count from "atl:data"\njewel x = duo("hi") {\n mike: trim |> words\n el: count\n}');
57
+ assert(js.includes('count(words(trim("hi")))'), 'duo flattened correctly');
58
+ });
59
+ test('semantic rejects invalid import source', () => {
60
+ let threw = false;
61
+ try {
62
+ compile('feature foo from "bk:audio"');
63
+ }
64
+ catch (err) {
65
+ threw = true;
66
+ }
67
+ assert(threw, 'should throw on invalid import');
68
+ });
69
+ console.log('All tests complete.');
@@ -0,0 +1,56 @@
1
+ export declare enum TokenType {
2
+ JEWEL = "JEWEL",
3
+ VERSE = "VERSE",
4
+ SEND = "SEND",
5
+ TALK = "TALK",
6
+ IFWILD = "IFWILD",
7
+ ELSEWILD = "ELSEWILD",
8
+ RUN = "RUN",
9
+ IN = "IN",
10
+ FEATURE = "FEATURE",
11
+ FROM = "FROM",
12
+ YANK = "YANK",
13
+ DUO = "DUO",
14
+ MIKE = "MIKE",
15
+ EL = "EL",
16
+ IDENTIFIER = "IDENTIFIER",
17
+ STRING = "STRING",
18
+ NUMBER = "NUMBER",
19
+ BOOLEAN = "BOOLEAN",
20
+ NULL = "NULL",
21
+ PIPE = "PIPE",
22
+ PLUS = "PLUS",
23
+ MINUS = "MINUS",
24
+ STAR = "STAR",
25
+ SLASH = "SLASH",
26
+ PERCENT = "PERCENT",
27
+ EQ_EQ = "EQ_EQ",
28
+ BANG_EQ = "BANG_EQ",
29
+ GT = "GT",
30
+ LT = "LT",
31
+ GT_EQ = "GT_EQ",
32
+ LT_EQ = "LT_EQ",
33
+ AND_AND = "AND_AND",
34
+ OR_OR = "OR_OR",
35
+ BANG = "BANG",
36
+ ASSIGN = "ASSIGN",
37
+ LBRACE = "LBRACE",
38
+ RBRACE = "RBRACE",
39
+ LPAREN = "LPAREN",
40
+ RPAREN = "RPAREN",
41
+ LBRACKET = "LBRACKET",
42
+ RBRACKET = "RBRACKET",
43
+ COMMA = "COMMA",
44
+ COLON = "COLON",
45
+ DOT = "DOT",
46
+ SEMICOLON = "SEMICOLON",
47
+ NEWLINE = "NEWLINE",
48
+ EOF = "EOF"
49
+ }
50
+ export interface Token {
51
+ type: TokenType;
52
+ value: string;
53
+ line: number;
54
+ column: number;
55
+ }
56
+ export declare const KEYWORDS: Record<string, TokenType>;
package/dist/token.js ADDED
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.KEYWORDS = exports.TokenType = void 0;
4
+ var TokenType;
5
+ (function (TokenType) {
6
+ // Keywords
7
+ TokenType["JEWEL"] = "JEWEL";
8
+ TokenType["VERSE"] = "VERSE";
9
+ TokenType["SEND"] = "SEND";
10
+ TokenType["TALK"] = "TALK";
11
+ TokenType["IFWILD"] = "IFWILD";
12
+ TokenType["ELSEWILD"] = "ELSEWILD";
13
+ TokenType["RUN"] = "RUN";
14
+ TokenType["IN"] = "IN";
15
+ TokenType["FEATURE"] = "FEATURE";
16
+ TokenType["FROM"] = "FROM";
17
+ TokenType["YANK"] = "YANK";
18
+ TokenType["DUO"] = "DUO";
19
+ TokenType["MIKE"] = "MIKE";
20
+ TokenType["EL"] = "EL";
21
+ // Literals
22
+ TokenType["IDENTIFIER"] = "IDENTIFIER";
23
+ TokenType["STRING"] = "STRING";
24
+ TokenType["NUMBER"] = "NUMBER";
25
+ TokenType["BOOLEAN"] = "BOOLEAN";
26
+ TokenType["NULL"] = "NULL";
27
+ // Operators
28
+ TokenType["PIPE"] = "PIPE";
29
+ TokenType["PLUS"] = "PLUS";
30
+ TokenType["MINUS"] = "MINUS";
31
+ TokenType["STAR"] = "STAR";
32
+ TokenType["SLASH"] = "SLASH";
33
+ TokenType["PERCENT"] = "PERCENT";
34
+ TokenType["EQ_EQ"] = "EQ_EQ";
35
+ TokenType["BANG_EQ"] = "BANG_EQ";
36
+ TokenType["GT"] = "GT";
37
+ TokenType["LT"] = "LT";
38
+ TokenType["GT_EQ"] = "GT_EQ";
39
+ TokenType["LT_EQ"] = "LT_EQ";
40
+ TokenType["AND_AND"] = "AND_AND";
41
+ TokenType["OR_OR"] = "OR_OR";
42
+ TokenType["BANG"] = "BANG";
43
+ TokenType["ASSIGN"] = "ASSIGN";
44
+ // Punctuation
45
+ TokenType["LBRACE"] = "LBRACE";
46
+ TokenType["RBRACE"] = "RBRACE";
47
+ TokenType["LPAREN"] = "LPAREN";
48
+ TokenType["RPAREN"] = "RPAREN";
49
+ TokenType["LBRACKET"] = "LBRACKET";
50
+ TokenType["RBRACKET"] = "RBRACKET";
51
+ TokenType["COMMA"] = "COMMA";
52
+ TokenType["COLON"] = "COLON";
53
+ TokenType["DOT"] = "DOT";
54
+ TokenType["SEMICOLON"] = "SEMICOLON";
55
+ // Special
56
+ TokenType["NEWLINE"] = "NEWLINE";
57
+ TokenType["EOF"] = "EOF";
58
+ })(TokenType || (exports.TokenType = TokenType = {}));
59
+ exports.KEYWORDS = {
60
+ jewel: TokenType.JEWEL,
61
+ verse: TokenType.VERSE,
62
+ send: TokenType.SEND,
63
+ talk: TokenType.TALK,
64
+ ifwild: TokenType.IFWILD,
65
+ elsewild: TokenType.ELSEWILD,
66
+ run: TokenType.RUN,
67
+ in: TokenType.IN,
68
+ feature: TokenType.FEATURE,
69
+ from: TokenType.FROM,
70
+ yank: TokenType.YANK,
71
+ duo: TokenType.DUO,
72
+ mike: TokenType.MIKE,
73
+ el: TokenType.EL,
74
+ true: TokenType.BOOLEAN,
75
+ false: TokenType.BOOLEAN,
76
+ null: TokenType.NULL,
77
+ };
@@ -0,0 +1,11 @@
1
+ feature upper from "bk:text"
2
+ feature first, last from "atl:data"
3
+
4
+ jewel cities = ["Atlanta", "Brooklyn", "Chicago"]
5
+
6
+ verse announce(city) {
7
+ send city |> upper
8
+ }
9
+
10
+ talk announce(first(cities))
11
+ talk announce(last(cities))
@@ -0,0 +1,12 @@
1
+ feature trim, lower from "bk:text"
2
+ feature words from "bk:parse"
3
+ feature countBy from "atl:data"
4
+
5
+ jewel verse = "run the jewels run the jewels run"
6
+
7
+ jewel freq = duo(verse) {
8
+ mike: trim |> lower |> words
9
+ el: countBy
10
+ }
11
+
12
+ talk freq
@@ -0,0 +1,12 @@
1
+ feature trim from "bk:text"
2
+ feature words from "bk:parse"
3
+ feature count from "atl:data"
4
+
5
+ jewel bars = " rtj from atlanta to brooklyn "
6
+
7
+ jewel total = duo(bars) {
8
+ mike: trim |> words
9
+ el: count
10
+ }
11
+
12
+ talk total
@@ -0,0 +1 @@
1
+ talk "Run The Jewels forever"