Skip to content
Merged
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
15 changes: 14 additions & 1 deletion packages/struktolab/src/common/code-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,19 @@ function countLoopHeader(text, lang) {
}
}

/** The catch text is written Java-style, "Exception e". */
function catchClause(text, lang) {
if (lang === "python") {
const match = /^\s*(\S+)\s+(\w+)\s*$/.exec(text);
return match ? `${match[1]} as ${match[2]}` : text;
}
if (lang === "javascript") {
const match = /(\w+)\s*$/.exec(text);
return match ? match[1] : text;
}
return text;
}

/**
* Generate source code from a struktog tree.
* @param {Object} tree - The struktog tree (root InsertNode)
Expand Down Expand Up @@ -242,7 +255,7 @@ function transform(node, level, t, lang) {
indent(level) +
(t.rightBracket ? t.rightBracket + " " : "") +
t.TryCatchNode.between +
text +
catchClause(text, lang) +
t.TryCatchNode.post +
(t.leftBracket ? " " + t.leftBracket + "\n" : ""),
);
Expand Down
Loading