rip-lang 1.2.1 → 1.2.2
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/docs/dist/rip.browser.js
CHANGED
|
@@ -6818,8 +6818,8 @@ function compileToJS(source, options = {}) {
|
|
|
6818
6818
|
return compiler.compileToJS(source);
|
|
6819
6819
|
}
|
|
6820
6820
|
// src/browser.js
|
|
6821
|
-
var VERSION = "1.2.
|
|
6822
|
-
var BUILD_DATE = "2025-11-04@08:
|
|
6821
|
+
var VERSION = "1.2.2";
|
|
6822
|
+
var BUILD_DATE = "2025-11-04@08:29:18GMT";
|
|
6823
6823
|
var dedent = (s) => {
|
|
6824
6824
|
const m = s.match(/^[ \t]*(?=\S)/gm);
|
|
6825
6825
|
const i = Math.min(...(m || []).map((x) => x.length));
|
|
@@ -238,4 +238,4 @@ ${this.indent()}}`}return`{ if (${this.generate(U,"value")}) ${this.generate(M,"
|
|
|
238
238
|
`:"",M=Y.slice(0,E).join(`
|
|
239
239
|
`)}let _=new x1().tokenize(M);if(this.options.showTokens)_.forEach((F)=>{console.log(`${F[0].padEnd(12)} ${JSON.stringify(F[1])}`)}),console.log();A1.lexer={tokens:_,pos:0,setInput:function(F,G){},lex:function(){if(this.pos>=this.tokens.length)return 1;let F=this.tokens[this.pos++];return this.yytext=F[1],this.yylloc=F[2],F[0]}};let A;try{A=A1.parse(M)}catch(F){if(/\?\s*\([^)]*\?[^)]*:[^)]*\)\s*:/.test(M)||/\?\s+\w+\s+\?\s+/.test(M))throw new Error(`Nested ternary operators are not supported. Use if/else statements instead:
|
|
240
240
|
Instead of: x ? (y ? a : b) : c
|
|
241
|
-
Use: if x then (if y then a else b) else c`);throw F}if(this.options.showSExpr)console.log(_1(A,0,!0)),console.log();let R=new R1({dataSection:U}).compile(A);return{tokens:_,sexpr:A,code:R,data:U}}compileToJS(M){return this.compile(M).code}compileToSExpr(M){return this.compile(M).sexpr}}function o2(M,U={}){return new N1(U).compile(M)}function K1(M,U={}){return new N1(U).compileToJS(M)}var G3="1.2.
|
|
241
|
+
Use: if x then (if y then a else b) else c`);throw F}if(this.options.showSExpr)console.log(_1(A,0,!0)),console.log();let R=new R1({dataSection:U}).compile(A);return{tokens:_,sexpr:A,code:R,data:U}}compileToJS(M){return this.compile(M).code}compileToSExpr(M){return this.compile(M).sexpr}}function o2(M,U={}){return new N1(U).compile(M)}function K1(M,U={}){return new N1(U).compileToJS(M)}var G3="1.2.2",Z3="2025-11-04@08:29:18GMT",t2=(M)=>{let U=M.match(/^[ \t]*(?=\S)/gm),Y=Math.min(...(U||[]).map((E)=>E.length));return M.replace(RegExp(`^[ ]{${Y}}`,"gm"),"").trim()};async function v2(){let M=document.querySelectorAll('script[type="text/rip"]');for(let U of M){if(U.hasAttribute("data-rip-processed"))continue;try{let Y=t2(U.textContent),E=K1(Y);(0,eval)(E),U.setAttribute("data-rip-processed","true")}catch(Y){console.error("Error compiling Rip script:",Y),console.error("Script content:",U.textContent)}}}if(typeof document!=="undefined")if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",v2);else v2();function e2(M){try{let Y=K1(M).replace(/^let\s+[^;]+;\s*\n\s*/m,"");Y=Y.replace(/^const\s+/gm,"var ");let E=(0,eval)(Y);if(E!==void 0)globalThis._=E;return E}catch(U){console.error("Rip compilation error:",U.message);return}}if(typeof globalThis!=="undefined")globalThis.rip=e2;export{e2 as rip,v2 as processRipScripts,A1 as parser,_1 as formatSExpr,K1 as compileToJS,o2 as compile,G3 as VERSION,x1 as Lexer,N1 as Compiler,R1 as CodeGenerator,Z3 as BUILD_DATE};
|
|
Binary file
|
package/docs/repl.html
CHANGED
|
@@ -234,6 +234,38 @@
|
|
|
234
234
|
font-size: 13px;
|
|
235
235
|
font-weight: 600;
|
|
236
236
|
color: #cccccc;
|
|
237
|
+
display: flex;
|
|
238
|
+
justify-content: space-between;
|
|
239
|
+
align-items: center;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
.pane-header-buttons {
|
|
243
|
+
display: flex;
|
|
244
|
+
gap: 8px;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
.pane-header button {
|
|
248
|
+
background: #5a5a5d;
|
|
249
|
+
color: #ffffff;
|
|
250
|
+
border: none;
|
|
251
|
+
padding: 6px 12px;
|
|
252
|
+
border-radius: 3px;
|
|
253
|
+
font-size: 12px;
|
|
254
|
+
font-weight: 500;
|
|
255
|
+
cursor: pointer;
|
|
256
|
+
transition: background 0.2s;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
.pane-header button:hover {
|
|
260
|
+
background: #6e6e71;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
.pane-header button.active {
|
|
264
|
+
background: #007acc;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
.pane-header button.active:hover {
|
|
268
|
+
background: #005a9e;
|
|
237
269
|
}
|
|
238
270
|
|
|
239
271
|
.editor, .output-code {
|
|
@@ -257,26 +289,6 @@
|
|
|
257
289
|
overflow: auto;
|
|
258
290
|
}
|
|
259
291
|
|
|
260
|
-
.compiler-options {
|
|
261
|
-
padding: 10px 15px;
|
|
262
|
-
background: #252526;
|
|
263
|
-
border-top: 1px solid #3e3e42;
|
|
264
|
-
display: flex;
|
|
265
|
-
gap: 15px;
|
|
266
|
-
font-size: 12px;
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
.compiler-options label {
|
|
270
|
-
display: flex;
|
|
271
|
-
align-items: center;
|
|
272
|
-
gap: 6px;
|
|
273
|
-
color: #cccccc;
|
|
274
|
-
cursor: pointer;
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
.compiler-options input[type="checkbox"] {
|
|
278
|
-
cursor: pointer;
|
|
279
|
-
}
|
|
280
292
|
|
|
281
293
|
/* Scrollbar styling */
|
|
282
294
|
::-webkit-scrollbar {
|
|
@@ -339,13 +351,13 @@
|
|
|
339
351
|
</div>
|
|
340
352
|
|
|
341
353
|
<div class="tabs">
|
|
342
|
-
<button class="tab active" data-tab="
|
|
343
|
-
<button class="tab" data-tab="
|
|
354
|
+
<button class="tab active" data-tab="compiler">Live Compiler</button>
|
|
355
|
+
<button class="tab" data-tab="repl">REPL Console</button>
|
|
344
356
|
</div>
|
|
345
357
|
|
|
346
358
|
<div class="content">
|
|
347
359
|
<!-- REPL Pane -->
|
|
348
|
-
<div class="pane
|
|
360
|
+
<div class="pane" id="repl-pane">
|
|
349
361
|
<div class="repl-container">
|
|
350
362
|
<div class="repl-output" id="repl-output">
|
|
351
363
|
<div class="welcome">
|
|
@@ -361,10 +373,16 @@
|
|
|
361
373
|
</div>
|
|
362
374
|
|
|
363
375
|
<!-- Compiler Pane -->
|
|
364
|
-
<div class="pane" id="compiler-pane">
|
|
376
|
+
<div class="pane active" id="compiler-pane">
|
|
365
377
|
<div class="compiler-container">
|
|
366
378
|
<div class="editor-pane" id="editor-left">
|
|
367
|
-
<div class="pane-header">
|
|
379
|
+
<div class="pane-header">
|
|
380
|
+
<span>Rip Source</span>
|
|
381
|
+
<div class="pane-header-buttons">
|
|
382
|
+
<button id="clear-btn" title="Clear the editor">Clear</button>
|
|
383
|
+
<button class="active" id="run-btn" title="Execute code and output to browser console">Run</button>
|
|
384
|
+
</div>
|
|
385
|
+
</div>
|
|
368
386
|
<textarea class="editor" id="editor" spellcheck="false"># Rip code - edit me!
|
|
369
387
|
def fibonacci(n)
|
|
370
388
|
if n <= 1
|
|
@@ -391,18 +409,14 @@ console.log "Domain:", domain</textarea>
|
|
|
391
409
|
<div class="resizer" id="resizer"></div>
|
|
392
410
|
|
|
393
411
|
<div class="editor-pane" id="editor-right">
|
|
394
|
-
<div class="pane-header">
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
<
|
|
399
|
-
|
|
400
|
-
</label>
|
|
401
|
-
<label>
|
|
402
|
-
<input type="checkbox" id="show-tokens">
|
|
403
|
-
Show Tokens
|
|
404
|
-
</label>
|
|
412
|
+
<div class="pane-header">
|
|
413
|
+
<span>Generated JavaScript</span>
|
|
414
|
+
<div class="pane-header-buttons">
|
|
415
|
+
<button id="show-sexp" title="Toggle S-expression display">S-Expressions</button>
|
|
416
|
+
<button id="show-tokens" title="Toggle token stream display">Tokens</button>
|
|
417
|
+
</div>
|
|
405
418
|
</div>
|
|
419
|
+
<pre class="output-code" id="output"></pre>
|
|
406
420
|
</div>
|
|
407
421
|
</div>
|
|
408
422
|
</div>
|
|
@@ -712,8 +726,12 @@ console.log "Domain:", domain</textarea>
|
|
|
712
726
|
|
|
713
727
|
const editor = document.getElementById('editor');
|
|
714
728
|
const output = document.getElementById('output');
|
|
715
|
-
const
|
|
716
|
-
const
|
|
729
|
+
const showSexpBtn = document.getElementById('show-sexp');
|
|
730
|
+
const showTokensBtn = document.getElementById('show-tokens');
|
|
731
|
+
|
|
732
|
+
// Track toggle state
|
|
733
|
+
let showSexp = false;
|
|
734
|
+
let showTokens = false;
|
|
717
735
|
|
|
718
736
|
// Strip utility helper functions for cleaner display
|
|
719
737
|
function stripHelpers(code) {
|
|
@@ -755,14 +773,14 @@ console.log "Domain:", domain</textarea>
|
|
|
755
773
|
|
|
756
774
|
let outputText = '';
|
|
757
775
|
|
|
758
|
-
if (showTokens
|
|
776
|
+
if (showTokens) {
|
|
759
777
|
result.tokens.forEach(t => {
|
|
760
778
|
outputText += `${t[0].padEnd(12)} ${JSON.stringify(t[1])}\n`;
|
|
761
779
|
});
|
|
762
780
|
outputText += '\n';
|
|
763
781
|
}
|
|
764
782
|
|
|
765
|
-
if (showSexp
|
|
783
|
+
if (showSexp) {
|
|
766
784
|
outputText += window.toSexpr ? window.toSexpr(result.sexpr, 0, true) : JSON.stringify(result.sexpr, null, 1);
|
|
767
785
|
outputText += '\n\n';
|
|
768
786
|
}
|
|
@@ -778,8 +796,43 @@ console.log "Domain:", domain</textarea>
|
|
|
778
796
|
|
|
779
797
|
// Auto-compile on changes
|
|
780
798
|
editor.addEventListener('input', compileCode);
|
|
781
|
-
|
|
782
|
-
|
|
799
|
+
|
|
800
|
+
// Toggle buttons for S-Expressions and Tokens
|
|
801
|
+
showSexpBtn.addEventListener('click', () => {
|
|
802
|
+
showSexp = !showSexp;
|
|
803
|
+
showSexpBtn.classList.toggle('active', showSexp);
|
|
804
|
+
compileCode();
|
|
805
|
+
});
|
|
806
|
+
|
|
807
|
+
showTokensBtn.addEventListener('click', () => {
|
|
808
|
+
showTokens = !showTokens;
|
|
809
|
+
showTokensBtn.classList.toggle('active', showTokens);
|
|
810
|
+
compileCode();
|
|
811
|
+
});
|
|
812
|
+
|
|
813
|
+
// Clear button - clears the Rip source editor
|
|
814
|
+
document.getElementById('clear-btn').addEventListener('click', () => {
|
|
815
|
+
editor.value = '';
|
|
816
|
+
compileCode();
|
|
817
|
+
editor.focus();
|
|
818
|
+
});
|
|
819
|
+
|
|
820
|
+
// Run button - executes the Rip code and outputs to console
|
|
821
|
+
document.getElementById('run-btn').addEventListener('click', () => {
|
|
822
|
+
try {
|
|
823
|
+
const source = editor.value;
|
|
824
|
+
const result = compile(source);
|
|
825
|
+
const js = result.code;
|
|
826
|
+
|
|
827
|
+
// Execute the compiled JavaScript and log to console
|
|
828
|
+
console.clear();
|
|
829
|
+
console.log('%c=== Rip Code Execution ===', 'color: #007acc; font-weight: bold');
|
|
830
|
+
eval(js);
|
|
831
|
+
console.log('%c=== Execution Complete ===', 'color: #4ec9b0; font-weight: bold');
|
|
832
|
+
} catch (error) {
|
|
833
|
+
console.error('Execution Error:', error);
|
|
834
|
+
}
|
|
835
|
+
});
|
|
783
836
|
|
|
784
837
|
// Initial compile
|
|
785
838
|
compileCode();
|