Open fridis opened 11 months ago
what if we made codepoint
an integer
?
@maxteufel great idea.
currently still a bit painful though:
diff --git a/lib/codepoint.fz b/lib/codepoint.fz
index 9108dc978..fc657d2d0 100644
--- a/lib/codepoint.fz
+++ b/lib/codepoint.fz
@@ -25,7 +25,7 @@
# codepoint -- represents a unicode codepoint
#
-public codepoint(public val u32) : String
+public codepoint(public val u32) : integer, String
pre
debug: (codepoint.range.contains val)
debug: !codepoint.utf16_surrogate.contains val
@@ -135,3 +135,16 @@ is
# This defines a total order over strings that is unrelated to alphabetic order.
#
fixed type.lteq(a, b codepoint) => a.val <= b.val
+
+
+ /* NYI: select mechanism missing to choose inheritance from String instead of integer */
+ public redef infix * (n i32) String.infix * => panic "NYI"
+ public redef element_of(s container.Set String) bool => panic "NYI"
+ public redef infix ∈ (s container.Set String) => panic "NYI"
+ public redef not_element_of(s container.Set String) => panic "NYI"
+ public redef infix ∉ (s container.Set String) => panic "NYI"
+ public redef infix + (other Any) String => String.concat codepoint.this other.as_string
+
+ public redef as_string =>
+ ref : String
+ utf8 Sequence u8 => codepoint.this.utf8
This used to be part of #2285: Since ranges of codepoints are frequently needed as in
codepoint.type.ascii_digits
, it might make sense to havecodepoint
inherithas_interval
. But then,has_interval
should no longer inheritinteger
. Needs to be analyzed how this can be done best.