ai: 生成代码准备重构前的一次提交
This commit is contained in:
1 parent
936a8d0e88
commit
032102f1d7
375 files changed
+4619
-7609
No files matched your search
+58
-1
@@ -1,3 +1,5 @@
|
||||
type .{ .Result } = @import("./error.spl");
|
||||
|
||||
pub type Display = shape {
|
||||
fn fmt(@Self self: *@self, out: @[*Sink]): bool;
|
||||
};
|
||||
@@ -12,12 +14,67 @@ pub type Sink = shape {
|
||||
// TODO shape default value for `fn write_bytes(@Self self: *@self, bytes: []const u8): bool;`
|
||||
};
|
||||
|
||||
pub comptime fn Formatter(S: Sink): type {
|
||||
pub type Spec = struct {
|
||||
align: enum { Left, Center, Right },
|
||||
width: usize,
|
||||
fill: u8,
|
||||
// attrs: enum {
|
||||
// number: struct {},
|
||||
// }
|
||||
};
|
||||
|
||||
pub type Error = enum {
|
||||
WriteFailed,
|
||||
UnclosedLeftBrace,
|
||||
UnclosedRightBrace,
|
||||
UnknownSpec,
|
||||
MissingArg,
|
||||
TooManyArgs,
|
||||
};
|
||||
|
||||
// not have { and }
|
||||
pub fn parse_spec(pattern: []const u8): @Result(Spec, Error) {
|
||||
var res = Spec {
|
||||
.fill = ' ',
|
||||
.width = 0,
|
||||
.align = .Left,
|
||||
};
|
||||
ret .Ok(res);
|
||||
}
|
||||
|
||||
pub comptime fn Format(S: Sink): type {
|
||||
ret struct {
|
||||
out: S,
|
||||
|
||||
pub fn with_sink(out: S): @self {
|
||||
ret .{ .out = out };
|
||||
}
|
||||
|
||||
fn write(@Self self: *@self, str: []const u8): bool {
|
||||
var res = true;
|
||||
for i in str {
|
||||
res = self.out.write_byte(i);
|
||||
if (res == false) {
|
||||
ret false;
|
||||
}
|
||||
}
|
||||
ret res;
|
||||
}
|
||||
|
||||
pub fn format(@Self self: *@self, pattern: []const u8, args: []const DisplayArg): Error {
|
||||
var starti = 0;
|
||||
for i in 0..pattern.len() {
|
||||
var ch = pattern[i];
|
||||
match pattern[i] {
|
||||
'{' => {
|
||||
|
||||
},
|
||||
'}' => {
|
||||
|
||||
},
|
||||
_ => { continue; },
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user