From 08e7ee16015a6b4ef9a60ea81403dd0c83cdfbc3 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Fri, 8 Nov 2024 22:19:13 -0600 Subject: [PATCH] fix to_string issues --- index.html | 7 -- main.css | 10 +++ priv/static/squared_away.mjs | 64 ++++++++++--------- src/squared_away.gleam | 34 +++++----- .../typechecker/typed_expr.gleam | 2 +- 5 files changed, 61 insertions(+), 56 deletions(-) diff --git a/index.html b/index.html index c50ea9f..a27b965 100644 --- a/index.html +++ b/index.html @@ -8,13 +8,6 @@ 🚧 form - - diff --git a/main.css b/main.css index 8b13789..9f749ed 100644 --- a/main.css +++ b/main.css @@ -1 +1,11 @@ +table { + margin: auto; + padding-top: 20px; +} + +.menu-item { + padding: 10px 20px; + display: inline; +} + diff --git a/priv/static/squared_away.mjs b/priv/static/squared_away.mjs index a94c358..f3f6308 100644 --- a/priv/static/squared_away.mjs +++ b/priv/static/squared_away.mjs @@ -3518,9 +3518,6 @@ function div(attrs, children2) { function p(attrs, children2) { return element("p", attrs, children2); } -function br(attrs) { - return element("br", attrs, toList([])); -} function table(attrs, children2) { return element("table", attrs, children2); } @@ -5146,6 +5143,8 @@ function to_string11(te) { return "=" + do_to_string2(te); } else if (te instanceof BuiltinSum2) { return "=" + do_to_string2(te); + } else if (te instanceof CrossLabel2) { + return "=" + do_to_string2(te); } else { return do_to_string2(te); } @@ -5373,7 +5372,7 @@ function interpret(loop$env, loop$expr) { throw makeError( "let_assert", "squared_away/squared_away_lang/interpreter", - 156, + 161, "", "Pattern match failed, no pattern matched the value.", { value: $ } @@ -5389,7 +5388,7 @@ function interpret(loop$env, loop$expr) { throw makeError( "let_assert", "squared_away/squared_away_lang/interpreter", - 160, + 165, "", "Pattern match failed, no pattern matched the value.", { value: $ } @@ -5520,7 +5519,7 @@ function interpret(loop$env, loop$expr) { throw makeError( "let_assert", "squared_away/squared_away_lang/interpreter", - 239, + 245, "", "Pattern match failed, no pattern matched the value.", { value: v } @@ -5541,7 +5540,7 @@ function interpret(loop$env, loop$expr) { throw makeError( "let_assert", "squared_away/squared_away_lang/interpreter", - 247, + 253, "", "Pattern match failed, no pattern matched the value.", { value: v } @@ -5562,7 +5561,7 @@ function interpret(loop$env, loop$expr) { throw makeError( "let_assert", "squared_away/squared_away_lang/interpreter", - 255, + 261, "", "Pattern match failed, no pattern matched the value.", { value: v } @@ -7683,7 +7682,7 @@ function view(model) { } else { let $12 = get4(model.value_grid, key); if (!$12.isOk()) { - return "center"; + return "left"; } else { let v = $12[0]; if (v instanceof Percent) { @@ -7789,14 +7788,9 @@ function view(model) { return e[1]; }); })(); - let grid = div( - toList([class$("table-container")]), - toList([ - table( - toList([class$("tg")]), - toList([tbody(toList([]), rows)]) - ) - ]) + let grid = table( + toList([class$("tg")]), + toList([tbody(toList([]), rows)]) ); let formula_mode_toggle = input( toList([ @@ -7828,7 +7822,6 @@ function view(model) { toList([on_click(new UserClickedSaveBtn())]), t("Save") ); - let load_label = label(toList([]), t("Load file")); let load_button = input( toList([ type_("file"), @@ -7839,19 +7832,30 @@ function view(model) { ]) ); return div( - toList([]), + toList([style(toList([["text-align", "center"]]))]), toList([ - formula_mode_toggle, - formula_mode_toggle_label, - grid_mode_toggle, - grid_mode_toggle_label, - save_button, - load_label, - load_button, - br(toList([])), - br(toList([])), + div( + toList([]), + toList([ + div( + toList([class$("menu-item")]), + toList([formula_mode_toggle, formula_mode_toggle_label]) + ), + div( + toList([class$("menu-item")]), + toList([grid_mode_toggle, grid_mode_toggle_label]) + ), + div( + toList([class$("menu-item")]), + toList([load_button]) + ), + div( + toList([class$("menu-item")]), + toList([save_button]) + ) + ]) + ), grid, - br(toList([])), error_to_display ]) ); @@ -8135,7 +8139,7 @@ function update(model, msg) { return [model, none()]; } else { let new_expr = expr_with_labels_updated[0]; - let formula = "=" + to_string11(new_expr); + let formula = to_string11(new_expr); let src_grid = insert4(model.src_grid, cell_below, formula); let id2 = to_string7(cell_below); focus(id2); diff --git a/src/squared_away.gleam b/src/squared_away.gleam index e15fce2..9d93302 100644 --- a/src/squared_away.gleam +++ b/src/squared_away.gleam @@ -275,7 +275,7 @@ fn update(model: Model, msg: Msg) -> #(Model, effect.Effect(Msg)) { case expr_with_labels_updated { Error(_) -> #(model, effect.none()) Ok(new_expr) -> { - let formula = "=" <> typed_expr.to_string(new_expr) + let formula = typed_expr.to_string(new_expr) let src_grid = grid.insert(model.src_grid, cell_below, formula) @@ -379,7 +379,7 @@ fn view(model: Model) -> element.Element(Msg) { True -> "left" False -> case grid.get(model.value_grid, key) { - Error(_) -> "center" + Error(_) -> "left" Ok(v) -> case v { value.Percent(_) @@ -447,10 +447,7 @@ fn view(model: Model) -> element.Element(Msg) { |> list.sort(fn(r1, r2) { int.compare(r1.0, r2.0) }) |> list.map(fn(e) { e.1 }) - let grid = - html.div([class("table-container")], [ - html.table([attribute.class("tg")], [html.tbody([], rows)]), - ]) + let grid = html.table([attribute.class("tg")], [html.tbody([], rows)]) let formula_mode_toggle = html.input([ @@ -473,7 +470,6 @@ fn view(model: Model) -> element.Element(Msg) { html.label([attribute.for("grid_mode")], t("Show grid coordinates")) let save_button = html.button([event.on_click(UserClickedSaveBtn)], t("Save")) - let load_label = html.label([], t("Load file")) let load_button = html.input([ attribute.type_("file"), @@ -481,18 +477,20 @@ fn view(model: Model) -> element.Element(Msg) { event.on_input(UserUploadedFile), ]) - html.div([], [ - formula_mode_toggle, - formula_mode_toggle_label, - grid_mode_toggle, - grid_mode_toggle_label, - save_button, - load_label, - load_button, - html.br([]), - html.br([]), + html.div([attribute.style([#("text-align", "center")])], [ + html.div([], [ + html.div([attribute.class("menu-item")], [ + formula_mode_toggle, + formula_mode_toggle_label, + ]), + html.div([attribute.class("menu-item")], [ + grid_mode_toggle, + grid_mode_toggle_label, + ]), + html.div([attribute.class("menu-item")], [load_button]), + html.div([attribute.class("menu-item")], [save_button]), + ]), grid, - html.br([]), error_to_display, ]) } diff --git a/src/squared_away/squared_away_lang/typechecker/typed_expr.gleam b/src/squared_away/squared_away_lang/typechecker/typed_expr.gleam index 62c3793..9d07de3 100644 --- a/src/squared_away/squared_away_lang/typechecker/typed_expr.gleam +++ b/src/squared_away/squared_away_lang/typechecker/typed_expr.gleam @@ -58,7 +58,7 @@ pub fn visit_cross_labels( pub fn to_string(te: TypedExpr) -> String { case te { - Label(_, _) | UnaryOp(_, _, _) | BinaryOp(_, _, _, _) | BuiltinSum(_, _) -> + Label(_, _) | UnaryOp(_, _, _) | BinaryOp(_, _, _, _) | BuiltinSum(_, _) | CrossLabel(_, _, _, _) -> "=" <> do_to_string(te) _ -> do_to_string(te) }