From 0223429e470d3fb84c8bd8d96920f1b8f72adbff Mon Sep 17 00:00:00 2001 From: BENJAMIN PEINHARDT Date: Sun, 1 Sep 2024 22:49:58 -0500 Subject: [PATCH] remove columns and rows from UI --- squared_away/src/squared_away.gleam | 14 +---- .../src/squared_away_lang/interpreter.gleam | 7 --- .../src/squared_away_lang/parser.gleam | 6 -- .../src/squared_away_lang/parser/expr.gleam | 1 - .../src/squared_away_lang/scanner.gleam | 60 ++----------------- .../src/squared_away_lang/scanner/token.gleam | 3 - .../src/squared_away_lang/typechecker.gleam | 10 ---- .../typechecker/typed_expr.gleam | 1 - 8 files changed, 6 insertions(+), 96 deletions(-) diff --git a/squared_away/src/squared_away.gleam b/squared_away/src/squared_away.gleam index 0f6edb1..30d37d1 100644 --- a/squared_away/src/squared_away.gleam +++ b/squared_away/src/squared_away.gleam @@ -97,13 +97,6 @@ fn update(model: Model, msg: Msg) -> #(Model, effect.Effect(Msg)) { fn view(model: Model) -> element.Element(Msg) { let alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" |> string.to_graphemes - let columns = [ - html.th([class("sticky-header")], [html.text("")]), - ..list.map(alphabet, fn(l) { - html.th([class("sticky-header")], [html.text(l)]) - }) - ] - let rows = list.range(1, 100) |> list.map(int.to_string) @@ -132,15 +125,12 @@ fn view(model: Model) -> element.Element(Msg) { }) }) - html.tr([], [html.th([class("sticky-column")], t(row)), ..cells]) + html.tr([], cells) }) let grid = html.div([class("table-container")], [ - html.table([], [ - html.thead([], [html.tr([], columns)]), - html.tbody([], rows), - ]), + html.table([], [html.tbody([], rows)]), ]) let formula_mode_toggle = diff --git a/squared_away_lang/src/squared_away_lang/interpreter.gleam b/squared_away_lang/src/squared_away_lang/interpreter.gleam index 2b4bf18..9968ef8 100644 --- a/squared_away_lang/src/squared_away_lang/interpreter.gleam +++ b/squared_away_lang/src/squared_away_lang/interpreter.gleam @@ -69,13 +69,6 @@ pub fn interpret( typed_expr.BooleanLiteral(_, b) -> Ok(value.Boolean(b)) typed_expr.IntegerLiteral(_, n) -> Ok(value.Integer(n)) typed_expr.FloatLiteral(_, f) -> Ok(value.FloatingPointNumber(f)) - typed_expr.CellReference(_, cell_ref) -> { - let assert Ok(maybe_expr) = dict.get(env, cell_ref) - case maybe_expr { - Error(e) -> Error(e) - Ok(expr) -> interpret(env, expr) - } - } typed_expr.UnaryOp(_, op, expr) -> { use value <- result.try(interpret(env, expr)) case op, value { diff --git a/squared_away_lang/src/squared_away_lang/parser.gleam b/squared_away_lang/src/squared_away_lang/parser.gleam index 19b07b7..800fa4a 100644 --- a/squared_away_lang/src/squared_away_lang/parser.gleam +++ b/squared_away_lang/src/squared_away_lang/parser.gleam @@ -48,12 +48,6 @@ fn do_parse( Error(_) -> Ok(#(expr.FloatLiteral(f), rest)) } } - [token.CellReference(key), ..rest] -> { - case try_parse_binary_ops(rest) { - Ok(#(op, rest)) -> Ok(#(op(expr.CellReference(key)), rest)) - Error(_) -> Ok(#(expr.CellReference(key), rest)) - } - } [token.TrueToken, ..rest] -> { case try_parse_binary_ops(rest) { Ok(#(op, rest)) -> Ok(#(op(expr.BooleanLiteral(True)), rest)) diff --git a/squared_away_lang/src/squared_away_lang/parser/expr.gleam b/squared_away_lang/src/squared_away_lang/parser/expr.gleam index e2f563b..f57701c 100644 --- a/squared_away_lang/src/squared_away_lang/parser/expr.gleam +++ b/squared_away_lang/src/squared_away_lang/parser/expr.gleam @@ -5,7 +5,6 @@ pub type Expr { Label(txt: String) CrossLabel(row: String, col: String) IntegerLiteral(n: Int) - CellReference(key: String) BooleanLiteral(val: Bool) UnaryOp(op: UnaryOpKind, expr: Expr) BinaryOp(lhs: Expr, op: BinaryOpKind, rhs: Expr) diff --git a/squared_away_lang/src/squared_away_lang/scanner.gleam b/squared_away_lang/src/squared_away_lang/scanner.gleam index ef89cc0..cad67f1 100644 --- a/squared_away_lang/src/squared_away_lang/scanner.gleam +++ b/squared_away_lang/src/squared_away_lang/scanner.gleam @@ -62,19 +62,10 @@ fn do_scan( } Error(_) -> { - case parse_cell_ref(src, "") { - Ok(#(cell_ref, rest)) -> - do_scan(string.trim_left(rest), [ - token.CellReference(cell_ref), - ..acc - ]) - _ -> { - case parse_identifier(src, "") { - Error(Nil) -> Error(scan_error.ScanError) - Ok(#(ident, rest)) -> - do_scan(string.trim_left(rest), [token.Label(ident), ..acc]) - } - } + case parse_identifier(src, "") { + Error(Nil) -> Error(scan_error.ScanError) + Ok(#(ident, rest)) -> + do_scan(string.trim_left(rest), [token.Label(ident), ..acc]) } } } @@ -148,49 +139,6 @@ fn parse_identifier(src: String, acc: String) -> Result(#(String, String), Nil) } } -fn parse_cell_ref(src: String, acc: String) -> Result(#(String, String), Nil) { - // A cell reference is a string of characters followed by a string of numbers (aka an int), - // so we can reuse the integer parsing at a slight runtime cost for now - case src { - "A" as l <> rest - | "B" as l <> rest - | "C" as l <> rest - | "D" as l <> rest - | "E" as l <> rest - | "F" as l <> rest - | "G" as l <> rest - | "H" as l <> rest - | "I" as l <> rest - | "J" as l <> rest - | "K" as l <> rest - | "L" as l <> rest - | "M" as l <> rest - | "N" as l <> rest - | "O" as l <> rest - | "P" as l <> rest - | "Q" as l <> rest - | "R" as l <> rest - | "S" as l <> rest - | "T" as l <> rest - | "U" as l <> rest - | "V" as l <> rest - | "W" as l <> rest - | "X" as l <> rest - | "Y" as l <> rest - | "Z" as l <> rest -> parse_cell_ref(rest, acc <> l) - _ -> { - case acc { - // Meaning we called this on something that didnt start with a capital letter - "" -> Error(Nil) - _ -> { - use #(n, rest) <- result.try(parse_integer(src, "")) - Ok(#(acc <> int.to_string(n), rest)) - } - } - } - } -} - fn parse_integer(src: String, acc: String) -> Result(#(Int, String), Nil) { case src { "1" as x <> rest diff --git a/squared_away_lang/src/squared_away_lang/scanner/token.gleam b/squared_away_lang/src/squared_away_lang/scanner/token.gleam index a65c899..afff93f 100644 --- a/squared_away_lang/src/squared_away_lang/scanner/token.gleam +++ b/squared_away_lang/src/squared_away_lang/scanner/token.gleam @@ -41,9 +41,6 @@ pub type Token { LParen /// ) RParen - /// Cell Reference A3, XX532 - CellReference(key: String) - /// Anything not starting with an = in a cell is a string literal Label(String) LabelDef(txt: String) Underscore diff --git a/squared_away_lang/src/squared_away_lang/typechecker.gleam b/squared_away_lang/src/squared_away_lang/typechecker.gleam index 54e6fa2..9e9b249 100644 --- a/squared_away_lang/src/squared_away_lang/typechecker.gleam +++ b/squared_away_lang/src/squared_away_lang/typechecker.gleam @@ -107,16 +107,6 @@ pub fn typecheck( use expr <- result.try(typecheck(env, inner)) Ok(typed_expr.Group(type_: expr.type_, expr:)) } - expr.CellReference(key) -> { - let assert Ok(ref_expr) = dict.get(env, key) - case ref_expr { - Ok(expr) -> { - use expr <- result.try(typecheck(env, expr)) - Ok(typed_expr.CellReference(type_: expr.type_, key:)) - } - Error(e) -> Error(e) - } - } expr.UnaryOp(op, expr) -> { use expr <- result.try(typecheck(env, expr)) case op, expr.type_ { diff --git a/squared_away_lang/src/squared_away_lang/typechecker/typed_expr.gleam b/squared_away_lang/src/squared_away_lang/typechecker/typed_expr.gleam index e3815db..2711687 100644 --- a/squared_away_lang/src/squared_away_lang/typechecker/typed_expr.gleam +++ b/squared_away_lang/src/squared_away_lang/typechecker/typed_expr.gleam @@ -8,7 +8,6 @@ pub type TypedExpr { CrossLabel(type_: typ.Typ, key: String) LabelDef(type_: typ.Typ, txt: String) IntegerLiteral(type_: typ.Typ, n: Int) - CellReference(type_: typ.Typ, key: String) BooleanLiteral(type_: typ.Typ, b: Bool) UnaryOp(type_: typ.Typ, op: expr.UnaryOpKind, expr: TypedExpr) BinaryOp(