Skip to content

Commit

Permalink
fix to_string issues
Browse files Browse the repository at this point in the history
  • Loading branch information
bcpeinhardt committed Nov 9, 2024
1 parent d3abc09 commit 08e7ee1
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 56 deletions.
7 changes: 0 additions & 7 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@

<title>🚧 form</title>

<style>
/* input.errorcell {
outline: 1px solid maroon;
border: 1px solid maroon;
} */
</style>

<!-- Uncomment this if you add the TailwindCSS integration -->
<!-- <link rel="stylesheet" href="/priv/static/form.css"> -->
<script type="module" src="/priv/static/squared_away.mjs"></script>
Expand Down
10 changes: 10 additions & 0 deletions main.css
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
table {
margin: auto;
padding-top: 20px;
}

.menu-item {
padding: 10px 20px;
display: inline;
}


64 changes: 34 additions & 30 deletions priv/static/squared_away.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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: $ }
Expand All @@ -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: $ }
Expand Down Expand Up @@ -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 }
Expand All @@ -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 }
Expand All @@ -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 }
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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([
Expand Down Expand Up @@ -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"),
Expand All @@ -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
])
);
Expand Down Expand Up @@ -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);
Expand Down
34 changes: 16 additions & 18 deletions src/squared_away.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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(_)
Expand Down Expand Up @@ -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([
Expand All @@ -473,26 +470,27 @@ 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"),
attribute.id("csvupload"),
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,
])
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 08e7ee1

Please sign in to comment.