Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/struktolab/src/common/pseudocode-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ function placeholder() {
* "x > 0" → { text: "x > 0", columnWidths: null }
*/
function extractColumnWidths(str) {
const match = str.match(/^(.*?)\s*\[([0-9.,\s]+)\]\s*$/);
const match = str.match(/^(.*?)\s+\[([0-9.,\s]+)\]\s*$/);
if (match) {
const text = match[1].trim();
const widths = match[2].split(",").map(s => parseFloat(s.trim())).filter(n => !isNaN(n));
Expand Down
11 changes: 11 additions & 0 deletions packages/struktolab/src/common/pseudocode-parser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,14 @@ test("keeps the body of a line it does not understand", () => {
const out = roundTrip('while x > 0:\n x = x - 1\n output("x")\ny = 1');
assert.equal(out, 'while x > 0:\nx = x - 1\noutput("x")\ny = 1');
});

test("keeps an index at the end of a condition", () => {
const code = "switch notes[0]:\n case 1:\n y = 1";
assert.equal(roundTrip(code), code);
});

test("reads column widths after the condition", () => {
const tree = parsePseudocode("if a[0] > 1 [0.7, 0.3]:\n y = 1\nelse:\n y = 2", KEYWORDS_EN);
assert.equal(tree.followElement.text, "a[0] > 1");
assert.deepEqual(tree.followElement.columnWidths, [0.7, 0.3]);
});
Loading