Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
fcaa839
add Query action
coned Sep 30, 2023
c800f11
add buttons
coned Sep 30, 2023
0f6de78
rename Query as PerformQuery
coned Sep 30, 2023
482267b
finish cursor position
coned Oct 7, 2023
2bff616
add cursor info
coned Oct 21, 2023
0719866
add CursorMove and ContextInfo
coned Oct 29, 2023
ab08839
add minor query engine
coned Dec 11, 2023
9f42a60
Merge remote-tracking branch 'origin/a11y-query' into a11y-query
coned Dec 11, 2023
643c3fa
Merge remote-tracking branch 'origin/dev' into a11y-query
coned Dec 11, 2023
095556d
fix merge error
coned Dec 11, 2023
76ea97d
add basic structure
coned Dec 11, 2023
8cc9808
finish two commands
coned Dec 18, 2023
ae59105
add parser structure
coned Jan 8, 2024
ec03ad6
add QueryAst
coned Jan 29, 2024
59c11f6
add lexer/parser
coned Jan 29, 2024
3c0dd0d
Merge remote-tracking branch 'origin/dev' into a11y-query
coned Feb 24, 2024
706470d
fix query part
coned Feb 24, 2024
f47e5bc
fix scratchmode merge error
coned Feb 24, 2024
d2ab254
add prompt_bar
coned Feb 24, 2024
f72a880
add a11y model
coned Feb 24, 2024
e2b7cc8
add readme for a11y
coned Feb 24, 2024
9630786
add input for query
coned Feb 24, 2024
0983763
add a11y_bar
coned Feb 25, 2024
cd4d493
fix bugs of displaying a11y_bar
coned Feb 25, 2024
6ad3d7e
connect QueryEngine and A11yModel
coned Feb 25, 2024
84f163b
change the a11y toggle to \
coned Mar 4, 2024
28aa162
Merge remote-tracking branch 'origin/dev' into a11y-query
coned Mar 4, 2024
f86926e
change engine to execute command
coned Mar 4, 2024
7ebc5bd
clear code
coned Mar 5, 2024
106d3c8
add color highlight
coned Mar 5, 2024
c7318d1
change prompt notation
coned Mar 5, 2024
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
1 change: 1 addition & 0 deletions src/haz3lweb/Init.ml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ let startup : PersistentData.t =
mode = Documentation;
explainThis =
{ show = true; show_feedback = false; highlight = NoHighlight };
accessibility = { enable = true; is_editing = false };
};
scratch =
( 0,
Expand Down
1 change: 1 addition & 0 deletions src/haz3lweb/Keyboard.re
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ let handle_key_event = (k: Key.t): option(Update.t) => {
| (Down, "ArrowDown") => now(Select(Resize(Local(Down))))
| (Down, "Home") => now(Select(Resize(Extreme(Left(ByToken)))))
| (Down, "End") => now(Select(Resize(Extreme(Right(ByToken)))))
| (Up, "\\") => Some(Set(Accessibility(ToggleIsEditing)))
| (_, "Enter") => now(Insert(Form.linebreak))
| _ when String.length(key) == 1 =>
/* Note: length==1 prevent specials like
Expand Down
13 changes: 12 additions & 1 deletion src/haz3lweb/Model.re
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type t = {
results: ModelResults.t,
statics: CachedStatics.t,
explainThisModel: ExplainThisModel.t,
accessibilityModel: AccessibilityModel.t,
ui_state,
};

Expand All @@ -49,6 +50,7 @@ let mk = (editors, results, statics) => {
results,
statics,
explainThisModel: ExplainThisModel.init,
accessibilityModel: AccessibilityModel.init,
ui_state: ui_state_init,
};

Expand Down Expand Up @@ -93,9 +95,18 @@ let load = (init_model: t): t => {
~mode=settings.mode,
~instructor_mode=settings.instructor_mode,
);
let accessibilityModel = init_model.accessibilityModel;
let ui_state = init_model.ui_state;
let statics = Editors.mk_statics(~settings, editors);
{editors, settings, results, statics, explainThisModel, ui_state};
{
editors,
settings,
results,
statics,
explainThisModel,
accessibilityModel,
ui_state,
};
};

let save = ({editors, settings, explainThisModel, results, _}: t) => {
Expand Down
1 change: 1 addition & 0 deletions src/haz3lweb/Settings.re
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type t = {
instructor_mode: bool,
benchmark: bool,
explainThis: ExplainThisModel.Settings.t,
accessibility: AccessibilityModel.Settings.t,
mode,
};

Expand Down
27 changes: 27 additions & 0 deletions src/haz3lweb/Update.re
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,20 @@ let update_settings =
mode,
},
}
| Accessibility(ToggleEnable) =>
let accessibility = {
...settings.accessibility,
enable: !settings.accessibility.enable,
};
let settings = {...settings, accessibility};
{...model, settings};
| Accessibility(ToggleIsEditing) =>
let accessibility = {
...settings.accessibility,
is_editing: !settings.accessibility.is_editing,
};
let settings = {...settings, accessibility};
{...model, settings};
};

let schedule_evaluation = (~schedule_action, model: Model.t): unit =>
Expand Down Expand Up @@ -392,6 +406,19 @@ let rec apply =
: Zipper.can_put_down(z)
? PerformAction(Put_down) : MoveToNextHole(Right);
apply(model, a, state, ~schedule_action);
| PerformAction(a) when model.settings.accessibility.is_editing =>
let accessibilityModel =
AccessibilityUpdate.update_model(
~settings=model.settings,
~ctx_init=
model.editors |> Editors.get_ctx_init(~settings=model.settings),
~editor=model.editors |> Editors.get_editor,
model.accessibilityModel,
Edit(a),
);
let model = {...model, accessibilityModel};
JsUtil.log(model.accessibilityModel.input);
Ok(model);
| PerformAction(a)
when model.settings.core.assist && model.settings.core.statics =>
let model = UpdateAssistant.reset_buffer(model);
Expand Down
10 changes: 7 additions & 3 deletions src/haz3lweb/UpdateAction.re
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type settings_action =
| InstructorMode
| Evaluation(evaluation_settings_action)
| ExplainThis(ExplainThisModel.Settings.action)
| Accessibility(AccessibilityModel.Settings.action)
| Mode(Settings.mode);

[@deriving (show({with_path: false}), sexp, yojson)]
Expand Down Expand Up @@ -126,7 +127,8 @@ let is_edit: t => bool =
| Benchmark
| ContextInspector
| InstructorMode
| Evaluation(_) => false
| Evaluation(_)
| Accessibility(_) => false
}
| SetMeta(meta_action) =>
switch (meta_action) {
Expand Down Expand Up @@ -186,7 +188,8 @@ let reevaluate_post_update: t => bool =
| Elaborate
| Dynamics
| InstructorMode
| Mode(_) => true
| Mode(_)
| Accessibility(_) => true
}
| SetMeta(meta_action) =>
switch (meta_action) {
Expand Down Expand Up @@ -238,7 +241,8 @@ let should_scroll_to_caret =
| Benchmark
| ContextInspector
| InstructorMode
| Evaluation(_) => false
| Evaluation(_)
| Accessibility(_) => false
}
| SetMeta(meta_action) =>
switch (meta_action) {
Expand Down
22 changes: 21 additions & 1 deletion src/haz3lweb/view/Page.re
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ open Js_of_ocaml;
open Haz3lcore;
open Virtual_dom.Vdom;
open Node;
open Util;

let handlers = (~inject: UpdateAction.t => Ui_effect.t(unit), model) => {
let get_selection = (model: Model.t): string =>
Expand Down Expand Up @@ -51,7 +52,16 @@ let handlers = (~inject: UpdateAction.t => Ui_effect.t(unit), model) => {
let main_view =
(
~inject: UpdateAction.t => Ui_effect.t(unit),
{settings, editors, explainThisModel, results, statics, ui_state, _}: Model.t,
{
settings,
editors,
explainThisModel,
accessibilityModel,
results,
statics,
ui_state,
_,
}: Model.t,
) => {
let editor = Editors.get_editor(editors);
let statics = Editors.lookup_statics(~settings, ~statics, editors);
Expand All @@ -64,6 +74,7 @@ let main_view =
@ [EditorModeView.view(~inject, ~settings, ~editors)],
);
let bottom_bar = CursorInspector.view(~inject, ~settings, cursor_info);
let a11y_bar = Accessibility.view(~_inject=inject, accessibilityModel);
let sidebar =
settings.explainThis.show && settings.core.statics
? ExplainThis.view(
Expand All @@ -76,6 +87,14 @@ let main_view =
: div([]);
let highlights =
ExplainThis.get_color_map(~settings, ~explainThisModel, cursor_info);
let highlights =
Some(
accessibilityModel.colorings
|> List.fold_left(
(map, (id, color)) => Id.Map.add(id, color, map),
highlights |> OptUtil.get(() => Id.Map.empty),
),
);
let editors_view =
switch (editors) {
| Scratch(idx, _) =>
Expand Down Expand Up @@ -129,6 +148,7 @@ let main_view =
),
sidebar,
bottom_bar,
a11y_bar,
];
};

Expand Down
26 changes: 26 additions & 0 deletions src/haz3lweb/view/a11y/Accessibility.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
open Virtual_dom.Vdom;
//open Util.Web;

let inputField_id = "a11y-input";
let outputArea_id = "a11y-output";

let input_view = (id, input): Node.t => {
Node.div(~attr=Attr.id(id), [Node.text("\\" ++ input)]);
};

let output_view = (id, content): Node.t => {
Node.div(~attr=Attr.id(id), [Node.text(content)]);
};

let view = (~_inject, model: AccessibilityModel.t): Node.t => {
Node.div(
~attr=Attr.classes(["a11y"]),
[
input_view(inputField_id, model.input),
output_view(
outputArea_id,
model.query_result |> Option.value(~default=""),
),
],
);
};
121 changes: 121 additions & 0 deletions src/haz3lweb/view/a11y/AccessibilityEngine.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
open Haz3lcore;
open Sexplib.Std;
open QueryAst;

let query_parser = (query: string) => {
let lexbuf = Lexing.from_string(query);
let result =
switch (Parser.main(Lexer.token, lexbuf)) {
| query_ast => Some(query_ast)
| exception _ => None
};
JsUtil.log(result);
result;
};

module QueryResult = {
[@deriving (show({with_path: false}), sexp, yojson)]
type textobject =
| Term(Term.t)
| Info(Info.t)
| Type(Typ.t);

[@deriving (show({with_path: false}), sexp, yojson)]
type t = {
msg: string,
t_object: option(textobject),
};

let empty = {msg: "nothing", t_object: None};
let error = (msg: string) => {msg, t_object: None};

let mk = (msg, t_object): t => {
{msg, t_object};
};

let change_msg = (msg: string, result: t): t => {
{msg, t_object: result.t_object};
};

let get_id = (result: t): option(Id.t) => {
switch (result.t_object) {
| Some(Info(ci)) => Some(Info.id_of(ci))
| _ => None
};
};
};

let rec evaluate_text_object =
(
~settings: Settings.t,
~ctx_init,
~editor: Editor.t,
text_obj: text_object,
) => {
switch (text_obj) {
| Inner(Term) =>
let zipper = editor.state.zipper;
let (term, _) = MakeTerm.from_zip_for_sem(zipper);
let info_map =
Interface.Statics.mk_map_ctx(settings.core, ctx_init, term);
let result =
switch (zipper.backpack, Indicated.index(zipper)) {
| _ when !settings.core.statics => QueryResult.empty
| _ when Id.Map.is_empty(info_map) =>
QueryResult.error("No Static information available")
| (_, None) => QueryResult.error("No cursor in program")
| (_, Some(id)) =>
switch (Id.Map.find_opt(id, info_map)) {
| None => QueryResult.error("Whitespace or Comment")
| Some(ci) => QueryResult.mk("info", Some(QueryResult.Info(ci)))
}
};
result;
| Inner(Parenthesis) => QueryResult.empty
| Queried(query) => evaluate_query(~settings, ~ctx_init, ~editor, query)
};
}

and evaluate_query =
(
~settings: Settings.t,
~ctx_init,
~editor: Editor.t,
query: QueryAst.query,
)
: QueryResult.t => {
let (text_obj_command, q_op) = query;
let text_obj_result =
evaluate_text_object(~settings, ~ctx_init, ~editor, text_obj_command);
switch (text_obj_result.t_object, q_op) {
| (Some(Info(ci)), (None, Type)) =>
switch (ci) {
| InfoExp(e) =>
QueryResult.mk(e.ty |> Typ.show, Some(QueryResult.Type(e.ty)))
| InfoPat(p) =>
QueryResult.mk(p.ty |> Typ.show, Some(QueryResult.Type(p.ty)))
| InfoTyp(t) =>
QueryResult.mk(t.ty |> Typ.show, Some(QueryResult.Type(t.ty)))
| _ => QueryResult.error("No type information available")
}
| (_, (None, Type)) => QueryResult.error("No type information available")
| _ => QueryResult.error("No information available")
};
};

let evaluate_command =
(
~settings: Settings.t,
~ctx_init,
~editor: Editor.t,
command: QueryAst.command,
)
: QueryResult.t => {
switch (command) {
| Query(query) => evaluate_query(~settings, ~ctx_init, ~editor, query)
| Partial(text_object) =>
evaluate_text_object(~settings, ~ctx_init, ~editor, text_object)
|> QueryResult.change_msg("The selected text is highlighted")
| Action(_) => QueryResult.empty
};
};
24 changes: 24 additions & 0 deletions src/haz3lweb/view/a11y/AccessibilityModel.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
open Sexplib.Std;
module Sexp = Sexplib.Sexp;
open Haz3lcore;
module Settings = {
[@deriving (show({with_path: false}), sexp, yojson)]
type t = {
enable: bool,
is_editing: bool,
};

[@deriving (show({with_path: false}), sexp, yojson)]
type action =
| ToggleEnable
| ToggleIsEditing;
};

[@deriving (show({with_path: false}), sexp, yojson)]
type t = {
input: string,
query_result: option(string),
colorings: list((Id.t, string)),
};

let init = {input: "", query_result: None, colorings: []};
Loading