cli: add deterministic source formatter
This commit is contained in:
1 parent
d901d5227b
commit
462ddd2c5c
14 files changed
+787
-13
No files matched your search
@@ -0,0 +1,40 @@
|
||||
// Header stays before the module.
|
||||
module fmt.layout
|
||||
import std.option; // explicit import
|
||||
|
||||
// Generic declaration.
|
||||
struct Pair<T: Copy> {
|
||||
first: T,
|
||||
second: T,
|
||||
}
|
||||
|
||||
enum Choice<T: Copy> {
|
||||
some(T),
|
||||
none
|
||||
}
|
||||
|
||||
fn identity(x: u64) -> u64 effects [] {
|
||||
x
|
||||
}
|
||||
|
||||
fn apply<T: Copy, F: fn(T) -> T effects []>(x: T) -> T effects [] {
|
||||
return F(x);
|
||||
}
|
||||
|
||||
fn main() -> u64 effects [] {
|
||||
let pair = Pair::<u64> { first: 40u64, second: 2u64 }; // keep trailing
|
||||
let bytes = b"//not a comment\x00";
|
||||
let x = (pair.first + pair.second) * 1u64;
|
||||
if x < 43u64 {
|
||||
match Choice::<u64>::some(x) {
|
||||
Choice::<u64>::some(v) => {
|
||||
return apply::<u64, fn identity>(v);
|
||||
}
|
||||
Choice::<u64>::none => {
|
||||
return 0u64;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return x >> 1u64;
|
||||
}
|
||||
} // final
|
||||
Reference in new issue
Block a user