aboutsummaryrefslogtreecommitdiff
path: root/std/default/format.pk
diff options
context:
space:
mode:
authorJJ2023-12-30 00:03:06 +0000
committerJJ2023-12-30 00:03:06 +0000
commitb8445b011d9b2a287af0e014998c42525a7fd315 (patch)
tree1b1008c2df5902fae12f40a394113a6453da2a4b /std/default/format.pk
parent774a35ae21dada36af48ae32c862b22587fba107 (diff)
std: restructure, refactor std.ast
Diffstat (limited to 'std/default/format.pk')
-rw-r--r--std/default/format.pk52
1 files changed, 0 insertions, 52 deletions
diff --git a/std/default/format.pk b/std/default/format.pk
deleted file mode 100644
index b117632..0000000
--- a/std/default/format.pk
+++ /dev/null
@@ -1,52 +0,0 @@
-## std/format: Niceties around printing and debugging.
-## This module is imported by default.
-
-## The Display interface. Any type implementing `str` is printable.
-## Any type that is Display must also implement Debug.
-pub type Display = interface
- str(Self): str
- dbg(Self): str
-
-## The Debug interface. Broadly implemented for every type with compiler magic.
-## Types can (and should) override the generic implementations.
-pub type Debug = interface
- dbg(Self): str
-
-## Prints all of its arguments to the command line.
-pub func print(params: varargs[Display]) =
- stdout.write(params.map(x => x.str).join(" "), "\n")
-
-## Prints all of its arguments to the command line, in Debug form.
-## Note: this function is special! does not count as a side effect
-pub func dbg(params: varargs[Debug]) =
- stdout.write(params.map(x => x.dbg).join(" "), "\n")
-
-## A dummy implementation of the Display interface for strings.
-pub func str(self: str): str = self
-## An implementation of the Debug interface for strings.
-pub func dbg(self: str): str = "\"" & self & "\""
-
-## An implementation of the Debug interface for all structs.
-## Uses the special `struct` typeclass.
-pub func dbg(self: struct): str =
- "{" & self.fields.map(field => field.id & field.value.dbg) & "}"
-
-## An implementation of the Debug interface for all tuples.
-## Uses the special `tuple` typeclass.
-pub func dbg(self: tuple): str =
- result &= "("
- for i, field in self.fields.enumerate():
- result &= field.id.map(id => id & " = ").get_or("")
- if i != self.fields.len:
- result &= ", "
- result &= ")"
-
-## An implementation of the Debug interface for all arrays and lists.
-pub func dbg(self: Iter[Debug]): str =
- "[" & self.map(x => x.str).join(", ") & "]"
-
-## The fmt macro. Builds a formatted string from its arguments.
-pub macro fmt(formatted: static[str], args: varargs[Display]) =
- # if not formatted of String:
- # macro_error("fmt must take a static string parameter!")
- ...