mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 13:29:12 +00:00
cleanup, improve docs
This commit is contained in:
parent
c32fa5b600
commit
0143035dc0
8 changed files with 42 additions and 60 deletions
|
@ -495,12 +495,6 @@ pub fn desugar_expr<'a>(
|
|||
desugar_defs_node_values(arena, &mut defs, src, line_info, module_path, false);
|
||||
let loc_ret = desugar_expr(arena, loc_ret, src, line_info, module_path);
|
||||
|
||||
// Desugar any suffixed nodes, such as `foo = bar!`
|
||||
// desugar_defs_node_suffixed(
|
||||
// arena,
|
||||
// arena.alloc(Loc::at(loc_expr.region, Defs(arena.alloc(defs), loc_ret))),
|
||||
// )
|
||||
|
||||
arena.alloc(Loc::at(loc_expr.region, Defs(arena.alloc(defs), loc_ret)))
|
||||
}
|
||||
Apply(loc_fn, loc_args, called_via) => {
|
||||
|
@ -683,15 +677,6 @@ pub fn desugar_expr<'a>(
|
|||
value: If(desugared_if_thens.into_bump_slice(), desugared_final_else),
|
||||
region: loc_expr.region,
|
||||
})
|
||||
|
||||
// Desugar any suffixed nodes, such as `if isTrue! then ...`
|
||||
// desugar_if_node_suffixed(
|
||||
// arena,
|
||||
// arena.alloc(Loc {
|
||||
// value: If(desugared_if_thens.into_bump_slice(), desugared_final_else),
|
||||
// region: loc_expr.region,
|
||||
// }),
|
||||
// )
|
||||
}
|
||||
Expect(condition, continuation) => {
|
||||
let desugared_condition =
|
||||
|
|
|
@ -312,9 +312,6 @@ pub fn canonicalize_module_defs<'a>(
|
|||
// visited a BinOp node we'd recursively try to apply this to each of its nested
|
||||
// operators, and then again on *their* nested operators, ultimately applying the
|
||||
// rules multiple times unnecessarily.
|
||||
// if module_path.contains("test.roc"){
|
||||
// dbg!(&loc_defs);
|
||||
// }
|
||||
|
||||
crate::desugar::desugar_defs_node_values(arena, loc_defs, src, &mut None, module_path, true);
|
||||
|
||||
|
|
|
@ -265,7 +265,6 @@ pub fn canonicalize_def_header_pattern<'a>(
|
|||
|
||||
match pattern {
|
||||
// Identifiers that shadow ability members may appear (and may only appear) at the header of a def.
|
||||
// TODO should we use suffixed here?
|
||||
Identifier {
|
||||
ident: name,
|
||||
suffixed: _,
|
||||
|
@ -377,7 +376,6 @@ pub fn canonicalize_pattern<'a>(
|
|||
use PatternType::*;
|
||||
|
||||
let can_pattern = match pattern {
|
||||
// TODO do we need to use suffixed here?
|
||||
Identifier {
|
||||
ident: name,
|
||||
suffixed: _,
|
||||
|
@ -634,7 +632,6 @@ pub fn canonicalize_pattern<'a>(
|
|||
|
||||
for loc_pattern in patterns.iter() {
|
||||
match loc_pattern.value {
|
||||
// TODO should we use suffixed here?
|
||||
Identifier {
|
||||
ident: label,
|
||||
suffixed: _,
|
||||
|
|
|
@ -128,7 +128,7 @@ pub fn unwrap_suffixed_expression<'a>(
|
|||
},
|
||||
));
|
||||
|
||||
// we generate an intermedite pattern `#!a0` etc
|
||||
// we generate an intermediate pattern `#!a0` etc
|
||||
// so we dont unwrap the definition pattern
|
||||
let (mut answer_var, answer_pat) = next_suffixed_answer_pattern(arena);
|
||||
|
||||
|
@ -363,6 +363,9 @@ pub fn unwrap_suffixed_expression_if_then_else_help<'a>(
|
|||
) -> Result<&'a Loc<Expr<'a>>, EUnwrapped<'a>> {
|
||||
Ok(loc_expr)
|
||||
|
||||
// TODO - the logic below is mostly correct, however it needs to be
|
||||
// translated to this new method and tests added, leaving this for a future PR
|
||||
|
||||
// consider each if-statement, if it is suffixed we need to desugar e.g.
|
||||
// ```
|
||||
// if isFalse! then
|
||||
|
|
|
@ -7,6 +7,11 @@ mod suffixed_tests {
|
|||
use roc_test_utils::assert_multiline_str_eq;
|
||||
|
||||
/**
|
||||
* This example tests a suffixed statement, followed
|
||||
* by a Body with an empty record pattern.
|
||||
*
|
||||
* The def final expression is explicitly provided.
|
||||
*
|
||||
```roc
|
||||
main =
|
||||
line! "Ahoy"
|
||||
|
@ -44,8 +49,8 @@ mod suffixed_tests {
|
|||
}
|
||||
|
||||
/**
|
||||
The hello world of examples
|
||||
|
||||
* The most simple suffixed example. A single statement
|
||||
* without arguments and a final expression.
|
||||
```roc
|
||||
main =
|
||||
foo!
|
||||
|
@ -80,8 +85,8 @@ mod suffixed_tests {
|
|||
}
|
||||
|
||||
/**
|
||||
The hello world of examples
|
||||
|
||||
* A single suffixed statement with arguments applied.
|
||||
* Note there is no final expression.
|
||||
```roc
|
||||
main = foo! "bar" {} "baz"
|
||||
|
||||
|
@ -109,8 +114,8 @@ mod suffixed_tests {
|
|||
}
|
||||
|
||||
/**
|
||||
The hello world of examples
|
||||
|
||||
* Multiple suffixed statements with no
|
||||
* arguments, and no final expression.
|
||||
```roc
|
||||
main =
|
||||
foo!
|
||||
|
@ -147,6 +152,8 @@ mod suffixed_tests {
|
|||
}
|
||||
|
||||
/**
|
||||
* A definition with a closure that contains a Defs node, which also
|
||||
* contains a suffixed binops statement.
|
||||
```roc
|
||||
main =
|
||||
x = \msg ->
|
||||
|
@ -188,8 +195,11 @@ mod suffixed_tests {
|
|||
}
|
||||
|
||||
/**
|
||||
Example of unwrapping a pipline statement
|
||||
|
||||
* Example of unwrapping a pipline statement
|
||||
*
|
||||
* Note pipelines are desugared into Apply functions,
|
||||
* however this also tests the parser.
|
||||
*
|
||||
```roc
|
||||
main =
|
||||
"hello"
|
||||
|
@ -228,8 +238,12 @@ mod suffixed_tests {
|
|||
}
|
||||
|
||||
/**
|
||||
Example with a Parens sub-expression in an Apply function
|
||||
|
||||
* Example with a parens suffixed sub-expression
|
||||
* in the function part of an Apply.
|
||||
*
|
||||
* Note how the parens unwraps into an intermediate answer #!a0 instead of
|
||||
* unwrapping the def `do`.
|
||||
*
|
||||
```roc
|
||||
main =
|
||||
do = (sayMultiple!) "hi"
|
||||
|
@ -263,8 +277,8 @@ mod suffixed_tests {
|
|||
}
|
||||
|
||||
/**
|
||||
Example of handling Var's with single and multiple suffixes
|
||||
|
||||
* Example of unwrapping mixed Body defs with
|
||||
* Var's of both single and multiple suffixes
|
||||
```roc
|
||||
main =
|
||||
a = foo!
|
||||
|
@ -311,8 +325,10 @@ mod suffixed_tests {
|
|||
}
|
||||
|
||||
/**
|
||||
Example with multiple suffixes on a var
|
||||
|
||||
* Example with a multiple suffixed Var
|
||||
*
|
||||
* Note it unwraps into an intermediate answer `#!a0`
|
||||
*
|
||||
```roc
|
||||
main =
|
||||
foo!!
|
||||
|
@ -350,8 +366,7 @@ mod suffixed_tests {
|
|||
}
|
||||
|
||||
/**
|
||||
Example of nesting suffixed Apply functions
|
||||
|
||||
* A suffixed expression in the function part of the Apply
|
||||
```roc
|
||||
main =
|
||||
x = (foo! "bar") "hello"
|
||||
|
@ -385,7 +400,7 @@ mod suffixed_tests {
|
|||
}
|
||||
|
||||
/**
|
||||
Example of an Applly with an argument that needs to be unwrapped
|
||||
* A suffixed expression in an Apply argument position.
|
||||
```roc
|
||||
main =
|
||||
x = bar (foo! "hello")
|
||||
|
@ -419,8 +434,7 @@ mod suffixed_tests {
|
|||
}
|
||||
|
||||
/**
|
||||
Example with multiple defs, the suffixed is not the first def
|
||||
|
||||
* Example where the suffixed def is not the first def
|
||||
```roc
|
||||
main =
|
||||
msg = "hello"
|
||||
|
@ -455,8 +469,8 @@ mod suffixed_tests {
|
|||
}
|
||||
|
||||
/**
|
||||
Example of a suffixed inside a closure, and annotated blocks
|
||||
|
||||
* Annotated defs and a suffixed expression
|
||||
* with annotations inside a closure
|
||||
```roc
|
||||
main =
|
||||
x : Str -> Task _ _
|
||||
|
@ -505,8 +519,7 @@ mod suffixed_tests {
|
|||
}
|
||||
|
||||
/**
|
||||
Example of a suffixed inside a closure, and annotated blocks
|
||||
|
||||
* Nested suffixed expressions
|
||||
```roc
|
||||
main =
|
||||
z = foo! (bar! baz) (blah stuff)
|
||||
|
|
|
@ -212,7 +212,6 @@ fn generate_entry_docs(
|
|||
match either_index.split() {
|
||||
Err(value_index) => match &defs.value_defs[value_index.index()] {
|
||||
ValueDef::Annotation(loc_pattern, loc_ann) => {
|
||||
// TODO is this right for suffixed??
|
||||
if let Pattern::Identifier {
|
||||
ident: identifier,
|
||||
suffixed: _,
|
||||
|
@ -238,7 +237,6 @@ fn generate_entry_docs(
|
|||
ann_type,
|
||||
..
|
||||
} => {
|
||||
// TODO is this right for suffixed??
|
||||
if let Pattern::Identifier {
|
||||
ident: identifier,
|
||||
suffixed: _,
|
||||
|
@ -259,7 +257,6 @@ fn generate_entry_docs(
|
|||
}
|
||||
|
||||
ValueDef::Body(pattern, _) => {
|
||||
// TODO is this right for suffixed??
|
||||
if let Pattern::Identifier {
|
||||
ident: identifier,
|
||||
suffixed: _,
|
||||
|
@ -292,7 +289,6 @@ fn generate_entry_docs(
|
|||
}
|
||||
|
||||
ValueDef::Stmt(loc_expr) => {
|
||||
// TODO is this right for suffixed??
|
||||
if let roc_parse::ast::Expr::Var {
|
||||
ident: identifier, ..
|
||||
} = loc_expr.value
|
||||
|
@ -320,7 +316,6 @@ fn generate_entry_docs(
|
|||
let mut type_vars = Vec::new();
|
||||
|
||||
for var in vars.iter() {
|
||||
// TODO is this right for suffixed??
|
||||
if let Pattern::Identifier {
|
||||
ident: ident_name,
|
||||
suffixed: _,
|
||||
|
@ -359,7 +354,6 @@ fn generate_entry_docs(
|
|||
let mut type_vars = Vec::new();
|
||||
|
||||
for var in vars.iter() {
|
||||
// TODO is this right for suffixed??
|
||||
if let Pattern::Identifier {
|
||||
ident: ident_name,
|
||||
suffixed: _,
|
||||
|
@ -388,7 +382,6 @@ fn generate_entry_docs(
|
|||
let mut type_vars = Vec::new();
|
||||
|
||||
for var in vars.iter() {
|
||||
// TODO is this right for suffixed??
|
||||
if let Pattern::Identifier {
|
||||
ident: ident_name,
|
||||
suffixed: _,
|
||||
|
@ -655,7 +648,6 @@ fn type_to_docs(in_func_type_ann: bool, type_annotation: ast::TypeAnnotation) ->
|
|||
.vars
|
||||
.iter()
|
||||
.filter_map(|loc_pattern| match loc_pattern.value {
|
||||
// TODO is this right for suffixed??
|
||||
ast::Pattern::Identifier { ident, suffixed: _ } => Some(ident.to_string()),
|
||||
_ => None,
|
||||
})
|
||||
|
|
|
@ -5985,11 +5985,6 @@ fn build_pending_specializations<'a>(
|
|||
// this seems to work for now
|
||||
*shadowed
|
||||
}
|
||||
Pattern::RecordDestructure { .. } => {
|
||||
// this seems to work for now, we added to enable suffixed expressions
|
||||
// the issue is likely that we can have a `main = say! "hi"` which is
|
||||
symbol
|
||||
}
|
||||
_ => todo!("top-level destrucuture patterns are not implemented"),
|
||||
};
|
||||
|
||||
|
|
|
@ -713,9 +713,9 @@ pub fn parse_single_def<'a>(
|
|||
// Stdout.line! "Bar"
|
||||
// a=Stdout.line! "Foo"
|
||||
// Task.ok {}
|
||||
operator_result_state.line_indent() + 1,
|
||||
&operator_result_state.line_indent() + 1,
|
||||
arena,
|
||||
operator_result_state.clone(),
|
||||
operator_result_state,
|
||||
loc_pattern,
|
||||
spaces_before_current,
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue