Skip to content

Commit

Permalink
fix bug I just introduced with cross labels
Browse files Browse the repository at this point in the history
  • Loading branch information
bcpeinhardt committed Oct 26, 2024
1 parent c5c1eb9 commit a7d44e6
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 21 deletions.
2 changes: 1 addition & 1 deletion squared_away/src/squared_away.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 8 additions & 5 deletions squared_away_lang/src/squared_away_lang/interpreter.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -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) -> {
Expand Down
5 changes: 4 additions & 1 deletion squared_away_lang/src/squared_away_lang/parser.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -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),
))
}
}
}

Expand Down
15 changes: 5 additions & 10 deletions squared_away_lang/src/squared_away_lang/typechecker.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit a7d44e6

Please sign in to comment.