File tree Expand file tree Collapse file tree 3 files changed +49
-0
lines changed Expand file tree Collapse file tree 3 files changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -59,6 +59,9 @@ const semanticChecks = [
5959 [ "character literals" , "f(x)='2'" ] ,
6060 [ "parentheses around a primary" , "f(x)=(3)" ] ,
6161 [ "complicated equation" , "f(x) = 1 + (2 + -3) << -4 >> (19 * 39) % x ^ 2 << 38 & 18" ] ,
62+ [ "function with slices" , "f(x) = x \\ x + 1 \\ x + 2" ] ,
63+ [ "function with slices of different types" , "f(x) = x \\ 'a' \\ x + 2" ] ,
64+ [ "printing sliced function result" , "f(x) = x \\ x + 1 \\ x + 2\nprint(f(x))" ] ,
6265] ;
6366
6467// Programs that are syntactically correct but have semantic errors
Original file line number Diff line number Diff line change @@ -463,6 +463,49 @@ const fixtures = [
463463 const globalRange = [];
464464 funktionPrint("a");
465465 ` ) ,
466+ } ,
467+ {
468+ name : "slices" ,
469+ source :
470+ "`1..9` t3t\n" +
471+ "f(x) = x \\ x + 1 \\ x + 2\n" +
472+ "f(x).step(2)\n" +
473+ "print(x:7)" ,
474+ expected : dedent ( `
475+ function generateRange(start, end, step) {
476+ const range = [];
477+ if (step === 0) step = 1;
478+ if (start <= end) {
479+ for (let i = start; i <= end; i += step) {
480+ range.push(i);
481+ }
482+ }
483+ else {
484+ for (let i = start; i >= end; i -= step) {
485+ range.push(i);
486+ }
487+ }
488+ return range;
489+ }
490+
491+ function funktionPrint(value) {
492+ if (Array.isArray(value)) {
493+ console.log(value.join('\\n'));
494+ }
495+ else {
496+ console.log(value);
497+ }
498+ }
499+
500+ const globalRange = generateRange(1, 9, 3);
501+ function f_1(x_1) {
502+ return [x_1, (x_1 + 1), (x_1 + 2)].join(' ');
503+ }
504+ let x_1 = initializeMutableRange(globalRange);
505+
506+ applyFunction(x_1, 2, f_1);
507+ funktionPrint(x_1.values.slice(0, 3));
508+ ` )
466509 }
467510] ;
468511
Original file line number Diff line number Diff line change @@ -45,6 +45,9 @@ const syntaxChecks = [
4545 ] ,
4646 [ "commenting" , 'print("hi") //This is a comment' ] ,
4747 [ "using input as a function with arithmetic operation" , "f(x)=input() + 2" ] ,
48+ [ "function with slices" , "f(x) = x \\ x + 1 \\ x + 2" ] ,
49+ [ "multi-line function with slices" , "f(x) = x \\ \n x + 1 \\ \n x + 2" ] ,
50+ [ "function with slices and step call" , "f(x) = x \\ x + 1 \\ x + 2\nf(x).step(2)" ] ,
4851] ;
4952
5053// Programs with syntax errors that the parser will detect
You can’t perform that action at this time.
0 commit comments