Skip to content

Commit

Permalink
fixed editor bugs and made a separate tab for tutorials
Browse files Browse the repository at this point in the history
  • Loading branch information
reevafaisal committed Oct 11, 2024
1 parent 8f01458 commit a6f225c
Show file tree
Hide file tree
Showing 15 changed files with 18,712 additions and 344 deletions.
42 changes: 2 additions & 40 deletions src/haz3lschool/DocumentationEnv.re
Original file line number Diff line number Diff line change
Expand Up @@ -176,48 +176,10 @@ module D = (DocEnv: DocEnv) => {
if (!instructor_mode) {
switch (pos) {
| HiddenTests
// =>
// Update the `hidden_tests` editor when position is HiddenTests
// print_endline("Updating HiddenTests editor");
// let updated_hidden_tests = documentation.eds.hidden_tests.tests;
// {
// // ...documentation,
// eds: {
// ...documentation.eds,
// hidden_tests: {
// ...documentation.eds.hidden_tests,
// tests: updated_hidden_tests,
// },
// your_impl: documentation.eds.your_impl,
// },
// pos: HiddenTests,
// };
// | YourImpl =>
// // Update the `your_impl` editor when position is YourImpl
// print_endline("Updating YourImpl editor");
// let updated_your_impl = documentation.eds.your_impl;
// {
// // ...documentation,
// eds: {
// ...documentation.eds,
// your_impl: updated_your_impl,
// hidden_tests: documentation.eds.hidden_tests,
// },
// pos: YourImpl,
// };
| _ => {
// Handle other cases by just updating the position
eds: documentation.eds,
pos,
}
| _ => {eds: documentation.eds, pos}
};
} else {
{
// When instructor_mode is enabled, decide if further logic is needed
// In this case, just return the documentation with updated position
eds: documentation.eds,
pos,
};
{eds: documentation.eds, pos};
};

let zipper_of_code = code => {
Expand Down
139 changes: 65 additions & 74 deletions src/haz3lweb/Editors.re
Original file line number Diff line number Diff line change
Expand Up @@ -18,83 +18,29 @@ type exercises = (int, list(Exercise.spec), Exercise.state);
[@deriving (show({with_path: false}), sexp, yojson)]
type t =
| Scratch(int, list(ScratchSlide.state))
| Documentation(string, list((string, DocumentationEnv.state)))
| Documentation(string, list((string, ScratchSlide.state)))
| Tutorial(string, list((string, DocumentationEnv.state)))
| Exercises(int, list(Exercise.spec), Exercise.state);

// [@deriving (show({with_path: false}), sexp, yojson)]
// type cur_state =
// | ScratchState(ScratchSlide.state)
// | DocumentationState(DocumentationEnv.state)
// | ExerciseState(Exercise.state);

let get_editor = (editors: t): Editor.t =>
switch (editors) {
| Scratch(n, slides) =>
assert(n < List.length(slides));
List.nth(slides, n).hidden_tests.tests;
| Documentation(name, slides) =>
// assert(List.mem_assoc(name, slides));
// let slide_state = List.assoc(name, slides);
List.assoc(name, slides).hidden_tests.tests
| Tutorial(name, slides) =>
assert(List.mem_assoc(name, slides));
let slide_state = List.assoc(name, slides);
DocumentationEnv.editor_of_state(slide_state);
// List.assoc(name, slides).eds.your_impl;
| Exercises(_, _, exercise) => Exercise.editor_of_state(exercise)
};

// let put_editor = (ed: DocumentationEnv.state, eds: t): t =>
// switch (eds) {
// | Scratch(n, slides) =>
// assert(n < List.length(slides));
// let convert_to_state = (doc_state: DocumentationEnv.state): state => {
// title: doc_state.eds.title,
// description: doc_state.eds.description,
// // your_impl: doc_state.eds.your_impl, // or however this field maps
// hidden_tests: {
// tests: doc_state.eds.hidden_tests.tests, // or however this field maps
// hints: doc_state.eds.hidden_tests.hints,
// },
// };
// let new_ed = convert_to_state(ed);
// Scratch(n, Util.ListUtil.put_nth(n, new_ed, slides));

// | Documentation(name, slides) =>
// assert(List.mem_assoc(name, slides));

// // NEW //
// let update_slide =
// (hint: string, state: DocumentationEnv.state)
// : (string, DocumentationEnv.state) =>
// if (hint == name) {
// let updatedState =
// switch (ed.pos) {
// | DocumentationEnv.HiddenTests =>
// DocumentationEnv.put_editor(state, ed.eds.hidden_tests.tests) // Update hidden_tests
// | DocumentationEnv.YourImpl =>
// DocumentationEnv.put_editor(state, ed.eds.your_impl) // Update your_impl
// };
// (hint, updatedState);
// } else {
// (hint, state);
// };

// let updatedSlides =
// List.map(
// slide => {
// let (hint, state) = slide;
// update_slide(hint, state);
// },
// slides,
// );

// Documentation(name, updatedSlides);
// // //

// | Exercises(n, specs, exercise) =>
// Exercises(
// n,
// specs,
// Exercise.put_editor(exercise, ed.eds.hidden_tests.tests),
// )
// };
let update_assoc = ((k, v), lst) =>
List.map(((k', v')) => k == k' ? (k, v) : (k', v'), lst);

let put_editor = (editor: Editor.t, eds: t): t =>
switch (eds) {
Expand All @@ -114,6 +60,18 @@ let put_editor = (editor: Editor.t, eds: t): t =>

| Documentation(name, slides) =>
assert(List.mem_assoc(name, slides));
let new_ed = {
title: "",
description: "",
hidden_tests: {
tests: editor,
hints: [],
},
};
Documentation(name, slides |> update_assoc((name, new_ed)));

| Tutorial(name, slides) =>
assert(List.mem_assoc(name, slides));

// Function to update the slide based on `editor`
let update_slide =
Expand Down Expand Up @@ -145,8 +103,7 @@ let put_editor = (editor: Editor.t, eds: t): t =>
slides,
);

Documentation(name, updatedSlides);

Tutorial(name, updatedSlides);
| Exercises(n, specs, exercise) =>
// For Exercises, update the hidden_tests with `editor`
Exercises(n, specs, Exercise.put_editor(exercise, editor))
Expand All @@ -173,13 +130,15 @@ let get_ctx_init = (~settings as _: Settings.t, editors: t): Ctx.t =>
| Scratch(_)
| Exercises(_)
| Documentation(_) => Builtins.ctx_init
| Tutorial(_) => Builtins.ctx_init
};

let get_env_init = (~settings as _: Settings.t, editors: t): Environment.t =>
switch (editors) {
| Scratch(_)
| Exercises(_)
| Documentation(_) => Builtins.env_init
| Tutorial(_) => Builtins.env_init
};

let mk_statics = (~settings: Settings.t, editors: t): CachedStatics.t => {
Expand All @@ -195,6 +154,10 @@ let mk_statics = (~settings: Settings.t, editors: t): CachedStatics.t => {
let key = ScratchSlide.scratch_key(name);
[(key, ScratchSlide.mk_statics(~settings, editor, ctx_init))]
|> CachedStatics.mk;
| Tutorial(name, _) =>
let key = ScratchSlide.scratch_key(name);
[(key, ScratchSlide.mk_statics(~settings, editor, ctx_init))]
|> CachedStatics.mk;
| Exercises(_, _, exercise) =>
Exercise.mk_statics(settings.core, exercise) |> CachedStatics.mk
};
Expand All @@ -210,6 +173,9 @@ let lookup_statics =
| Documentation(name, _) =>
let key = ScratchSlide.scratch_key(name);
CachedStatics.lookup(statics, key);
| Tutorial(name, _) =>
let key = ScratchSlide.scratch_key(name);
CachedStatics.lookup(statics, key);
| Exercises(_, _, exercise) =>
let key = Exercise.key_for_statics(exercise);
CachedStatics.lookup(statics, key);
Expand All @@ -232,12 +198,13 @@ let get_spliced_elabs =
lookup_statics(~settings, ~statics, editors);
let d = Interface.elaborate(~settings=settings.core, info_map, term);
[(key, d)];
| Documentation(name, slides) =>
// let key = DocumentationEnv.scratch_key(name);
// let CachedStatics.{term, info_map, _} =
// lookup_statics(~settings, ~statics, editors);
// let d = Interface.elaborate(~settings=settings.core, info_map, term);
// [(key, d)];
| Documentation(name, _) =>
let key = ScratchSlide.scratch_key(name);
let CachedStatics.{term, info_map, _} =
lookup_statics(~settings, ~statics, editors);
let d = Interface.elaborate(~settings=settings.core, info_map, term);
[(key, d)];
| Tutorial(name, slides) =>
let slideState = List.assoc(name, slides);
DocumentationEnv.spliced_elabs(settings.core, slideState);
| Exercises(_, _, exercise) =>
Expand All @@ -247,7 +214,8 @@ let get_spliced_elabs =
let set_instructor_mode = (editors: t, instructor_mode: bool): t =>
switch (editors) {
| Scratch(n, slides) => Scratch(n, slides)
| Documentation(name, slides) =>
| Documentation(_) => editors
| Tutorial(name, slides) =>
// Assuming you want to pass instructor_mode down to each slide
let updated_slides =
List.map(
Expand All @@ -262,7 +230,7 @@ let set_instructor_mode = (editors: t, instructor_mode: bool): t =>
},
slides,
);
Documentation(name, updated_slides);
Tutorial(name, updated_slides);
| Exercises(n, specs, exercise) =>
Exercises(
n,
Expand All @@ -285,10 +253,17 @@ let reset_nth_slide = (n, slides) => {
// Util.ListUtil.put_nth(n, init_nth, slides);
// };

let reset_named_slide_2 = (name, slides) => {
let (_, init_editors, _) = Init.startup.tutorial;
let data = List.assoc(name, init_editors);
let init_name = DocumentationEnv.unpersist_state(data);
slides |> List.remove_assoc(name) |> List.cons((name, init_name));
};

let reset_named_slide = (name, slides) => {
let (_, init_editors, _) = Init.startup.documentation;
let data = List.assoc(name, init_editors);
let init_name = DocumentationEnv.unpersist_state(data);
let init_name = ScratchSlide.unpersist(data);
slides |> List.remove_assoc(name) |> List.cons((name, init_name));
};

Expand All @@ -302,6 +277,20 @@ let reset_current = (editors: t, ~instructor_mode: bool): t =>
Scratch(n, editorList);

| Documentation(name, slides) =>
let from_tup = ((word: string, status: state)) => (
word,
toEditor(status),
);
let slides = List.map(from_tup, slides);
let slides = reset_named_slide(name, slides);
let to_tup = ((word: string, editor: Editor.t)) => (
word,
fromEditor(editor),
);
let slides = List.map(to_tup, slides);
Documentation(name, slides);

| Tutorial(name, slides) =>
let from_tup = ((word: string, status: DocumentationEnv.state)) => {
// word,
// toEditor(status),
Expand All @@ -324,7 +313,7 @@ let reset_current = (editors: t, ~instructor_mode: bool): t =>

let updatedSlides = List.map(from_tup, slides);

Documentation(name, updatedSlides);
Tutorial(name, updatedSlides);

| Exercises(n, specs, _) =>
Exercises(
Expand All @@ -337,6 +326,7 @@ let reset_current = (editors: t, ~instructor_mode: bool): t =>
let import_current = (editors: t, data: option(string)): t =>
switch (editors) {
| Documentation(_)
| Tutorial(_)
| Exercises(_) => failwith("impossible")
| Scratch(idx, slides) =>
switch (data) {
Expand Down Expand Up @@ -370,4 +360,5 @@ let switch_example_slide = (editors: t, name: string): option(t) =>
when !List.mem_assoc(name, slides) || cur == name =>
None
| Documentation(_, slides) => Some(Documentation(name, slides))
| Tutorial(_, slides) => Some(Tutorial(name, slides))
};
16 changes: 15 additions & 1 deletion src/haz3lweb/Export.re
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type all = {
scratch: string,
exercise: string,
documentation: string,
tutorial: string,
log: string,
};

Expand All @@ -16,6 +17,7 @@ type all_f22 = {
settings: string,
scratch: string,
exercise: string,
tutorial: string,
log: string,
};

Expand All @@ -26,12 +28,22 @@ let mk_all = (~instructor_mode, ~log) => {
let scratch = Store.Scratch.export(~settings=settings_obj.core.evaluation);
let documentation =
Store.Documentation.export(~settings=settings_obj.core.evaluation);
let tutorial =
Store.Tutorial.export(~settings=settings_obj.core.evaluation);
let exercise =
Store.Exercise.export(
~specs=ExerciseSettings.exercises,
~instructor_mode,
);
{settings, explainThisModel, scratch, documentation, exercise, log};
{
settings,
explainThisModel,
scratch,
documentation,
exercise,
tutorial,
log,
};
};

let export_all = (~instructor_mode, ~log) => {
Expand All @@ -47,6 +59,7 @@ let import_all = (data, ~specs) => {
settings: all_f22.settings,
scratch: all_f22.scratch,
documentation: "",
tutorial: all_f22.tutorial,
exercise: all_f22.exercise,
log: all_f22.log,
explainThisModel: "",
Expand All @@ -56,6 +69,7 @@ let import_all = (data, ~specs) => {
Store.ExplainThisModel.import(all.explainThisModel);
let instructor_mode = settings.instructor_mode;
Store.Scratch.import(~settings=settings.core.evaluation, all.scratch);
Store.Tutorial.import(~settings=settings.core.evaluation, all.tutorial);
Store.Exercise.import(all.exercise, ~specs, ~instructor_mode);
Log.import(all.log);
};
Loading

0 comments on commit a6f225c

Please sign in to comment.