From bb1028f1919920a08008e87f22ff8221c2d8e7c4 Mon Sep 17 00:00:00 2001 From: RudraBJoshi Date: Mon, 18 May 2026 11:24:23 -0700 Subject: [PATCH 1/6] New Robot Pseudocode --- _includes/runners/code.html | 34 +- .../2026-05-12-AP-CSP_Pseudocode_runner.ipynb | 192 ++++++++++- _sass/open-coding/forms/code-runner.scss | 5 + .../PseudocodeExecutor.js | 2 +- .../Pseudosystem_Executors/RobotExecutor.js | 313 ++++++++++++++++++ assets/js/pages/runners/index.js | 3 +- assets/js/pages/runners/tilemaps/index.js | 275 +++++++++++++++ 7 files changed, 808 insertions(+), 16 deletions(-) rename assets/js/pages/runners/executors/{ => Pseudosystem_Executors}/PseudocodeExecutor.js (99%) create mode 100644 assets/js/pages/runners/executors/Pseudosystem_Executors/RobotExecutor.js create mode 100644 assets/js/pages/runners/tilemaps/index.js diff --git a/_includes/runners/code.html b/_includes/runners/code.html index 8be07cf464..0244c2c056 100644 --- a/_includes/runners/code.html +++ b/_includes/runners/code.html @@ -60,9 +60,12 @@ // AP CSP Pseudocode syntax highlighting mode for CodeMirror 5 if (typeof CodeMirror !== 'undefined' && !CodeMirror.modes['pseudocode']) { CodeMirror.defineMode('pseudocode', function() { - const KW = new Set(['IF','ELSE','REPEAT','TIMES','UNTIL','FOR','EACH','IN','PROCEDURE','RETURN','AND','OR','NOT','MOD']); - const BI = new Set(['DISPLAY','INPUT','APPEND','INSERT','REMOVE','LENGTH']); - const BOOL= new Set(['TRUE','FALSE']); + const KW = new Set(['IF','ELSE','REPEAT','TIMES','UNTIL','FOR','EACH','IN','PROCEDURE','RETURN','AND','OR','NOT','MOD']); + const BI = new Set(['DISPLAY','INPUT','APPEND','INSERT','REMOVE','LENGTH']); + const BOOL = new Set(['TRUE','FALSE']); + // Robot commands folded into existing token types for colour consistency + const BI_EXTRA = new Set(['MOVE_FORWARD','ROTATE_LEFT','ROTATE_RIGHT','CAN_MOVE','RENDER']); + const KW_EXTRA = new Set(['SPAWN','CHARACTER','GOAL','AT','FROM','TILEMAPS','IMPORT']); return { token: function(stream) { if (stream.eatSpace()) return null; @@ -70,11 +73,11 @@ // Comments if (stream.match('//')) { stream.skipToEnd(); return 'comment'; } - // Strings — handles curly and straight quotes + // Strings — handles curly (“ ”) and straight quotes const q = stream.peek(); - if (q === '"' || q === '“' || q === '”' || q === "'") { + if (q === '"' || q === '\u201c' || q === '\u201d' || q === "'") { stream.next(); - const close = (q === '“') ? '”' : q; + const close = (q === '\u201c') ? '\u201d' : q; while (!stream.eol() && stream.peek() !== close) stream.next(); if (!stream.eol()) stream.next(); return 'string'; @@ -83,12 +86,12 @@ // Numbers if (stream.match(/^-?\d+(\.\d*)?/)) return 'number'; - // Words: keywords / builtins / booleans / identifiers + // Words: robot commands take priority, then pseudocode keywords if (stream.match(/^[a-zA-Z_][a-zA-Z0-9_]*/)) { const w = stream.current().toUpperCase(); - if (KW.has(w)) return 'keyword'; - if (BI.has(w)) return 'builtin'; - if (BOOL.has(w)) return 'atom'; + if (KW.has(w) || KW_EXTRA.has(w)) return 'keyword'; + if (BI.has(w) || BI_EXTRA.has(w)) return 'builtin'; + if (BOOL.has(w)) return 'atom'; return 'variable'; } @@ -108,7 +111,7 @@