From 8f01458375b0bc4234cea42cde3e6bcdc7320f40 Mon Sep 17 00:00:00 2001 From: reevafaisal Date: Thu, 3 Oct 2024 12:59:47 -0400 Subject: [PATCH] integrated new persistent state --- src/haz3lschool/DocumentationEnv.re | 434 ++------------------------- src/haz3lweb/Editors.re | 2 +- src/haz3lweb/Init.ml | 441 +++++++++++++++++++++------- src/haz3lweb/Model.re | 27 +- src/haz3lweb/PersistentData.re | 2 +- src/haz3lweb/ScratchSlide.re | 5 + src/haz3lweb/Store.re | 41 ++- 7 files changed, 411 insertions(+), 541 deletions(-) diff --git a/src/haz3lschool/DocumentationEnv.re b/src/haz3lschool/DocumentationEnv.re index df5ad4e518..1c17ff80a8 100644 --- a/src/haz3lschool/DocumentationEnv.re +++ b/src/haz3lschool/DocumentationEnv.re @@ -26,12 +26,6 @@ module D = (DocEnv: DocEnv) => { [@deriving (show({with_path: false}), sexp, yojson)] type hint = string; - // [@deriving (show({with_path: false}), sexp, yojson)] - // type syntax_test = (hint, SyntaxTest.predicate); - - // [@deriving (show({with_path: false}), sexp, yojson)] - // type syntax_tests = list(syntax_test); - [@deriving (show({with_path: false}), sexp, yojson)] type your_tests('code) = { tests: 'code, @@ -55,18 +49,8 @@ module D = (DocEnv: DocEnv) => { type p('code) = { title: string, description: string, - // version: int, - // module_name: string, - // prompt: - // [@printer (fmt, _) => Format.pp_print_string(fmt, "prompt")] [@opaque] ExerciseEnv.node, - // point_distribution, - // prelude: 'code, - // correct_impl: 'code, - // your_tests: your_tests('code), your_impl: 'code, - // hidden_bugs: list(wrong_impl('code)), hidden_tests: hidden_tests('code), - // syntax_tests, }; [@deriving (show({with_path: false}), sexp, yojson)] @@ -86,12 +70,7 @@ module D = (DocEnv: DocEnv) => { [@deriving (show({with_path: false}), sexp, yojson)] type pos = - // | Prelude - // | CorrectImpl - // | YourTestsValidation - // | YourTestsTesting | YourImpl - // | HiddenBugs(int) | HiddenTests; [@deriving (show({with_path: false}), sexp, yojson)] @@ -104,31 +83,11 @@ module D = (DocEnv: DocEnv) => { { title: p.title, description: p.description, - // version: p.version, - // module_name: p.module_name, - // prompt: p.prompt, - // point_distribution: p.point_distribution, - // prelude: f(p.prelude), - // correct_impl: f(p.correct_impl), - // your_tests: { - // tests: f(p.your_tests.tests), - // required: p.your_tests.required, - // provided: p.your_tests.provided, - // }, your_impl: f(p.your_impl), - // hidden_bugs: - // p.hidden_bugs - // |> List.map(wrong_impl => { - // { - // impl: PersistentZipper.persist(wrong_impl.impl), - // hint: wrong_impl.hint, - // } - // }), hidden_tests: { tests: PersistentZipper.persist(p.hidden_tests.tests), hints: p.hidden_tests.hints, }, - // syntax_tests: p.syntax_tests, }; }; @@ -144,44 +103,30 @@ module D = (DocEnv: DocEnv) => { let key_of_state = ({eds, _}) => key_of(eds); [@deriving (show({with_path: false}), sexp, yojson)] - type persistent_state = (pos, list((pos, PersistentZipper.t))); - // type persistent_state = { - // title : string, - // description : string, - // pos : pos, - // tutorial : list((pos, PersistentZipper.t)), - // }; + type persistent_state = { + focus: pos, + title: string, + description: string, + editors: list((pos, PersistentZipper.t)), + }; let editor_of_state: state => Editor.t = ({pos, eds, _}) => switch (pos) { - // | Prelude => eds.prelude - // | CorrectImpl => eds.correct_impl - // | YourTestsValidation => eds.your_tests.tests - // | YourTestsTesting => eds.your_tests.tests - | YourImpl => - // print_endline("grabs YourImpl"); - eds.your_impl - // | HiddenBugs(i) => List.nth(eds.hidden_bugs, i).impl - | HiddenTests => - // print_endline("grabs HiddenTests"); - eds.hidden_tests.tests + | YourImpl => eds.your_impl + | HiddenTests => eds.hidden_tests.tests }; let put_editor = ({pos, eds} as state: state, editor: Editor.t) => switch (pos) { - | YourImpl => - // print_endline("YourImpl"); - { + | YourImpl => { ...state, eds: { ...eds, your_impl: editor, }, } - | HiddenTests => - // print_endline("HiddenTests"); - { + | HiddenTests => { ...state, eds: { ...eds, @@ -194,20 +139,10 @@ module D = (DocEnv: DocEnv) => { }; let editors = ({eds, _}: state) => [ - // eds.prelude, - // eds.correct_impl, - // eds.your_tests.tests, - // eds.your_tests.tests, eds.your_impl, eds.hidden_tests.tests, ]; - // @ List.map(wrong_impl => wrong_impl.impl, eds.hidden_bugs) - // @ [eds.hidden_tests.tests]; - // let editor_positions = - // [YourImpl] - // // @ List.mapi((i, _) => HiddenBugs(i), eds.hidden_bugs) - // @ [HiddenTests]; let editor_positions = [YourImpl, HiddenTests]; let positioned_editors = state => @@ -215,26 +150,13 @@ module D = (DocEnv: DocEnv) => { let idx_of_pos = (pos, p: p('code)) => switch (pos) { - // | Prelude => 0 - // | CorrectImpl => 1 - // | YourTestsTesting => 2 - // | YourTestsValidation => 3 | YourImpl => 0 - // | HiddenBugs(i) => - // if (i < List.length(p.hidden_bugs)) { - // 5 + i; - // } else { - // failwith("invalid hidden bug index"); - // } + | HiddenTests => 0 + List.length(p.hidden_tests.tests) // NEED TO FIGURE OUT HOW TO ACTUALLY MAKE THIS WORK }; let pos_of_idx = (p: p('code), idx: int) => switch (idx) { - // | 0 => Prelude - // | 1 => CorrectImpl - // | 2 => YourTestsTesting - // | 3 => YourTestsValidation | 0 => YourImpl | _ => if (idx < 0) { @@ -306,129 +228,29 @@ module D = (DocEnv: DocEnv) => { }; let transition: transitionary_spec => spec = - ( - { - title, - description, - // version, - // module_name, - // prompt, - // point_distribution, - // prelude, - // correct_impl, - // your_tests, - your_impl, - // hidden_bugs, - hidden_tests, - // syntax_tests, - }, - ) => { - // let prelude = zipper_of_code(prelude); - // let correct_impl = zipper_of_code(correct_impl); - // let your_tests = { - // let tests = zipper_of_code(your_tests.tests); - // {tests, required: your_tests.required, provided: your_tests.provided}; - // }; + ({title, description, your_impl, hidden_tests}) => { let your_impl = zipper_of_code(your_impl); - // let hidden_bugs = - // List.fold_left( - // (acc, {impl, hint}) => { - // let impl = zipper_of_code(impl); - // acc @ [{impl, hint}]; - // }, - // [], - // hidden_bugs, - // ); let hidden_tests = { let {tests, hints} = hidden_tests; let tests = zipper_of_code(tests); {tests, hints}; }; - { - title, - description, - // version, - // module_name, - // prompt, - // point_distribution, - // prelude, - // correct_impl, - // your_tests, - your_impl, - // hidden_bugs, - hidden_tests, - // syntax_tests, - }; + {title, description, your_impl, hidden_tests}; }; - // let unpersist = (zipper: persistent_state) => { - // let zipper = PersistentZipper.unpersist(zipper.hidden_tests.tests); - // Editor.init(zipper, ~read_only=false); - // }; - let editor_of_serialization = zipper => Editor.init(zipper); let eds_of_spec: spec => eds = - ( - { - title, - description, - // version, - // module_name, - // prompt, - // point_distribution, - // prelude, - // correct_impl, - // your_tests, - your_impl, - // hidden_bugs, - hidden_tests, - // syntax_tests, - }, - ) => { - // let prelude = editor_of_serialization(prelude); - // let correct_impl = editor_of_serialization(correct_impl); - // let your_tests = { - // let tests = editor_of_serialization(your_tests.tests); - // {tests, required: your_tests.required, provided: your_tests.provided}; - // }; + ({title, description, your_impl, hidden_tests}) => { let your_impl = editor_of_serialization(your_impl); - // let hidden_bugs = - // hidden_bugs - // |> List.map(({impl, hint}) => { - // let impl = editor_of_serialization(impl); - // {impl, hint}; - // }); + let hidden_tests = { let {tests, hints} = hidden_tests; let tests = editor_of_serialization(tests); {tests, hints}; }; - { - title, - description, - // version, - // module_name, - // prompt, - // point_distribution, - // prelude, - // correct_impl, - // your_tests, - your_impl, - // hidden_bugs, - hidden_tests, - // syntax_tests, - }; + {title, description, your_impl, hidden_tests}; }; - // FIX ME - - // let set_instructor_mode = ({eds, _} as state: state, new_mode: bool) => { - // ...state, - // eds: { - // ...eds, - // hint: Editor.set_read_only(eds.title, !new_mode), - // }, - // }; let set_instructor_mode = ({eds, _} as state: state, new_mode: bool) => { let updated_hidden_tests = { ...eds.hidden_tests, @@ -446,92 +268,62 @@ module D = (DocEnv: DocEnv) => { let visible_in = (pos, ~instructor_mode) => { switch (pos) { - // | Prelude => instructor_mode - // | CorrectImpl => instructor_mode - // | YourTestsValidation => true - // | YourTestsTesting => false | YourImpl => true - // | HiddenBugs(_) => instructor_mode | HiddenTests => instructor_mode }; }; - // let state_of_spec = (spec, ~instructor_mode: bool): state => { - // let eds = eds_of_spec(spec); - // set_instructor_mode({pos: HiddenTests, eds}, instructor_mode); - // }; - let state_of_spec = (spec, ~instructor_mode: bool): state => { let eds = eds_of_spec(spec); set_instructor_mode({pos: HiddenTests, eds}, instructor_mode); }; - let persistent_state_of_state = - ({pos, _} as state: state, ~instructor_mode: bool) => { + let persistent_state_of_state = (state: state, ~instructor_mode: bool) => { let zippers = positioned_editors(state) |> List.filter(((pos, _)) => visible_in(pos, ~instructor_mode)) |> List.map(((pos, editor)) => { (pos, PersistentZipper.persist(Editor.(editor.state.zipper))) }); - (pos, zippers); + { + focus: state.pos, + editors: zippers, + title: state.eds.title, + description: state.eds.description, + }; }; let unpersist_state = ( - (pos, positioned_zippers): persistent_state, + {focus, editors, _}: persistent_state, ~spec: spec, ~instructor_mode: bool, ) + // ~editing_title: bool, : state => { let lookup = (pos, default) => if (visible_in(pos, ~instructor_mode)) { - let persisted_zipper = List.assoc(pos, positioned_zippers); + let persisted_zipper = List.assoc(pos, editors); let zipper = PersistentZipper.unpersist(persisted_zipper); Editor.init(zipper); } else { editor_of_serialization(default); }; - // let prelude = lookup(Prelude, spec.prelude); - // let correct_impl = lookup(CorrectImpl, spec.correct_impl); - // let your_tests_tests = lookup(YourTestsValidation, spec.your_tests.tests); let your_impl = lookup(YourImpl, spec.your_impl); - // let (_, hidden_bugs) = - // List.fold_left( - // ((i, hidden_bugs: list(wrong_impl(Editor.t))), {impl, hint}) => { - // let impl = lookup(HiddenBugs(i), impl); - // (i + 1, hidden_bugs @ [{impl, hint}]); - // }, - // (0, []), - // spec.hidden_bugs, - // ); let hidden_tests_tests = lookup(HiddenTests, spec.hidden_tests.tests); set_instructor_mode( { - pos, + pos: focus, eds: { title: spec.title, description: spec.description, - // version: spec.version, - // module_name: spec.module_name, - // prompt: spec.prompt, - // point_distribution: spec.point_distribution, - // prelude, - // correct_impl, - // your_tests: { - // tests: your_tests_tests, - // required: spec.your_tests.required, - // provided: spec.your_tests.provided, - // }, your_impl, - // hidden_bugs, hidden_tests: { tests: hidden_tests_tests, hints: spec.hidden_tests.hints, }, }, - // syntax_tests: spec.syntax_tests, }, instructor_mode, ); @@ -551,12 +343,8 @@ module D = (DocEnv: DocEnv) => { }; type stitched('a) = { - // test_validation: 'a, // prelude + correct_impl + your_tests user_impl: 'a, // prelude + your_impl - // user_tests: 'a, // prelude + your_impl + your_tests - // prelude: 'a, // prelude instructor: 'a, // prelude + correct_impl + hidden_tests.tests // TODO only needs to run in instructor mode - // hidden_bugs: list('a), // prelude + hidden_bugs[i].impl + your_tests, hidden_tests: 'a, }; @@ -588,39 +376,7 @@ module D = (DocEnv: DocEnv) => { let stitch1 = (ed1: Editor.t) => // EditorUtil.append_exp( EditorUtil.append_exp(term_of(ed1)); - // term_of(ed3), - // ); - - // let stitch_term = ({eds, _}: state): stitched(TermItem.t) => { - // let instructor = eds.hidden_tests.tests |> term_of; - // let user_impl_term = { - // // let your_impl_term = - // eds.your_impl |> term_of |> wrap_filter(FilterAction.Step); // let prelude_term = - // // EditorUtil.append_exp(your_impl_term); - // }; - // // let test_validation_term = - // // stitch3(eds.prelude, eds.correct_impl, eds.your_tests.tests); - // // let user_tests_term = - // // EditorUtil.append_exp(user_impl_term, term_of(eds.your_tests.tests)); - // let hidden_tests_term = - // EditorUtil.append_exp(user_impl_term, term_of(eds.hidden_tests.tests)); - // { - // // test_validation: wrap(test_validation_term, eds.your_tests.tests), - // user_impl: wrap(user_impl_term, eds.your_impl), - // // user_tests: wrap(user_tests_term, eds.your_tests.tests), - // // instructor works here as long as you don't shadow anything in the prelude - // // prelude: wrap(instructor, eds.prelude), - // instructor: wrap(instructor, eds.hidden_tests.tests), - // // hidden_bugs: - // // List.map( - // // (t): TermItem.t => - // // // term_of(t.impl), - // // wrap(stitch3(eds.prelude, t.impl, eds.your_tests.tests), t.impl), - // // eds.hidden_bugs, - // // ), - // hidden_tests: wrap(hidden_tests_term, eds.hidden_tests.tests), - // }; - // }; + let stitch_term = ({eds, _}: state): stitched(TermItem.t) => { let instructor = eds.hidden_tests.tests |> term_of; let user_impl_term = { @@ -658,12 +414,8 @@ module D = (DocEnv: DocEnv) => { }; let instructor = mk(t.instructor); { - // test_validation: mk(t.test_validation), user_impl: mk(t.user_impl), - // user_tests: mk(t.user_tests), - // prelude: instructor, // works as long as you don't shadow anything in the prelude instructor, - // hidden_bugs: List.map(mk, t.hidden_bugs), hidden_tests: mk(t.hidden_tests), }; }; @@ -673,12 +425,7 @@ module D = (DocEnv: DocEnv) => { let statics_of_stiched = (state: state, s: stitched(StaticsItem.t)): StaticsItem.t => switch (state.pos) { - // | Prelude => s.prelude - // | CorrectImpl => s.instructor - // | YourTestsValidation => s.test_validation - // | YourTestsTesting => s.user_tests | YourImpl => s.user_impl - // | HiddenBugs(idx) => List.nth(s.hidden_bugs, idx) | HiddenTests => s.hidden_tests }; @@ -688,53 +435,28 @@ module D = (DocEnv: DocEnv) => { |> stitch_static(settings) |> statics_of_stiched(documentation); - // let prelude_key = "prelude"; - // let test_validation_key = "test_validation"; let user_impl_key = "user_impl"; - // let user_tests_key = "user_tests"; let instructor_key = "instructor"; - // let hidden_bugs_key = n => "hidden_bugs_" ++ string_of_int(n); let hidden_tests_key = "hidden_tests"; let key_for_statics = (state: state): string => switch (state.pos) { - // | Prelude => prelude_key - // | CorrectImpl => instructor_key - // | YourTestsValidation => test_validation_key - // | YourTestsTesting => user_tests_key | YourImpl => user_impl_key - // | HiddenBugs(idx) => hidden_bugs_key(idx) | HiddenTests => hidden_tests_key }; let spliced_elabs = (settings: CoreSettings.t, state: state) : list((ModelResults.key, DHExp.t)) => { - let { - // test_validation, - user_impl, - // user_tests, - // prelude: _, - instructor, - // hidden_bugs, - hidden_tests, - } = + let {user_impl, instructor, hidden_tests} = stitch_static(settings, stitch_term(state)); let elab = (s: CachedStatics.statics) => Interface.elaborate(~settings, s.info_map, s.term); [ - // (test_validation_key, elab(test_validation)), (user_impl_key, elab(user_impl)), - // (user_tests_key, elab(user_tests)), (instructor_key, elab(instructor)), (hidden_tests_key, elab(hidden_tests)), ]; - // @ ( - // hidden_bugs - // |> List.mapi((n, hidden_bug: StaticsItem.t) => - // (hidden_bugs_key(n), elab(hidden_bug)) - // ) - // ); }; let mk_statics = @@ -742,17 +464,10 @@ module D = (DocEnv: DocEnv) => { : list((ModelResults.key, StaticsItem.t)) => { let stitched = stitch_static(settings, stitch_term(state)); [ - // (prelude_key, stitched.prelude), - // (test_validation_key, stitched.test_validation), (user_impl_key, stitched.user_impl), - // (user_tests_key, stitched.user_tests), (instructor_key, stitched.instructor), (hidden_tests_key, stitched.hidden_tests), ]; - // @ List.mapi( - // (n, hidden_bug: StaticsItem.t) => (hidden_bugs_key(n), hidden_bug), - // stitched.hidden_bugs, - // ); }; module DynamicsItem = { @@ -784,15 +499,7 @@ module D = (DocEnv: DocEnv) => { results: option(ModelResults.t), ) : stitched(DynamicsItem.t) => { - let { - // test_validation, - user_impl, - // user_tests, - // prelude, - instructor, - // hidden_bugs, - hidden_tests, - } = + let {user_impl, instructor, hidden_tests} = stitch_static(settings, stitch_term(state)); let result_of = key => switch (results) { @@ -802,63 +509,25 @@ module D = (DocEnv: DocEnv) => { |> Option.value(~default=ModelResult.NoElab) }; - // let test_validation = - // DynamicsItem.{ - // term: test_validation.term, - // info_map: test_validation.info_map, - // result: result_of(test_validation_key), - // }; - let user_impl = DynamicsItem.{ term: user_impl.term, info_map: user_impl.info_map, result: result_of(user_impl_key), }; - - // let user_tests = - // DynamicsItem.{ - // term: user_tests.term, - // info_map: user_tests.info_map, - // result: result_of(user_tests_key), - // }; - // let prelude = - // DynamicsItem.{ - // term: prelude.term, - // info_map: prelude.info_map, - // result: NoElab, - // }; let instructor = DynamicsItem.{ term: instructor.term, info_map: instructor.info_map, result: result_of(instructor_key), }; - // let hidden_bugs = - // List.mapi( - // (n, statics_item: StaticsItem.t) => - // DynamicsItem.{ - // term: statics_item.term, - // info_map: statics_item.info_map, - // result: result_of(hidden_bugs_key(n)), - // }, - // hidden_bugs, - // ); let hidden_tests = DynamicsItem.{ term: hidden_tests.term, info_map: hidden_tests.info_map, result: result_of(hidden_tests_key), }; - { - // test_validation, - user_impl, - // user_tests, - instructor, - // prelude, - // hidden_bugs, - hidden_tests, - }; + {user_impl, instructor, hidden_tests}; }; let stitch_dynamic = @@ -873,25 +542,14 @@ module D = (DocEnv: DocEnv) => { } else if (settings.statics) { let t = stitch_static(settings, stitch_term(state)); { - // test_validation: DynamicsItem.statics_only(t.test_validation), user_impl: DynamicsItem.statics_only(t.user_impl), - // user_tests: DynamicsItem.statics_only(t.user_tests), instructor: DynamicsItem.statics_only(t.instructor), - // prelude: DynamicsItem.statics_only(t.prelude), - // hidden_bugs: List.map(DynamicsItem.statics_only, t.hidden_bugs), hidden_tests: DynamicsItem.statics_only(t.hidden_tests), }; } else { { - // test_validation: DynamicsItem.empty, user_impl: DynamicsItem.empty, - // user_tests: DynamicsItem.empty, instructor: DynamicsItem.empty, - // prelude: DynamicsItem.empty, - // hidden_bugs: - // List.init(List.length(state.eds.hidden_bugs), _ => - // DynamicsItem.empty - // ), hidden_tests: DynamicsItem.empty, }; }; @@ -943,46 +601,16 @@ module D = (DocEnv: DocEnv) => { }; let blank_spec = (~title, ~description) => { - // ~module_name, - // ~point_distribution, - // ~required_tests, - // ~provided_tests, - // ~num_wrong_impls, - - // let prelude = Zipper.next_blank(); - // let correct_impl = Zipper.next_blank(); - // let your_tests_tests = Zipper.next_blank(); let your_impl_m = Zipper.next_blank(); - // let hidden_bugs = - // List.init( - // num_wrong_impls, - // i => { - // let zipper = Zipper.next_blank(); - // {impl: zipper, hint: "TODO: hint " ++ string_of_int(i)}; - // }, - // ); let hidden_tests_tests = Zipper.next_blank(); { title, description, - // version: 1, - // module_name, - // prompt: ExerciseEnv.default, - // point_distribution, - // prelude, - // correct_impl, - // your_tests: { - // tests: your_tests_tests, - // required: required_tests, - // provided: provided_tests, - // }, your_impl: your_impl_m, - // hidden_bugs, hidden_tests: { tests: hidden_tests_tests, hints: [], }, - // syntax_tests: [], }; }; diff --git a/src/haz3lweb/Editors.re b/src/haz3lweb/Editors.re index 19c4b7b3f4..508e35535a 100644 --- a/src/haz3lweb/Editors.re +++ b/src/haz3lweb/Editors.re @@ -288,7 +288,7 @@ let reset_nth_slide = (n, slides) => { let reset_named_slide = (name, slides) => { let (_, init_editors, _) = Init.startup.documentation; let data = List.assoc(name, init_editors); - let init_name = ScratchSlide.unpersist(data); + let init_name = DocumentationEnv.unpersist_state(data); slides |> List.remove_assoc(name) |> List.cons((name, init_name)); }; diff --git a/src/haz3lweb/Init.ml b/src/haz3lweb/Init.ml index 97cff0304c..928409f20e 100644 --- a/src/haz3lweb/Init.ml +++ b/src/haz3lweb/Init.ml @@ -214,12 +214,23 @@ let startup : PersistentData.t = [ ( "Casting", { - title = ""; + focus = YourImpl; + title = "Casting"; description = ""; - hidden_tests = - { - tests = + editors = + [ + ( YourImpl, + { + zipper = + "((selection((focus \ + Left)(content())))(backpack())(relatives((siblings(()((Grout((id \ + 0)(shape Convex))))))(ancestors())))(caret Outer))"; + backup_text = " "; + } ); + ( HiddenTests, { + (* tests = *) + (* { *) zipper = "((selection((focus Left)(content())(mode \ Normal)))(backpack())(relatives((siblings(()((Secondary((id \ @@ -7129,18 +7140,35 @@ let startup : PersistentData.t = f(1, 2);\n\ \ \n\ \ "; - }; - hints = []; - }; - } ); + } + (* hints = []; *) + (* Closes Hidden Tests *) ) + (* Closes HiddenTests editor *); + ] + (* Closes Editors list *); + } + (* Closes P state record *) ); + (* } ); *) ( "ADT Statics", { - title = ""; + focus = DocumentationEnv.YourImpl; + title = "ADT Statics"; description = ""; - hidden_tests = - { - tests = + editors = + [ + (* hidden_tests = *) + ( YourImpl, + { + zipper = + "((selection((focus \ + Left)(content())))(backpack())(relatives((siblings(()((Grout((id \ + 0)(shape Convex))))))(ancestors())))(caret Outer))"; + backup_text = " "; + } ); + ( HiddenTests, { + (* tests = *) + (* { *) zipper = "((selection((focus Left)(content())(mode \ Normal)))(backpack())(relatives((siblings(()((Secondary((id \ @@ -9540,18 +9568,34 @@ let startup : PersistentData.t = let Yo(1): +Yo = Yo in #err: type incons#\n\ let Yo(1): +Yo(Bool) = Yo(true) in #err: type incons#\n\ \"Thats all, folks\"\n"; - }; - hints = []; - }; + } + (* hints = []; *) + (* }; *) ) + (* closes cur hidden tests tuple *); + ] + (* closes editor list*); } ); ( "Basic Reference", { - title = ""; + focus = YourImpl; + title = "Basic Reference"; description = ""; - hidden_tests = - { - tests = + editors = + [ + ( YourImpl, + (* Editor for user implementation *) + { + zipper = + "((selection((focus \ + Left)(content())))(backpack())(relatives((siblings(()((Grout((id \ + 0)(shape Convex))))))(ancestors())))(caret Outer))"; + backup_text = " "; + } ); + ( HiddenTests, + (* hidden_tests = *) { + (* tests = *) + (* { *) zipper = "((selection((focus Left)(content())(mode \ Normal)))(backpack())(relatives((siblings(()((Secondary((id \ @@ -12314,17 +12358,30 @@ let startup : PersistentData.t = test 3 + 3 == 6 end;\n\ test 2 + 2 == 5 end;\n\n\ 2 + 2"; - }; - hints = []; - }; + (* }; + hints = []; *) + } ); + ]; } ); ( "Types & static errors", { + focus = YourImpl; title = ""; description = ""; - hidden_tests = - { - tests = + editors = + [ + ( YourImpl, + (* Editor for user implementation *) + { + zipper = ""; + (* Serialized zipper data *) + backup_text = " "; + } ); + ( HiddenTests, + (* { *) + (* hidden_tests = + { *) + (* tests = *) { zipper = "((selection((focus Left)(content())(mode \ @@ -14371,18 +14428,33 @@ let startup : PersistentData.t = let _: [Int] = 1.0::[2] in #err#\n\ let _: [Int] = 1::[2.0] in #err#\n\ \"BYE\""; - }; - hints = []; - }; + } + (* hints = []; *) + (* }; *) ); + ]; } ); + (* } ); *) ( "ADT Dynamics", { - title = ""; + focus = YourImpl; + title = "ADT Dynamics"; description = ""; - hidden_tests = - { - tests = + editors = + [ + (* hidden_tests = *) + ( YourImpl, + (* Editor for user implementation *) { + zipper = + "((selection((focus \ + Left)(content())))(backpack())(relatives((siblings(()((Grout((id \ + 0)(shape Convex))))))(ancestors())))(caret Outer))"; + backup_text = ""; + } ); + ( HiddenTests, + { + (* tests = + { *) zipper = "((selection((focus Left)(content())(mode \ Normal)))(backpack())(relatives((siblings(()((Secondary((id \ @@ -16397,17 +16469,31 @@ let startup : PersistentData.t = eval(Ap(Lam(\"yo\", Var(\"yo\")), Lam(\"bro\", \ Var(\"bro\")))),\n\ Ok(Lam(\"bro\", Var(\"bro\")))) end"; - }; - hints = []; - }; + } + (* hints = []; + }; *) ); + ]; } ); + (* } ); *) ( "Polymorphism", { - title = ""; + focus = YourImpl; + title = "Polymorphism"; description = ""; - hidden_tests = - { - tests = + editors = + [ + ( YourImpl, + { + zipper = + "((selection((focus \ + Left)(content())))(backpack())(relatives((siblings(()((Grout((id \ + 0)(shape Convex))))))(ancestors())))(caret Outer))"; + backup_text = ""; + } ); + ( HiddenTests, + (* hidden_tests = *) + (* { + tests = *) { zipper = "((selection((focus Left)(content())(mode \ @@ -18200,35 +18286,61 @@ let startup : PersistentData.t = let ex5 = list_of_mylist(x) in # [1, 2, 3] #\n\n\n\ # All output from examples: #\n\ (ex1, ex2, ex3, ex4, ex5)"; - }; - hints = []; - }; + } + (* hints = []; + }; *) ); + ]; } ); ( "Programming Expressively", { - title = ""; + focus = YourImpl; + title = "Programming Expressively"; description = ""; - hidden_tests = - { - tests = + editors = + [ + ( YourImpl, { + zipper = + "((selection((focus \ + Left)(content())))(backpack())(relatives((siblings(()((Grout((id \ + 0)(shape Convex))))))(ancestors())))(caret Outer))"; + backup_text = " "; + } ); + ( HiddenTests, + (* hidden_tests = *) + { + (* tests = + { *) zipper = "((selection((focus Left)(content())(mode \ Normal)))(backpack())(relatives((siblings(()((Grout((id \ 73cb2f1d-94b4-42eb-9d77-a832748556b0)(shape \ Convex))))))(ancestors())))(caret Outer))"; backup_text = " "; - }; - hints = []; - }; + } + (* hints = []; + }; *) ); + ]; } ); ( "Composing Arithmetic Expressions", { - title = ""; + focus = YourImpl; + title = "Composing Arithmetic Expressions"; description = ""; - hidden_tests = - { - tests = + editors = + [ + ( YourImpl, + { + zipper = + "((selection((focus \ + Left)(content())))(backpack())(relatives((siblings(()((Grout((id \ + 0)(shape Convex))))))(ancestors())))(caret Outer))"; + backup_text = " "; + } ); + ( HiddenTests, + (* hidden_tests = *) + (* { + tests = *) { zipper = "((selection((focus Left)(content())(mode \ @@ -18236,17 +18348,30 @@ let startup : PersistentData.t = 41444a61-1cf6-408b-82c6-464f3ca6750e)(shape \ Convex))))))(ancestors())))(caret Outer))"; backup_text = " "; - }; - hints = []; - }; + } + (* hints = []; + }; *) ); + ]; } ); ( "Computing Equationally", { - title = ""; + focus = YourImpl; + title = "Computing Equationally"; description = ""; - hidden_tests = - { - tests = + editors = + [ + ( YourImpl, + { + zipper = + "((selection((focus \ + Left)(content())))(backpack())(relatives((siblings(()((Grout((id \ + 0)(shape Convex))))))(ancestors())))(caret Outer))"; + backup_text = " "; + } ); + ( HiddenTests, + (* hidden_tests = *) + (* { + tests = *) { zipper = "((selection((focus Left)(content())(mode \ @@ -18254,17 +18379,30 @@ let startup : PersistentData.t = c7e3b9bd-efaa-41f2-800d-9986a6e814d6)(shape \ Convex))))))(ancestors())))(caret Outer))"; backup_text = " "; - }; - hints = []; - }; + } + (* hints = []; + }; *) ); + ]; } ); ( "Variables", { - title = ""; + focus = YourImpl; + title = "Variables"; description = ""; - hidden_tests = - { - tests = + editors = + [ + ( YourImpl, + { + zipper = + "((selection((focus \ + Left)(content())))(backpack())(relatives((siblings(()((Grout((id \ + 0)(shape Convex))))))(ancestors())))(caret Outer))"; + backup_text = " "; + } ); + ( HiddenTests, + (* hidden_tests = *) + (* { + tests = *) { zipper = "((selection((focus Left)(content())(mode \ @@ -18272,17 +18410,30 @@ let startup : PersistentData.t = 92e68905-30cc-415b-b920-6323180c56d1)(shape \ Convex))))))(ancestors())))(caret Outer))"; backup_text = " "; - }; - hints = []; - }; + } + (* hints = []; + }; *) ); + ]; } ); ( "Compositionality", { - title = ""; + focus = YourImpl; + title = "Compositionality"; description = ""; - hidden_tests = - { - tests = + editors = + [ + ( YourImpl, + { + zipper = + "((selection((focus \ + Left)(content())))(backpack())(relatives((siblings(()((Grout((id \ + 0)(shape Convex))))))(ancestors())))(caret Outer))"; + backup_text = " "; + } ); + ( HiddenTests, + (* hidden_tests = *) + (* { + tests = *) { zipper = "((selection((focus Left)(content())(mode \ @@ -18290,17 +18441,30 @@ let startup : PersistentData.t = 661cbe22-ffdc-4fa3-b227-f7b56a1c8ed6)(shape \ Convex))))))(ancestors())))(caret Outer))"; backup_text = " "; - }; - hints = []; - }; + } + (* hints = []; + }; *) ); + ]; } ); ( "Scope", { - title = ""; + focus = YourImpl; + title = "Scope"; description = ""; - hidden_tests = - { - tests = + editors = + [ + ( YourImpl, + { + zipper = + "((selection((focus \ + Left)(content())))(backpack())(relatives((siblings(()((Grout((id \ + 0)(shape Convex))))))(ancestors())))(caret Outer))"; + backup_text = " "; + } ); + ( HiddenTests, + (* hidden_tests = *) + (* { + tests = *) { zipper = "((selection((focus Left)(content())(mode \ @@ -18308,17 +18472,30 @@ let startup : PersistentData.t = f213697c-e203-41c4-8888-fc12e3ac46bf)(shape \ Convex))))))(ancestors())))(caret Outer))"; backup_text = " "; - }; - hints = []; - }; + } + (* hints = []; + }; *) ); + ]; } ); ( "Shadowing", { - title = ""; + focus = YourImpl; + title = "Shadowing"; description = ""; - hidden_tests = - { - tests = + editors = + [ + ( YourImpl, + { + zipper = + "((selection((focus \ + Left)(content())))(backpack())(relatives((siblings(()((Grout((id \ + 0)(shape Convex))))))(ancestors())))(caret Outer))"; + backup_text = " "; + } ); + ( HiddenTests, + (* hidden_tests = *) + (* { + tests = *) { zipper = "((selection((focus Left)(content())(mode \ @@ -18326,17 +18503,30 @@ let startup : PersistentData.t = 3d8e1707-1e20-4160-946e-73cdb9e98ee1)(shape \ Convex))))))(ancestors())))(caret Outer))"; backup_text = " "; - }; - hints = []; - }; + } + (* hints = []; + }; *) ); + ]; } ); ( "Booleans and Types", { - title = ""; + focus = YourImpl; + title = "Booleans and Types"; description = ""; - hidden_tests = - { - tests = + editors = + [ + ( YourImpl, + { + zipper = + "((selection((focus \ + Left)(content())))(backpack())(relatives((siblings(()((Grout((id \ + 0)(shape Convex))))))(ancestors())))(caret Outer))"; + backup_text = " "; + } ); + ( HiddenTests, + (* hidden_tests = *) + (* { + tests = *) { zipper = "((selection((focus Left)(content())(mode \ @@ -18344,17 +18534,30 @@ let startup : PersistentData.t = f49430b2-1265-4e87-a6d6-795eb57c37f8)(shape \ Convex))))))(ancestors())))(caret Outer))"; backup_text = " "; - }; - hints = []; - }; + } + (* hints = []; + }; *) ); + ]; } ); ( "Conditional Expressions", { - title = ""; + focus = YourImpl; + title = "Conditional Expressions"; description = ""; - hidden_tests = - { - tests = + editors = + [ + ( YourImpl, + { + zipper = + "((selection((focus \ + Left)(content())))(backpack())(relatives((siblings(()((Grout((id \ + 0)(shape Convex))))))(ancestors())))(caret Outer))"; + backup_text = " "; + } ); + ( HiddenTests, + (* hidden_tests = *) + (* { + tests = *) { zipper = "((selection((focus Left)(content())(mode \ @@ -18362,17 +18565,30 @@ let startup : PersistentData.t = e2b7d6b9-5b95-4fad-9278-60097f30375f)(shape \ Convex))))))(ancestors())))(caret Outer))"; backup_text = " "; - }; - hints = []; - }; + } + (* hints = []; *) + (* }; *) ); + ]; } ); ( "Functions", { - title = ""; + focus = YourImpl; + title = "Functions"; description = ""; - hidden_tests = - { - tests = + editors = + [ + ( YourImpl, + { + zipper = + "((selection((focus \ + Left)(content())))(backpack())(relatives((siblings(()((Grout((id \ + 0)(shape Convex))))))(ancestors())))(caret Outer))"; + backup_text = " "; + } ); + ( HiddenTests, + (* hidden_tests = *) + (* { + tests = *) { zipper = "((selection((focus Left)(content())(mode \ @@ -18380,9 +18596,10 @@ let startup : PersistentData.t = b60e7d0e-e290-4b23-b03c-7fe121fb5dcd)(shape \ Convex))))))(ancestors())))(caret Outer))"; backup_text = " "; - }; - hints = []; - }; + } + (* hints = []; + }; *) ); + ]; } ); ], [ diff --git a/src/haz3lweb/Model.re b/src/haz3lweb/Model.re index 0aa84cf8f3..c22660e92e 100644 --- a/src/haz3lweb/Model.re +++ b/src/haz3lweb/Model.re @@ -74,7 +74,6 @@ let load_editors = (Scratch(idx, slides), results); | Documentation => let (name, slides, results) = Store.Documentation.load(~settings); - let fromEditor = (editor: Editor.t): DocumentationEnv.state => { pos: DocumentationEnv.YourImpl, eds: { @@ -93,13 +92,6 @@ let load_editors = ); print_endline("inside load editors"); let slides = List.map(to_tup, slides); - // let (n, specs, exercise) = - // Store.Exercise.load( - // ~specs=ExerciseSettings.exercises, - // ~instructor_mode, - // ); - // (Exercises(n, specs, exercise), ModelResults.empty); - (Documentation(name, slides), results); | Exercises => let (n, specs, exercise) = @@ -134,6 +126,24 @@ let save_editors = Store.Exercise.save((n, specs, exercise), ~instructor_mode) }; +// let save_editors_2 = (editors: Editors.t, results: ModelResults.t): unit => +// switch (editors) { +// | Scratch(_) => () +// | Documentation(name, slides) => +// let toEditor = (state: DocumentationEnv.state): Editor.t => { +// switch (state) { +// | s => s.eds.your_impl +// }; +// }; +// let from_tup = ((word: string, status: DocumentationEnv.state)) => ( +// word, +// toEditor(status), +// ); +// let slides = List.map(from_tup, slides); +// Store.Documentation.save((name, slides, results)); +// | Exercises(_) => () +// }; + let load = (init_model: t): t => { let settings = Store.Settings.load(); let explainThisModel = Store.ExplainThisModel.load(); @@ -150,6 +160,7 @@ let load = (init_model: t): t => { let save = ({editors, settings, explainThisModel, results, _}: t) => { save_editors(editors, results, ~instructor_mode=settings.instructor_mode); + // save_editors_2(editors, results); Store.ExplainThisModel.save(explainThisModel); Store.Settings.save(settings); }; diff --git a/src/haz3lweb/PersistentData.re b/src/haz3lweb/PersistentData.re index 6e7b1a4419..3af156e4cf 100644 --- a/src/haz3lweb/PersistentData.re +++ b/src/haz3lweb/PersistentData.re @@ -11,7 +11,7 @@ type scratch = ( [@deriving (show({with_path: false}), sexp, yojson)] type documentation = ( string, - list((string, ScratchSlide.persistent_state)), + list((string, DocumentationEnv.persistent_state)), [@default []] list((string, ModelResult.persistent)), ); diff --git a/src/haz3lweb/ScratchSlide.re b/src/haz3lweb/ScratchSlide.re index 40234eeaff..94910ca1b1 100644 --- a/src/haz3lweb/ScratchSlide.re +++ b/src/haz3lweb/ScratchSlide.re @@ -81,6 +81,11 @@ let unpersist = (zipper: persistent_state) => { Editor.init(zipper, ~read_only=false); }; +// let unpersist = (zipper: persistent_state) => { +// let zipper = PersistentZipper.unpersist(zipper.hidden_tests.tests); +// Editor.init(zipper, ~read_only=false); +// }; + let serialize = (state: state) => { let editor = persist(state.hidden_tests.tests); let persistent_state: persistent_state = { diff --git a/src/haz3lweb/Store.re b/src/haz3lweb/Store.re index 2477174a52..2f34ca5625 100644 --- a/src/haz3lweb/Store.re +++ b/src/haz3lweb/Store.re @@ -194,10 +194,10 @@ module Documentation = { ); }; - let unpersist = ((name, zipper)) => { - let zipper = PersistentZipper.unpersist(zipper); - (name, Editor.init(zipper, ~read_only=false)); - }; + // let unpersist = ((name, zipper)) => { + // let zipper = PersistentZipper.unpersist(zipper); + // (name, Editor.init(zipper, ~read_only=false)); + // }; // let fromEditor = (editor: Editor.t): ScratchSlide.persistent_state => { // title: "", @@ -206,14 +206,16 @@ module Documentation = { // }; let pzipper_to_pstate = - (slide: PersistentZipper.t): ScratchSlide.persistent_state => { - // { + (slide: PersistentZipper.t): DocumentationEnv.persistent_state => { + focus: YourImpl, title: "", description: "", - hidden_tests: { - tests: slide, - hints: [], - }, + editors: [(HiddenTests, slide)], + // your_impl: Editor.init(Zipper.init()), + // hidden_tests: { + // tests: slide, + // hints: [], + // }, // }; }; @@ -233,16 +235,23 @@ module Documentation = { ); }; + let unpersist = (state: DocumentationEnv.persistent_state) => { + let focused_zipper = List.assoc(state.focus, state.editors); + let zipper = PersistentZipper.unpersist(focused_zipper); + Editor.init(zipper, ~read_only=false); + }; + let of_persistent = (~settings, (string, slides, results): persistent) => { - let state_to_zipper = - ((str: string, status: ScratchSlide.persistent_state)) => { - (str, ScratchSlide.unpersist(status)); + let state_to_editor = + ((str: string, status: DocumentationEnv.persistent_state)) => { + (str, unpersist(status)); }; - let slides = List.map(state_to_zipper, slides); - let slides = List.map(persist, slides); + let slides = List.map(state_to_editor, slides); + // let slides = List.map(persist, slides); ( string, - List.map(unpersist, slides), + slides, + // List.map(unpersist, slides), results |> List.to_seq |> ModelResults.of_seq