import { GraderSpecificationFor } from "../graders/QuestionGrader"; import { ResponseHandler, SubmissionType } from "./responses"; /** * ## Code Editor Response Element Specification * * A code editor response element facilitates open-ended code-writing questions. Here's an example: * * ![image](media://response-sample-code-editor.png) * * ```typescript * export const Practice_Question_List_Index_Of : QuestionSpecification = { * question_id: "recursion_list_index_of", * tags: [], * points: 8, * mk_description: * `For this question, you will work with a structure of nodes (see reference material) representing a **singly linked list** of integers. * * Consider the \`index_of\` function below, which searches a **singly linked list** represented by \`Node\`s for a particular value and returns the 0-based index at which that value first occurs (or \`-1\` if the value is not found). * * The \`index_of\` function internally calls a helper function \`index_of_helper\`, passing in an initial value of \`0\` for the \`index\` parameter: * * \`\`\`cpp * // EFFECTS: Returns the index at which 'value' first occurs in the * // given list. If the value does not occur, returns -1. * Node *index_of(Node *node, int value) { * return index_of_helper(node, value, 0); * } * \`\`\` * * Implement the \`index_of_helper\` function below. * * - Your implementation should work correctly for any list. * - Your code **must** use recursion (and **may not** use any loops). * - Your implementation must be **tail recursive**. * - You may not call any functions, other than calling \`index_of_helper\` recursively.`, * response: { * kind: "code_editor", * codemirror_mime_type: "text/x-c++src", * code_language: "cpp", * header: "int index_of_helper(Node *node, int value, int index) {", * starter: "", * footer: "}", * sample_solution: * `if (!node) { * return -1; * } * if (node->datum == value) { * return index; * } * return index_of_helper(node->next, value, index + 1);` * } * }; * ``` * * ### Syntax Highlighting and Language Support * * You'll want to specify the language you're working with in two places. * * - `code_language`: For highlighting in the header/footer, specify the alias for any * [highlightjs supported language](https://highlightjs.readthedocs.io/en/latest/supported-languages.html). * For no highlighting, specify `"text"`. * * - `codemirror_mime_type`: For syntax highlighting and language support within * the code editor itself, specify one of the [MIME types supported by CodeMirror](https://codemirror.net/mode/) * (click into the language you want, then scroll to the bottom to see the relevant MIME type). * For no highlighting, specify `"null"`. * * ### Header, Footer, Starter Code * * The `header` and `footer` options specify code above/below the editor. Students can't * edit the header/footer code. The `starter` options specifies code to initially * populate the code editor, which students can change. * * ### Code Editor Submissions * * A submission for an code editor response is simply a string with whatever content * was in the code editor box. See [[`CodeEditorSubmission`]] for details. * */ export type CodeEditorSpecification = { kind: "code_editor"; code_language: string; codemirror_mime_type: string; starter: string; header?: string; footer?: string; sample_solution?: SubmissionType<"code_editor">; default_grader?: GraderSpecificationFor<"code_editor">; }; /** * A submission for a code editor response is simply a string with whatever content * was in the code editor box. */ export type CodeEditorSubmission = string; export declare const CODE_EDITOR_HANDLER: ResponseHandler<"code_editor">;