rip-lang 3.6.1 → 3.7.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.
Binary file
package/docs/index.html CHANGED
@@ -564,7 +564,8 @@
564
564
  <div class="pane-header-buttons">
565
565
  <button id="show-tokens" title="Toggle token stream display">Tokens</button>
566
566
  <button id="show-sexp" title="Toggle S-expression display">S-Expressions</button>
567
- <button id="show-runtime" title="Toggle runtime code display">Runtime</button>
567
+ <button id="show-preamble" title="Toggle preamble code display">Preamble</button>
568
+ <button id="show-types" title="Toggle .d.ts type declarations">Types</button>
568
569
  <button id="show-js" title="Toggle JavaScript output">JS</button>
569
570
  </div>
570
571
  </div>
@@ -933,7 +934,8 @@ console.log "Domain:", domain`;
933
934
 
934
935
  const showTokensBtn = document.getElementById('show-tokens');
935
936
  const showSexpBtn = document.getElementById('show-sexp');
936
- const showRuntimeBtn = document.getElementById('show-runtime');
937
+ const showPreambleBtn = document.getElementById('show-preamble');
938
+ const showTypesBtn = document.getElementById('show-types');
937
939
  const showJSBtn = document.getElementById('show-js');
938
940
  const replOutput = document.getElementById('repl-output');
939
941
  const promptSpan = document.getElementById('prompt');
@@ -981,46 +983,67 @@ console.log "Domain:", domain`;
981
983
 
982
984
  let showTokens = localStorage.getItem('rip-repl-tokens') === 'true';
983
985
  let showSexp = localStorage.getItem('rip-repl-sexp') === 'true';
984
- let showRuntime = localStorage.getItem('rip-repl-runtime') === 'true';
986
+ let showPreamble = localStorage.getItem('rip-preamble') === 'true';
987
+ let showTypes = localStorage.getItem('rip-types') === 'true';
985
988
  let showJS = localStorage.getItem('rip-repl-js') !== 'false'; // default true
986
989
 
987
- function stripHelpers(code) {
988
- code = code.replace(/^const slice = \[\]\.slice;\n/m, '');
989
- code = code.replace(/^const modulo = \(n, d\) => \{[^}]+\};\n/m, '');
990
- code = code.replace(/^const toSearchable = \(v, allowNewlines\) => \{[\s\S]+?\n\};\n/m, '');
991
- code = code.replace(/^\n+/, '');
992
- return code;
990
+ // Format tokens for display — clean, minimal output
991
+ const SUPPRESS_VALUE = new Set([
992
+ 'DEF', 'IF', 'ELSE', 'UNLESS', 'FOR', 'WHILE', 'UNTIL', 'LOOP',
993
+ 'SWITCH', 'WHEN', 'TRY', 'CATCH', 'FINALLY', 'THROW', 'RETURN',
994
+ 'CLASS', 'EXTENDS', 'SUPER', 'NEW', 'DELETE', 'TYPEOF', 'INSTANCEOF',
995
+ 'IMPORT', 'FROM', 'EXPORT', 'DEFAULT', 'ENUM', 'INTERFACE',
996
+ 'AND', 'OR', 'NOT', 'IS', 'ISNT', 'IN', 'OF',
997
+ 'TRUE', 'FALSE', 'NULL', 'UNDEFINED', 'YES', 'NO',
998
+ 'CALL_START', 'CALL_END', 'PARAM_START', 'PARAM_END',
999
+ 'INDEX_START', 'INDEX_END', 'TERMINATOR',
1000
+ ]);
1001
+
1002
+ function formatTokens(tokens) {
1003
+ let maxTag = 0;
1004
+ for (const t of tokens) maxTag = Math.max(maxTag, t[0].length);
1005
+ return tokens.map(t => {
1006
+ let tag = t[0], val = t[1];
1007
+ if (SUPPRESS_VALUE.has(tag)) return tag;
1008
+ if (tag === val || tag.toLowerCase() === val) return tag;
1009
+ if (tag === 'INDENT' || tag === 'OUTDENT') return `${tag.padEnd(maxTag)} ${val}`;
1010
+ if (tag === 'STRING' || tag === 'REGEX') return `${tag.padEnd(maxTag)} ${val}`;
1011
+ return `${tag.padEnd(maxTag)} ${JSON.stringify(val)}`;
1012
+ }).join('\n');
993
1013
  }
994
1014
 
995
1015
  function compileCode() {
996
1016
  try {
997
1017
  const source = monacoEditor.getValue();
998
- const result = compile(source);
1018
+ const opts = {};
1019
+ if (!showPreamble) opts.skipPreamble = true;
1020
+ if (showTypes) opts.types = 'emit';
1021
+ const result = compile(source, opts);
999
1022
 
1000
1023
  let parts = [];
1001
1024
 
1002
1025
  if (showTokens) {
1003
- let tokenText = '';
1004
- result.tokens.forEach(t => {
1005
- tokenText += `${t[0].padEnd(12)} ${JSON.stringify(t[1])}\n`;
1006
- });
1007
- parts.push(tokenText);
1026
+ parts.push(formatTokens(result.tokens));
1008
1027
  }
1009
1028
 
1010
1029
  if (showSexp) {
1011
1030
  parts.push(window.toSexpr ? window.toSexpr(result.sexpr, 0, true) : JSON.stringify(result.sexpr, null, 1));
1012
1031
  }
1013
1032
 
1033
+ if (showTypes && result.dts) {
1034
+ parts.push('// .d.ts\n' + result.dts.trim());
1035
+ }
1036
+
1014
1037
  if (showJS) {
1015
- const cleanCode = showRuntime ? result.code : stripHelpers(result.code);
1016
- parts.push(cleanCode);
1038
+ parts.push(result.code);
1017
1039
  }
1018
1040
 
1019
1041
  const outputText = parts.join('\n\n');
1020
1042
 
1021
1043
  // Update output editor language and content
1022
1044
  const model = outputEditor.getModel();
1023
- monaco.editor.setModelLanguage(model, (showTokens || showSexp) ? 'plaintext' : 'javascript');
1045
+ let lang = (showTokens || showSexp) ? 'plaintext' : (showTypes && !showJS) ? 'typescript' : 'javascript';
1046
+ monaco.editor.setModelLanguage(model, lang);
1024
1047
  outputEditor.setValue(outputText);
1025
1048
  } catch (error) {
1026
1049
  const model = outputEditor.getModel();
@@ -1072,7 +1095,8 @@ console.log "Domain:", domain`;
1072
1095
  // Restore toggle button states from localStorage (before page reveal)
1073
1096
  showTokensBtn.classList.toggle('active', showTokens);
1074
1097
  showSexpBtn.classList.toggle('active', showSexp);
1075
- showRuntimeBtn.classList.toggle('active', showRuntime);
1098
+ showPreambleBtn.classList.toggle('active', showPreamble);
1099
+ showTypesBtn.classList.toggle('active', showTypes);
1076
1100
  showJSBtn.classList.toggle('active', showJS);
1077
1101
 
1078
1102
  // Initialize from URL hash on page load (default to compiler)
@@ -1154,8 +1178,8 @@ console.log "Domain:", domain`;
1154
1178
  replContext.showTokens = false;
1155
1179
  replContext.__reactiveVars = {}; // Store reactive objects persistently
1156
1180
 
1157
- // Inject reactive runtime into iframe context
1158
- (function injectReactiveRuntime() {
1181
+ // Inject reactive preamble into iframe context
1182
+ (function injectReactivePreamble() {
1159
1183
  const ctx = replContext;
1160
1184
  ctx.__currentEffect = null;
1161
1185
  ctx.__pendingEffects = new Set();
@@ -1248,7 +1272,7 @@ console.log "Domain:", domain`;
1248
1272
  function evaluateRip(code) {
1249
1273
  try {
1250
1274
  // Pass reactiveVars to compiler so it knows which vars need .value access
1251
- const result = compile(code, { reactiveVars, skipReactiveRuntime: true });
1275
+ const result = compile(code, { reactiveVars, skipPreamble: true });
1252
1276
  let js = result.code;
1253
1277
 
1254
1278
  // Track new reactive variables
@@ -1410,11 +1434,7 @@ console.log "Domain:", domain`;
1410
1434
  if (evalResult.success) {
1411
1435
  // Show debug info if enabled
1412
1436
  if (replContext.showTokens) {
1413
- let tokenOutput = '';
1414
- evalResult.result.tokens.forEach(t => {
1415
- tokenOutput += `${t[0].padEnd(12)} ${JSON.stringify(t[1])}<br>`;
1416
- });
1417
- addOutput(tokenOutput, 'command-output');
1437
+ addOutput(formatTokens(evalResult.result.tokens).replace(/\n/g, '<br>'), 'command-output');
1418
1438
  }
1419
1439
 
1420
1440
  if (replContext.showSexp) {
@@ -1528,10 +1548,11 @@ console.log "Domain:", domain`;
1528
1548
  monacoEditor.onDidChangeModelContent(compileCode);
1529
1549
 
1530
1550
  const toggles = [
1531
- { btn: showTokensBtn, key: 'rip-repl-tokens', get: () => showTokens, set: v => showTokens = v },
1532
- { btn: showSexpBtn, key: 'rip-repl-sexp', get: () => showSexp, set: v => showSexp = v },
1533
- { btn: showRuntimeBtn,key: 'rip-repl-runtime', get: () => showRuntime, set: v => showRuntime = v },
1534
- { btn: showJSBtn, key: 'rip-repl-js', get: () => showJS, set: v => showJS = v },
1551
+ { btn: showTokensBtn, key: 'rip-repl-tokens', get: () => showTokens, set: v => showTokens = v },
1552
+ { btn: showSexpBtn, key: 'rip-repl-sexp', get: () => showSexp, set: v => showSexp = v },
1553
+ { btn: showPreambleBtn, key: 'rip-preamble', get: () => showPreamble, set: v => showPreamble = v },
1554
+ { btn: showTypesBtn, key: 'rip-types', get: () => showTypes, set: v => showTypes = v },
1555
+ { btn: showJSBtn, key: 'rip-repl-js', get: () => showJS, set: v => showJS = v },
1535
1556
  ];
1536
1557
 
1537
1558
  for (const { btn, key, get, set } of toggles) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rip-lang",
3
- "version": "3.6.1",
3
+ "version": "3.7.0",
4
4
  "description": "A modern language that compiles to JavaScript",
5
5
  "type": "module",
6
6
  "main": "src/compiler.js",
@@ -67,7 +67,7 @@
67
67
  "author": "Steve Shreeve <steve.shreeve@gmail.com>",
68
68
  "license": "MIT",
69
69
  "devDependencies": {
70
- "@rip-lang/api": "workspace:*",
71
- "@rip-lang/ui": "workspace:*"
70
+ "@rip-lang/api": "1.1.5",
71
+ "@rip-lang/ui": "0.2.0"
72
72
  }
73
73
  }