mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 08:34:33 +00:00
Implement a migration to new braces syntax and add migrate tests
This commit is contained in:
parent
017fd006c6
commit
109cb93b20
540 changed files with 3425 additions and 2 deletions
|
@ -979,7 +979,7 @@ fn format_str_segment(seg: &StrSegment, buf: &mut Buf) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn push_op(buf: &mut Buf, op: BinOp) {
|
pub fn push_op(buf: &mut Buf, op: BinOp) {
|
||||||
match op {
|
match op {
|
||||||
called_via::BinOp::Caret => buf.push('^'),
|
called_via::BinOp::Caret => buf.push('^'),
|
||||||
called_via::BinOp::Star => buf.push('*'),
|
called_via::BinOp::Star => buf.push('*'),
|
||||||
|
|
|
@ -7,6 +7,7 @@ pub mod collection;
|
||||||
pub mod def;
|
pub mod def;
|
||||||
pub mod expr;
|
pub mod expr;
|
||||||
pub mod header;
|
pub mod header;
|
||||||
|
pub mod migrate;
|
||||||
pub mod node;
|
pub mod node;
|
||||||
pub mod pattern;
|
pub mod pattern;
|
||||||
pub mod spaces;
|
pub mod spaces;
|
||||||
|
|
1401
crates/compiler/fmt/src/migrate.rs
Normal file
1401
crates/compiler/fmt/src/migrate.rs
Normal file
File diff suppressed because it is too large
Load diff
|
@ -7,6 +7,7 @@ use roc_can::scope::Scope;
|
||||||
use roc_can_solo::env::SoloEnv;
|
use roc_can_solo::env::SoloEnv;
|
||||||
use roc_can_solo::scope::SoloScope;
|
use roc_can_solo::scope::SoloScope;
|
||||||
use roc_error_macros::set_panic_not_exit;
|
use roc_error_macros::set_panic_not_exit;
|
||||||
|
use roc_fmt::migrate::{MigrateError, Suffix};
|
||||||
use roc_fmt::{annotation::Formattable, header::fmt_header, MigrationFlags};
|
use roc_fmt::{annotation::Formattable, header::fmt_header, MigrationFlags};
|
||||||
use roc_module::ident::QualifiedModuleName;
|
use roc_module::ident::QualifiedModuleName;
|
||||||
use roc_module::symbol::{IdentIds, Interns, ModuleIds, PackageModuleIds, Symbol};
|
use roc_module::symbol::{IdentIds, Interns, ModuleIds, PackageModuleIds, Symbol};
|
||||||
|
@ -30,7 +31,7 @@ use roc_types::{
|
||||||
types::{AliasVar, Type},
|
types::{AliasVar, Type},
|
||||||
};
|
};
|
||||||
|
|
||||||
use roc_fmt::Buf;
|
use roc_fmt::{migrate, Buf};
|
||||||
|
|
||||||
/// Source code to parse. Usually in the form of a test case.
|
/// Source code to parse. Usually in the form of a test case.
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||||
|
@ -253,6 +254,77 @@ impl<'a> Output<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn migrate(&self) -> Result<InputOwned, MigrateError> {
|
||||||
|
match self {
|
||||||
|
Output::Header(header) => {
|
||||||
|
let arena = Bump::new();
|
||||||
|
let mut buf = Buf::new_in(
|
||||||
|
&arena,
|
||||||
|
MigrationFlags {
|
||||||
|
snakify: false,
|
||||||
|
parens_and_commas: false,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
migrate::fmt_header(&mut buf, header)?;
|
||||||
|
buf.fmt_end_of_file();
|
||||||
|
Ok(InputOwned::Header(buf.as_str().to_string()))
|
||||||
|
}
|
||||||
|
Output::ModuleDefs(defs) => {
|
||||||
|
let arena = Bump::new();
|
||||||
|
let mut buf = Buf::new_in(
|
||||||
|
&arena,
|
||||||
|
MigrationFlags {
|
||||||
|
snakify: false,
|
||||||
|
parens_and_commas: false,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
migrate::fmt_defs(&mut buf, defs)?;
|
||||||
|
buf.fmt_end_of_file();
|
||||||
|
Ok(InputOwned::ModuleDefs(buf.as_str().to_string()))
|
||||||
|
}
|
||||||
|
Output::Expr(expr) => {
|
||||||
|
let arena = Bump::new();
|
||||||
|
let mut buf = Buf::new_in(
|
||||||
|
&arena,
|
||||||
|
MigrationFlags {
|
||||||
|
snakify: false,
|
||||||
|
parens_and_commas: false,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
migrate::fmt_expr_top_level(&mut buf, 0, &expr.value)?;
|
||||||
|
buf.fmt_end_of_file();
|
||||||
|
Ok(InputOwned::Expr(buf.as_str().to_string()))
|
||||||
|
}
|
||||||
|
Output::Full(full_ast) => {
|
||||||
|
let arena = Bump::new();
|
||||||
|
let mut buf = Buf::new_in(
|
||||||
|
&arena,
|
||||||
|
MigrationFlags {
|
||||||
|
snakify: false,
|
||||||
|
parens_and_commas: false,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
migrate::fmt_header(&mut buf, &full_ast.header)?;
|
||||||
|
migrate::fmt_defs(&mut buf, &full_ast.defs)?;
|
||||||
|
buf.fmt_end_of_file();
|
||||||
|
Ok(InputOwned::Full(buf.as_str().to_string()))
|
||||||
|
}
|
||||||
|
Output::Pattern(pat) => {
|
||||||
|
let arena = Bump::new();
|
||||||
|
let mut buf = Buf::new_in(
|
||||||
|
&arena,
|
||||||
|
MigrationFlags {
|
||||||
|
snakify: false,
|
||||||
|
parens_and_commas: false,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
migrate::fmt_pattern(&mut buf, 0, &pat.value, Suffix::None)?;
|
||||||
|
buf.fmt_end_of_file();
|
||||||
|
Ok(InputOwned::Pattern(buf.as_str().to_string()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Malformed for Output<'a> {
|
impl<'a> Malformed for Output<'a> {
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
I()
|
|
@ -0,0 +1,10 @@
|
||||||
|
O({p: if
|
||||||
|
a
|
||||||
|
{
|
||||||
|
|
||||||
|
A
|
||||||
|
} else {
|
||||||
|
&m
|
||||||
|
}}, #
|
||||||
|
) : e
|
||||||
|
i
|
|
@ -0,0 +1 @@
|
||||||
|
{
|
|
@ -0,0 +1,2 @@
|
||||||
|
N((implements),h,(0),) : B
|
||||||
|
T
|
|
@ -0,0 +1,2 @@
|
||||||
|
N(-0,T,) : A
|
||||||
|
zT
|
|
@ -0,0 +1,4 @@
|
||||||
|
B(@A,) : w
|
||||||
|
#
|
||||||
|
@A = e
|
||||||
|
i
|
|
@ -0,0 +1,3 @@
|
||||||
|
Zx((e #
|
||||||
|
),f,) : i
|
||||||
|
s
|
|
@ -0,0 +1,2 @@
|
||||||
|
U((b(a,)),) : b
|
||||||
|
a
|
|
@ -0,0 +1,4 @@
|
||||||
|
M({s: s({J&
|
||||||
|
},)},{s: s({J&
|
||||||
|
},)},) : p
|
||||||
|
y
|
|
@ -0,0 +1,4 @@
|
||||||
|
Q((
|
||||||
|
"""
|
||||||
|
"""("",)),) : a
|
||||||
|
q
|
|
@ -0,0 +1,6 @@
|
||||||
|
il3(|k| # w#z
|
||||||
|
{
|
||||||
|
CCC(@C,( # i
|
||||||
|
t!(K,)),) : i
|
||||||
|
C
|
||||||
|
},)
|
|
@ -0,0 +1 @@
|
||||||
|
{
|
|
@ -0,0 +1 @@
|
||||||
|
{
|
|
@ -0,0 +1 @@
|
||||||
|
{
|
|
@ -0,0 +1 @@
|
||||||
|
{
|
|
@ -0,0 +1,9 @@
|
||||||
|
if
|
||||||
|
h
|
||||||
|
{
|
||||||
|
|
||||||
|
A
|
||||||
|
} else {
|
||||||
|
&e
|
||||||
|
}
|
||||||
|
s #
|
|
@ -0,0 +1 @@
|
||||||
|
x + 2
|
|
@ -0,0 +1 @@
|
||||||
|
1 + 2
|
|
@ -0,0 +1,3 @@
|
||||||
|
M() :
|
||||||
|
r
|
||||||
|
h
|
|
@ -0,0 +1,3 @@
|
||||||
|
A( #
|
||||||
|
p,) : e
|
||||||
|
A
|
|
@ -0,0 +1,3 @@
|
||||||
|
K() : #
|
||||||
|
s
|
||||||
|
K
|
|
@ -0,0 +1,4 @@
|
||||||
|
O() : O(z,
|
||||||
|
#
|
||||||
|
)
|
||||||
|
b #
|
|
@ -0,0 +1,4 @@
|
||||||
|
8: O(
|
||||||
|
{
|
||||||
|
},)
|
||||||
|
Q
|
|
@ -0,0 +1,4 @@
|
||||||
|
foo: [True,Perhaps(Thing,),]
|
||||||
|
foo = True
|
||||||
|
|
||||||
|
42
|
|
@ -0,0 +1,5 @@
|
||||||
|
launchTheNukes: {}, => Result(Bool,LaunchNukeErr,)
|
||||||
|
launchTheNukes = |{}|
|
||||||
|
crash("todo",)
|
||||||
|
|
||||||
|
launchTheNukes
|
|
@ -0,0 +1,5 @@
|
||||||
|
2:
|
||||||
|
r where e
|
||||||
|
implements
|
||||||
|
P
|
||||||
|
u
|
|
@ -0,0 +1,4 @@
|
||||||
|
foo: [True,Perhaps(Thing,),..*]
|
||||||
|
foo = True
|
||||||
|
|
||||||
|
42
|
|
@ -0,0 +1,6 @@
|
||||||
|
r:
|
||||||
|
r
|
||||||
|
#
|
||||||
|
#
|
||||||
|
|
||||||
|
h
|
|
@ -0,0 +1,5 @@
|
||||||
|
x: a
|
||||||
|
where
|
||||||
|
e
|
||||||
|
implements K, -> Z
|
||||||
|
s
|
|
@ -0,0 +1,4 @@
|
||||||
|
H() : p
|
||||||
|
#
|
||||||
|
s = p
|
||||||
|
d #
|
|
@ -0,0 +1,3 @@
|
||||||
|
{l: s, #
|
||||||
|
}: s
|
||||||
|
o
|
|
@ -0,0 +1,4 @@
|
||||||
|
k:
|
||||||
|
[T,..m
|
||||||
|
] #
|
||||||
|
D
|
|
@ -0,0 +1,4 @@
|
||||||
|
J() : [
|
||||||
|
] where e
|
||||||
|
implements T
|
||||||
|
i
|
|
@ -0,0 +1,3 @@
|
||||||
|
1: (f,
|
||||||
|
ww, -> p,..e)
|
||||||
|
Mh
|
|
@ -0,0 +1,3 @@
|
||||||
|
E(): B
|
||||||
|
{} = B
|
||||||
|
B
|
|
@ -0,0 +1,4 @@
|
||||||
|
{x,y,}: Foo
|
||||||
|
{x,y,} = {x: "foo"y: 3.14}
|
||||||
|
|
||||||
|
x
|
|
@ -0,0 +1,4 @@
|
||||||
|
UserId(x,): [UserId(I64,),]
|
||||||
|
UserId(x,) = UserId(42,)
|
||||||
|
|
||||||
|
x
|
|
@ -0,0 +1,4 @@
|
||||||
|
(x,y,): Foo
|
||||||
|
(x,y,) = ("foo",3.14,)
|
||||||
|
|
||||||
|
x
|
|
@ -0,0 +1,4 @@
|
||||||
|
A(
|
||||||
|
p,) :
|
||||||
|
e
|
||||||
|
A
|
|
@ -0,0 +1,3 @@
|
||||||
|
e: A #
|
||||||
|
as H()
|
||||||
|
n
|
|
@ -0,0 +1,4 @@
|
||||||
|
A(
|
||||||
|
e, # g
|
||||||
|
) : A
|
||||||
|
AA
|
|
@ -0,0 +1,2 @@
|
||||||
|
s: eas A()as A()
|
||||||
|
s
|
|
@ -0,0 +1,3 @@
|
||||||
|
g: [T(T, #
|
||||||
|
),]
|
||||||
|
D
|
|
@ -0,0 +1,3 @@
|
||||||
|
3: (..n #
|
||||||
|
), -> n
|
||||||
|
0
|
|
@ -0,0 +1,3 @@
|
||||||
|
d: (J,..g
|
||||||
|
)
|
||||||
|
2
|
|
@ -0,0 +1,4 @@
|
||||||
|
p: (..
|
||||||
|
i
|
||||||
|
)
|
||||||
|
{}
|
|
@ -0,0 +1,2 @@
|
||||||
|
1: ((),..n)
|
||||||
|
l
|
|
@ -0,0 +1,3 @@
|
||||||
|
Str.getUnsafe(haystack,haystackIndex,)
|
||||||
|
==
|
||||||
|
Str.getUnsafe(needle,needleIndex,)
|
|
@ -0,0 +1,3 @@
|
||||||
|
!!
|
||||||
|
|w| 2(
|
||||||
|
n,)
|
|
@ -0,0 +1,2 @@
|
||||||
|
i < 2
|
||||||
|
-6
|
|
@ -0,0 +1,2 @@
|
||||||
|
foo
|
||||||
|
|> Dict.keepIf(|(k,_v,)| List.contains(keysToDelete,k,) |> Bool.not,)
|
|
@ -0,0 +1 @@
|
||||||
|
Whee((12),(34),)
|
|
@ -0,0 +1,3 @@
|
||||||
|
a: N({h
|
||||||
|
},)
|
||||||
|
g
|
|
@ -0,0 +1,2 @@
|
||||||
|
0({lxtl: (se #
|
||||||
|
)},)
|
|
@ -0,0 +1 @@
|
||||||
|
Whee(12,34,)
|
|
@ -0,0 +1 @@
|
||||||
|
Whee(12,34,)
|
|
@ -0,0 +1 @@
|
||||||
|
Ok(a,)
|
|
@ -0,0 +1 @@
|
||||||
|
Ok(a,)
|
|
@ -0,0 +1 @@
|
||||||
|
a(b,c,d,)
|
|
@ -0,0 +1,2 @@
|
||||||
|
i: M((),c,)
|
||||||
|
t
|
|
@ -0,0 +1 @@
|
||||||
|
whee(12,34,)
|
|
@ -0,0 +1 @@
|
||||||
|
whee(12,34,)
|
|
@ -0,0 +1 @@
|
||||||
|
-whee(12,foo,)
|
|
@ -0,0 +1 @@
|
||||||
|
!whee(12,foo,)
|
|
@ -0,0 +1,2 @@
|
||||||
|
|{x,y,} as point@Location(inner,) as outer|
|
||||||
|
crash("",)
|
|
@ -0,0 +1,3 @@
|
||||||
|
e: J
|
||||||
|
as H(), -> A
|
||||||
|
r
|
|
@ -0,0 +1,5 @@
|
||||||
|
a = (
|
||||||
|
i
|
||||||
|
#
|
||||||
|
)
|
||||||
|
r
|
|
@ -0,0 +1,2 @@
|
||||||
|
b
|
||||||
|
|e| s
|
|
@ -0,0 +1,4 @@
|
||||||
|
0
|
||||||
|
!
|
||||||
|
.d
|
||||||
|
.d
|
|
@ -0,0 +1,3 @@
|
||||||
|
J
|
||||||
|
!
|
||||||
|
.1(!.0,)
|
|
@ -0,0 +1 @@
|
||||||
|
whee(1,)
|
|
@ -0,0 +1,9 @@
|
||||||
|
## first line of docs
|
||||||
|
## second line
|
||||||
|
## third line
|
||||||
|
## fourth line
|
||||||
|
##
|
||||||
|
## sixth line after doc new line
|
||||||
|
x = 5
|
||||||
|
|
||||||
|
42
|
|
@ -0,0 +1 @@
|
||||||
|
rec.field
|
|
@ -0,0 +1 @@
|
||||||
|
Whee
|
|
@ -0,0 +1 @@
|
||||||
|
(1,2,3,)
|
|
@ -0,0 +1 @@
|
||||||
|
whee
|
|
@ -0,0 +1 @@
|
||||||
|
N < l((r * N),)
|
|
@ -0,0 +1,5 @@
|
||||||
|
5 - (({
|
||||||
|
e = ((
|
||||||
|
r))
|
||||||
|
1
|
||||||
|
}))
|
|
@ -0,0 +1,3 @@
|
||||||
|
d +
|
||||||
|
(|w| x)(
|
||||||
|
x,)
|
|
@ -0,0 +1,4 @@
|
||||||
|
r ^
|
||||||
|
-f(
|
||||||
|
#
|
||||||
|
-P,)
|
|
@ -0,0 +1,2 @@
|
||||||
|
"${g}": q
|
||||||
|
f
|
|
@ -0,0 +1,5 @@
|
||||||
|
t =
|
||||||
|
"""
|
||||||
|
"
|
||||||
|
"""("",)
|
||||||
|
S
|
|
@ -0,0 +1,3 @@
|
||||||
|
a = (
|
||||||
|
6)
|
||||||
|
a
|
|
@ -0,0 +1 @@
|
||||||
|
launchTheNukes!(123,)
|
|
@ -0,0 +1 @@
|
||||||
|
fxFn!(arg,)
|
|
@ -0,0 +1,3 @@
|
||||||
|
importP{_: h
|
||||||
|
}
|
||||||
|
t!
|
|
@ -0,0 +1,2 @@
|
||||||
|
|L| E
|
||||||
|
#
|
|
@ -0,0 +1 @@
|
||||||
|
|8| T #
|
|
@ -0,0 +1,4 @@
|
||||||
|
|I({p? Y(
|
||||||
|
Y,)?,},[
|
||||||
|
],)|
|
||||||
|
K # (
|
|
@ -0,0 +1,2 @@
|
||||||
|
m0(|w| w?(e,),)
|
||||||
|
/ s
|
|
@ -0,0 +1,2 @@
|
||||||
|
i > |s| s
|
||||||
|
-a
|
|
@ -0,0 +1,4 @@
|
||||||
|
|L|
|
||||||
|
{
|
||||||
|
}
|
||||||
|
Θ
|
|
@ -0,0 +1,3 @@
|
||||||
|
|L(z,
|
||||||
|
|
||||||
|
)| 42
|
|
@ -0,0 +1,2 @@
|
||||||
|
|{i, #
|
||||||
|
e,}| a
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue