From a7d44e601182db03d0b43773e534b4573b340592 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Sat, 26 Oct 2024 17:56:46 -0500 Subject: [PATCH] fix bug I just introduced with cross labels --- squared_away/src/squared_away.gleam | 2 +- .../parse_cross_reference.accepted | 8 ++++---- .../src/squared_away_lang/interpreter.gleam | 13 ++++++++----- .../src/squared_away_lang/parser.gleam | 5 ++++- .../src/squared_away_lang/typechecker.gleam | 15 +++++---------- 5 files changed, 22 insertions(+), 21 deletions(-) diff --git a/squared_away/src/squared_away.gleam b/squared_away/src/squared_away.gleam index 61b1a81..4f5fd51 100644 --- a/squared_away/src/squared_away.gleam +++ b/squared_away/src/squared_away.gleam @@ -226,7 +226,7 @@ fn error_view(e: error.CompileError) { type_error.TypeError(txt) -> html.div([], t(txt)) } } - _ -> html.p([], t("Unimplemented view")) + _ -> html.p([], t(error.to_string(e))) } } diff --git a/squared_away_lang/birdie_snapshots/parse_cross_reference.accepted b/squared_away_lang/birdie_snapshots/parse_cross_reference.accepted index 7dff4b4..f6b6b8e 100644 --- a/squared_away_lang/birdie_snapshots/parse_cross_reference.accepted +++ b/squared_away_lang/birdie_snapshots/parse_cross_reference.accepted @@ -4,7 +4,7 @@ title: Parse Cross Reference file: ./test/squared_away_lang_test.gleam test_name: parse_cross_ref_test --- -C2: 4 -A2: Ben -B2: 4 -B1: Height +1_2: Ben +2_1: Height +2_2: 4 +3_2: 4 diff --git a/squared_away_lang/src/squared_away_lang/interpreter.gleam b/squared_away_lang/src/squared_away_lang/interpreter.gleam index 9968ef8..2d24ae0 100644 --- a/squared_away_lang/src/squared_away_lang/interpreter.gleam +++ b/squared_away_lang/src/squared_away_lang/interpreter.gleam @@ -19,11 +19,14 @@ pub fn interpret( typed_expr.Empty(_) -> Ok(value.Empty) typed_expr.LabelDef(_, txt) -> Ok(value.Text(txt)) typed_expr.Group(_, expr) -> interpret(env, expr) - typed_expr.CrossLabel(_, key) -> { - let assert Ok(expr) = dict.get(env, key) - case expr { - Error(e) -> Error(e) - Ok(expr) -> interpret(env, expr) + typed_expr.CrossLabel(x, key) -> { + case dict.get(env, key) { + Ok(expr) -> + case expr { + Error(e) -> Error(e) + Ok(expr) -> interpret(env, expr) + } + Error(_) -> Ok(value.Empty) } } typed_expr.Label(_, txt) -> { diff --git a/squared_away_lang/src/squared_away_lang/parser.gleam b/squared_away_lang/src/squared_away_lang/parser.gleam index 800fa4a..9da3cb3 100644 --- a/squared_away_lang/src/squared_away_lang/parser.gleam +++ b/squared_away_lang/src/squared_away_lang/parser.gleam @@ -11,10 +11,13 @@ pub fn parse( use #(expr, rest) <- result.try(do_parse(tokens)) case rest { [] -> Ok(expr) - _ -> + _ -> { + io.debug(expr) + io.debug(rest) Error(parse_error.ParseError( "After parsing there were leftover tokens " <> string.inspect(rest), )) + } } } diff --git a/squared_away_lang/src/squared_away_lang/typechecker.gleam b/squared_away_lang/src/squared_away_lang/typechecker.gleam index 685b9dd..ba8c290 100644 --- a/squared_away_lang/src/squared_away_lang/typechecker.gleam +++ b/squared_away_lang/src/squared_away_lang/typechecker.gleam @@ -63,11 +63,10 @@ pub fn typecheck( _ -> Continue(None) } }) - let col = + + let assert Ok(#(col, _)) = col_cell - |> string.to_graphemes - |> list.filter(string.contains("ABCDEFGHIJKLMNOPQRSTUVWXYZ", _)) - |> string.join("") + |> string.split_once("_") let assert Some(row_cell) = env @@ -81,12 +80,8 @@ pub fn typecheck( } }) - let row = - row_cell - |> string.to_graphemes - |> list.filter(string.contains("0123456789", _)) - |> string.join("") - let key = col <> row + let assert Ok(#(_, row)) = row_cell |> string.split_once("_") + let key = col <> "_" <> row let assert Ok(x) = dict.get(env, key) case x {