Skip to content

Commit

Permalink
Fix module formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
smores56 committed Jan 6, 2025
1 parent cd0e2a4 commit f524d35
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 127 deletions.
6 changes: 3 additions & 3 deletions crates/compiler/builtins/roc/Bool.roc
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ Eq implements
## `Bool` implements the `Eq` ability.
Bool := [True, False] implements [Eq { is_eq: bool_is_eq }]

bool_is_eq = \@Bool b1, @Bool b2 -> structural_eq b1 b2
bool_is_eq = \@Bool(b1), @Bool(b2) -> structural_eq(b1, b2)

## The boolean true value.
true : Bool
true = @Bool (True)
true = @Bool(True)

## The boolean false value.
false : Bool
false = @Bool (False)
false = @Bool(False)

## Returns `Bool.true` when both inputs are `Bool.true`. This is equivalent to
## the logic [AND](https://en.wikipedia.org/wiki/Logical_conjunction)
Expand Down
6 changes: 3 additions & 3 deletions crates/compiler/builtins/roc/Decode.roc
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,10 @@ from_bytes = \bytes, fmt ->
{ result, rest } ->
if List.is_empty(rest) then
when result is
Ok val -> Ok (val)
Err TooShort -> Err (TooShort)
Ok(val) -> Ok(val)
Err(TooShort) -> Err(TooShort)
else
Err (Leftover (rest))
Err(Leftover(rest))

## Transform the `val` of a [DecodeResult]
map_result : DecodeResult a, (a -> b) -> DecodeResult b
Expand Down
242 changes: 123 additions & 119 deletions crates/compiler/builtins/roc/Inspect.roc
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ custom : (f -> f) -> Inspector f where f implements InspectFormatter
custom = \fn -> @Inspector(fn)

apply : Inspector f, f -> f where f implements InspectFormatter
apply = \@Inspector fn, fmt -> fn(fmt)
apply = \@Inspector(fn), fmt -> fn(fmt)

Inspect implements
to_inspector : val -> Inspector f where val implements Inspect, f implements InspectFormatter
Expand Down Expand Up @@ -138,140 +138,143 @@ dbg_init = \{} -> @DbgFormatter({ data: "" })

dbg_list : list, ElemWalker (DbgFormatter, Bool) list elem, (elem -> Inspector DbgFormatter) -> Inspector DbgFormatter
dbg_list = \content, walk_fn, to_dbg_inspector ->
custom(\f0 ->
dbg_write(f0, "[")
|> \f1 ->
walk_fn(
content,
(f1, Bool.false),
\(f2, prepend_sep), elem ->
f3 =
if prepend_sep then
dbg_write(f2, ", ")
else
f2

elem
|> to_dbg_inspector
|> apply(f3)
|> \f4 -> (f4, Bool.true),
)
|> .0
|> dbg_write("]")
)
custom_list_dbg = \f0 ->
f1 = dbg_write(f0, "[")
(f5, _) = walk_fn(
content,
(f1, Bool.false),
\(f2, prepend_sep), elem ->
f3 =
if prepend_sep then
dbg_write(f2, ", ")
else
f2

elem
|> to_dbg_inspector
|> apply(f3)
|> \f4 -> (f4, Bool.true),
)

dbg_write(f5, "]")

custom(custom_list_dbg)

dbg_set : set, ElemWalker (DbgFormatter, Bool) set elem, (elem -> Inspector DbgFormatter) -> Inspector DbgFormatter
dbg_set = \content, walk_fn, to_dbg_inspector ->
custom(\f0 ->
dbg_write(f0, "{")
|> \f1 ->
walk_fn(
content,
(f1, Bool.false),
\(f2, prepend_sep), elem ->
f3 =
if prepend_sep then
dbg_write(f2, ", ")
else
f2

elem
|> to_dbg_inspector
|> apply(f3)
|> \f4 -> (f4, Bool.true),
)
|> .0
|> dbg_write("}")
)
custom_dbg_set = \f0 ->
f1 = dbg_write(f0, "{")
(f5, _) = walk_fn(
content,
(f1, Bool.false),
\(f2, prepend_sep), elem ->
f3 =
if prepend_sep then
dbg_write(f2, ", ")
else
f2

elem
|> to_dbg_inspector
|> apply(f3)
|> \f4 -> (f4, Bool.true),
)

dbg_write(f5, "}")

custom(custom_dbg_set)

dbg_dict : dict, KeyValWalker (DbgFormatter, Bool) dict key value, (key -> Inspector DbgFormatter), (value -> Inspector DbgFormatter) -> Inspector DbgFormatter
dbg_dict = \d, walk_fn, key_to_inspector, value_to_inspector ->
custom(\f0 ->
dbg_write(f0, "{")
|> \f1 ->
walk_fn(
d,
(f1, Bool.false),
\(f2, prepend_sep), key, value ->
f3 =
if prepend_sep then
dbg_write(f2, ", ")
else
f2

apply(key_to_inspector(key), f3)
|> dbg_write(": ")
|> \x -> apply(value_to_inspector(value), x)
|> \f4 -> (f4, Bool.true),
)
|> .0
|> dbg_write("}")
)
custom_dbg_dict = \f0 ->
f1 = dbg_write(f0, "{")
(f5, _) = walk_fn(
d,
(f1, Bool.false),
\(f2, prepend_sep), key, value ->
f3 =
if prepend_sep then
dbg_write(f2, ", ")
else
f2

apply(key_to_inspector(key), f3)
|> dbg_write(": ")
|> \x -> apply(value_to_inspector(value), x)
|> \f4 -> (f4, Bool.true),
)

dbg_write(f5, "}")

custom(custom_dbg_dict)

dbg_tag : Str, List (Inspector DbgFormatter) -> Inspector DbgFormatter
dbg_tag = \name, fields ->
if List.is_empty(fields) then
custom(\f0 -> dbg_write(f0, name))
else
custom(\f0 ->
dbg_write(f0, "(")
|> dbg_write(name)
|> \f1 ->
List.walk(
fields,
f1,
\f2, inspector ->
dbg_write(f2, " ")
|> \x -> apply(inspector, x),
)
|> dbg_write(")")
)
custom_dbg_tag = \f0 ->
f1 =
dbg_write(f0, "(")
|> dbg_write(name)

dbg_tuple : List (Inspector DbgFormatter) -> Inspector DbgFormatter
dbg_tuple = \fields ->
custom(\f0 ->
dbg_write(f0, "(")
|> \f1 ->
List.walk(
f3 = List.walk(
fields,
(f1, Bool.false),
\(f2, prepend_sep), inspector ->
f3 =
if prepend_sep then
dbg_write(f2, ", ")
else
f2

apply(inspector, f3)
|> \f4 -> (f4, Bool.true),
f1,
\f2, inspector ->
dbg_write(f2, " ")
|> \x -> apply(inspector, x),
)
|> .0
|> dbg_write(")")
)

dbg_write(f3, ")")

custom(custom_dbg_tag)

dbg_tuple : List (Inspector DbgFormatter) -> Inspector DbgFormatter
dbg_tuple = \fields ->
custom_dbg_tuple = \f0 ->
f1 = dbg_write(f0, "(")
(f5, _) = List.walk(
fields,
(f1, Bool.false),
\(f2, prepend_sep), inspector ->
f3 =
if prepend_sep then
dbg_write(f2, ", ")
else
f2

apply(inspector, f3)
|> \f4 -> (f4, Bool.true),
)

dbg_write(f5, ")")

custom(custom_dbg_tuple)

dbg_record : List { key : Str, value : Inspector DbgFormatter } -> Inspector DbgFormatter
dbg_record = \fields ->
custom(\f0 ->
dbg_write(f0, "{")
|> \f1 ->
List.walk(
fields,
(f1, Bool.false),
\(f2, prepend_sep), { key, value } ->
f3 =
if prepend_sep then
dbg_write(f2, ", ")
else
f2

dbg_write(f3, key)
|> dbg_write(": ")
|> \x -> apply(value, x)
|> \f4 -> (f4, Bool.true),
)
|> .0
|> dbg_write("}")
)
custom_dbg_record = \f0 ->
f1 = dbg_write(f0, "{")
(f5, _) = List.walk(
fields,
(f1, Bool.false),
\(f2, prepend_sep), { key, value } ->
f3 =
if prepend_sep then
dbg_write(f2, ", ")
else
f2

dbg_write(f3, key)
|> dbg_write(": ")
|> \x -> apply(value, x)
|> \f4 -> (f4, Bool.true),
)

dbg_write(f5, "}")

custom(custom_dbg_record)

dbg_bool : Bool -> Inspector DbgFormatter
dbg_bool = \b ->
Expand All @@ -280,12 +283,13 @@ dbg_bool = \b ->

dbg_str : Str -> Inspector DbgFormatter
dbg_str = \s ->
custom(\f0 ->
custom_dbg_str = \f0 ->
f0
|> dbg_write("\"")
|> dbg_write(s) # TODO: Should we be escaping strings for dbg/logging?
|> dbg_write("\"")
)

custom(custom_dbg_str)

dbg_opaque : * -> Inspector DbgFormatter
dbg_opaque = \_ ->
Expand Down
24 changes: 22 additions & 2 deletions crates/compiler/parse/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ fn loc_term_or_closure<'a>(
)),
loc_term(),
)
.trace("term_or_underscore")
.trace("term_or_closure")
}

fn loc_term<'a>() -> impl Parser<'a, Loc<Expr<'a>>, EExpr<'a>> {
Expand Down Expand Up @@ -718,7 +718,19 @@ fn parse_stmt_operator_chain<'a>(
..
},
state,
)) if matches!(expr_state.expr.value, Expr::Tag(..)) => {
)) if matches!(
expr_state.expr.value,
Expr::Tag(..)
| Expr::Apply(
Loc {
region: _,
value: Expr::Tag(..)
},
&[],
_
)
) =>
{
return parse_ability_def(expr_state, state, arena, implements, call_min_indent)
.map(|(td, s)| (MadeProgress, Stmt::TypeDef(td), s));
}
Expand Down Expand Up @@ -1997,6 +2009,14 @@ fn parse_ability_def<'a>(

let name = expr_state.expr.map_owned(|e| match e {
Expr::Tag(name) => name,
Expr::Apply(
Loc {
region: _,
value: Expr::Tag(name),
},
&[],
_,
) => name,
_ => unreachable!(),
});

Expand Down

0 comments on commit f524d35

Please sign in to comment.